enable deleting deprecated admin users

This commit is contained in:
Lucy Cifferello
2023-04-12 14:58:04 -06:00
parent 7ebf5a81d7
commit b5410a80af
3 changed files with 11 additions and 8 deletions

View File

@@ -114,7 +114,7 @@ import Lib.PkgRepository (
import Lib.Types.Core (PkgId, S9PK) import Lib.Types.Core (PkgId, S9PK)
import Model ( import Model (
Admin (..), Admin (..),
Key (AdminKey), Key (AdminKey), EntityField (AdminId, AdminDeletedAt),
) )
import Settings (AppSettings (appShouldLogAll)) import Settings (AppSettings (appShouldLogAll))
import System.Console.ANSI.Codes ( import System.Console.ANSI.Codes (
@@ -150,6 +150,9 @@ import Yesod.Persist.Core (
YesodPersistRunner (..), YesodPersistRunner (..),
defaultGetDBRunner, defaultGetDBRunner,
) )
import Database.Persist ((==.))
import Database.Persist (selectFirst)
import Database.Persist (entityVal)
-- | The foundation datatype for your application. This can be a good place to -- | The foundation datatype for your application. This can be a good place to
@@ -312,9 +315,11 @@ instance YesodAuth RegistryCtx where
pool <- getsYesod appConnPool pool <- getsYesod appConnPool
let checkCreds k s = flip runSqlPool pool $ do let checkCreds k s = flip runSqlPool pool $ do
let passHash = hashWith SHA256 . encodeUtf8 . ("start9_admin:" <>) $ decodeUtf8 s let passHash = hashWith SHA256 . encodeUtf8 . ("start9_admin:" <>) $ decodeUtf8 s
get (AdminKey $ decodeUtf8 k) <&> \case selectFirst [AdminDeletedAt ==. Nothing, AdminId ==. (AdminKey $ decodeUtf8 k)] [] <&> \case
Nothing -> False Nothing -> False
Just Admin{adminPassHash} -> adminPassHash == passHash Just adminEntity -> do
let Admin{adminPassHash} = entityVal adminEntity
adminPassHash == passHash
defaultMaybeBasicAuthId checkCreds defaultAuthSettings defaultMaybeBasicAuthId checkCreds defaultAuthSettings
loginDest _ = PackageIndexR V1 loginDest _ = PackageIndexR V1

View File

@@ -148,6 +148,7 @@ Admin
Id Text Id Text
createdAt UTCTime createdAt UTCTime
passHash (Digest SHA256) passHash (Digest SHA256)
deletedAt UTCTime Maybe
Upload Upload
uploader AdminId uploader AdminId

View File

@@ -17,7 +17,7 @@ import Startlude ( ($)
, ByteString , ByteString
, ConvertText(toS) , ConvertText(toS)
, FilePath , FilePath
, IsString(fromString)
, Monad(return) , Monad(return)
, Monoid(mempty) , Monoid(mempty)
, Text , Text
@@ -59,10 +59,7 @@ import Orphans.Emver ( )
import Lib.Types.Core (PkgId) import Lib.Types.Core (PkgId)
import Data.String import Data.String
import Data.List.Extra (splitOn) import Data.List.Extra (splitOn)
import Data.Maybe (Maybe) import Prelude (map, read)
import Prelude (sequence, read)
import Prelude (map)
import Protolude (readMaybe)
-- | Runtime settings to configure this application. These settings can be -- | Runtime settings to configure this application. These settings can be
-- loaded from various sources: defaults, environment variables, config files, -- loaded from various sources: defaults, environment variables, config files,
-- theoretically even a database. -- theoretically even a database.