retype AdminPkgs since PkgRecord id as key will not yet exist

This commit is contained in:
Lucy Cifferello
2024-04-16 14:10:13 -04:00
parent 54e980f3a0
commit 0a41ab2b12
4 changed files with 6 additions and 6 deletions

View File

@@ -329,7 +329,7 @@ getVersionPlatform pkgId arches = do
pure v pure v
pure $ entityVal <$> vps pure $ entityVal <$> vps
getAllowedPkgs :: (Monad m, MonadIO m) => PkgRecordId -> AdminId -> ReaderT SqlBackend m [AdminPkgs] getAllowedPkgs :: (Monad m, MonadIO m) => PkgId -> AdminId -> ReaderT SqlBackend m [AdminPkgs]
getAllowedPkgs pkgId adminId = do getAllowedPkgs pkgId adminId = do
pkgs <- select $ do pkgs <- select $ do
p <- from $ table @AdminPkgs p <- from $ table @AdminPkgs

View File

@@ -168,7 +168,7 @@ postCheckPkgAuthR pkgId = do
else if authorized && newPkg else if authorized && newPkg
-- if pkg is whitelisted and a new upload, add as authorized for this admin user -- if pkg is whitelisted and a new upload, add as authorized for this admin user
then do then do
runDB $ insert_ (AdminPkgs (AdminKey name) (PkgRecordKey pkgId)) runDB $ insert_ (AdminPkgs (AdminKey name) pkgId)
sendResponseText status200 "User authorized to upload this package." sendResponseText status200 "User authorized to upload this package."
else sendResponseText status401 "User not authorized to upload this package." else sendResponseText status401 "User not authorized to upload this package."
else sendResponseText status500 "Package does not belong on this registry." else sendResponseText status500 "Package does not belong on this registry."
@@ -207,7 +207,7 @@ postPkgUploadR = do
if authorized if authorized
then do then do
now <- liftIO getCurrentTime now <- liftIO getCurrentTime
runDB $ insert_ (Upload (AdminKey name) (PkgRecordKey packageManifestId) packageManifestVersion now) runDB $ insert_ (Upload (AdminKey name) (PkgRecordKey packageManifestId)packageManifestVersion now)
else sendResponseText status401 "User not authorized to upload this package." else sendResponseText status401 "User not authorized to upload this package."
else sendResponseText status500 "Package does not belong on this registry." else sendResponseText status500 "Package does not belong on this registry."
where where

View File

@@ -256,12 +256,12 @@ areRegexMatchesEqual textMap (PackageDevice regexMap) =
case MM.lookup key textMap of case MM.lookup key textMap of
val -> or $ regexMatch regexPattern <$> val val -> or $ regexMatch regexPattern <$> val
checkAdminAllowedPkgs :: PkgId -> Text -> Handler (Bool, Bool) -- (exists, new) checkAdminAllowedPkgs :: PkgId -> Text -> Handler (Bool, Bool) -- (authorized, newPkg)
checkAdminAllowedPkgs pkgId adminId = do checkAdminAllowedPkgs pkgId adminId = do
-- if pkg does not exist yet, allow, because authorized by whitelist -- if pkg does not exist yet, allow, because authorized by whitelist
pkg <- runDB $ getPkg (PkgRecordKey pkgId) pkg <- runDB $ getPkg (PkgRecordKey pkgId)
if length pkg > 0 if length pkg > 0
then do then do
res <- runDB $ getAllowedPkgs (PkgRecordKey pkgId) (AdminKey adminId) res <- runDB $ getAllowedPkgs pkgId (AdminKey adminId)
pure $ if length res > 0 then (True, False) else (False, False) pure $ if length res > 0 then (True, False) else (False, False)
else pure (True, True) else pure (True, True)

View File

@@ -155,7 +155,7 @@ Admin
AdminPkgs AdminPkgs
admin AdminId admin AdminId
pkgId PkgRecordId pkgId PkgId
UniqueAdminPkg pkgId admin UniqueAdminPkg pkgId admin
Upload Upload