Copyright | (c) Anton Gushcha, 2016 |
---|---|
License | MIT |
Maintainer | ncrashed@gmail.com |
Stability | experimental |
Portability | Portable |
Safe Haskell | None |
Language | Haskell2010 |
- data UserImpl = UserImpl {
- userImplLogin :: !Login
- userImplPassword :: !Password
- userImplEmail :: !Email
- data UserPerm = UserPerm {
- userPermUser :: !(Key UserImpl)
- userPermPermission :: !Permission
- data AuthToken = AuthToken {
- authTokenValue :: !SimpleToken
- authTokenUser :: !(Key UserImpl)
- authTokenExpire :: !UTCTime
- data UserRestore = UserRestore {}
- data AuthUserGroup = AuthUserGroup {
- authUserGroupName :: !Text
- authUserGroupParent :: !(Maybe (Key AuthUserGroup))
- data AuthUserGroupUsers = AuthUserGroupUsers {}
- data AuthUserGroupPerms = AuthUserGroupPerms {}
- data family EntityField record a
- data UserSingleUseCode = UserSingleUseCode {}
- type UserImplId = Key UserImpl
- type UserPermId = Key UserPerm
- type AuthTokenId = Key AuthToken
- type UserRestoreId = Key UserRestore
- type AuthUserGroupId = Key AuthUserGroup
- type AuthUserGroupUsersId = Key AuthUserGroupUsers
- type AuthUserGroupPermsId = Key AuthUserGroupPerms
- type UserSingleUseCodeId = Key UserSingleUseCode
- runDB :: (MonadReader AuthConfig m, MonadIO m) => SqlPersistT IO b -> m b
- migrateAll :: Migration
- passToByteString :: Password -> ByteString
- byteStringToPass :: ByteString -> Password
- userToUserInfo :: Entity UserImpl -> [Permission] -> [UserGroupId] -> RespUserInfo
- readUserInfo :: UserId -> SqlPersistT IO (Maybe RespUserInfo)
- readUserInfoByLogin :: Login -> SqlPersistT IO (Maybe RespUserInfo)
- getUserPermissions :: UserImplId -> SqlPersistT IO [Permission]
- setUserPermissions :: UserImplId -> [Permission] -> SqlPersistT IO ()
- createUser :: Int -> Login -> Password -> Email -> [Permission] -> SqlPersistT IO UserImplId
- hasPerm :: UserImplId -> Permission -> SqlPersistT IO Bool
- hasPerms :: UserImplId -> [Permission] -> SqlPersistT IO Bool
- createAdmin :: Int -> Login -> Password -> Email -> SqlPersistT IO UserImplId
- ensureAdmin :: Int -> Login -> Password -> Email -> SqlPersistT IO ()
- patchUser :: Int -> PatchUser -> Entity UserImpl -> SqlPersistT IO (Entity UserImpl)
- setUserPassword' :: MonadIO m => Int -> Password -> UserImpl -> m UserImpl
- getUserGroups :: UserImplId -> SqlPersistT IO [UserGroupId]
- setUserGroups :: UserImplId -> [UserGroupId] -> SqlPersistT IO ()
- validateGroups :: [UserGroupId] -> SqlPersistT IO [AuthUserGroupId]
- getGroupPermissions :: UserGroupId -> SqlPersistT IO [Permission]
- getUserGroupPermissions :: UserImplId -> SqlPersistT IO [Permission]
- getUserAllPermissions :: UserImplId -> SqlPersistT IO [Permission]
- readUserGroup :: UserGroupId -> SqlPersistT IO (Maybe UserGroup)
- toAuthUserGroup :: UserGroup -> (AuthUserGroup, AuthUserGroupId -> [AuthUserGroupUsers], AuthUserGroupId -> [AuthUserGroupPerms])
- insertUserGroup :: UserGroup -> SqlPersistT IO UserGroupId
- updateUserGroup :: UserGroupId -> UserGroup -> SqlPersistT IO ()
- deleteUserGroup :: UserGroupId -> SqlPersistT IO ()
- patchUserGroup :: UserGroupId -> PatchUserGroup -> SqlPersistT IO ()
DB entities
UserImpl | |
|
UserPerm | |
|
AuthToken | |
|
data UserRestore Source
UserRestore | |
|
data AuthUserGroup Source
data AuthUserGroupUsers Source
data AuthUserGroupPerms Source
data family EntityField record a
An EntityField
is parameterised by the Haskell record it belongs to
and the additional type of that field.
data UserSingleUseCode Source
IDs of entities
type UserImplId = Key UserImpl Source
type UserPermId = Key UserPerm Source
type AuthTokenId = Key AuthToken Source
type UserRestoreId = Key UserRestore Source
type AuthUserGroupId = Key AuthUserGroup Source
Operations
runDB :: (MonadReader AuthConfig m, MonadIO m) => SqlPersistT IO b -> m b Source
Execute database transaction
passToByteString :: Password -> ByteString Source
Convert password to bytestring
byteStringToPass :: ByteString -> Password Source
Convert bytestring into password
User
userToUserInfo :: Entity UserImpl -> [Permission] -> [UserGroupId] -> RespUserInfo Source
Helper to convert user to response
readUserInfo :: UserId -> SqlPersistT IO (Maybe RespUserInfo) Source
Get user by id
readUserInfoByLogin :: Login -> SqlPersistT IO (Maybe RespUserInfo) Source
Get user by login
getUserPermissions :: UserImplId -> SqlPersistT IO [Permission] Source
Return list of permissions for the given user (only permissions that are assigned to him directly)
setUserPermissions :: UserImplId -> [Permission] -> SqlPersistT IO () Source
Return list of permissions for the given user
createUser :: Int -> Login -> Password -> Email -> [Permission] -> SqlPersistT IO UserImplId Source
Creation of new user
hasPerm :: UserImplId -> Permission -> SqlPersistT IO Bool Source
Check whether the user has particular permission
hasPerms :: UserImplId -> [Permission] -> SqlPersistT IO Bool Source
Check whether the user has particular permissions
createAdmin :: Int -> Login -> Password -> Email -> SqlPersistT IO UserImplId Source
Creates user with admin privileges
ensureAdmin :: Int -> Login -> Password -> Email -> SqlPersistT IO () Source
Ensures that DB has at leas one admin, if not, creates a new one with specified info.
Apply patches for user
Update password of user
User groups
getUserGroups :: UserImplId -> SqlPersistT IO [UserGroupId] Source
Get all groups the user belongs to
setUserGroups :: UserImplId -> [UserGroupId] -> SqlPersistT IO () Source
Rewrite all user groups
validateGroups :: [UserGroupId] -> SqlPersistT IO [AuthUserGroupId] Source
Leave only existing groups
getGroupPermissions :: UserGroupId -> SqlPersistT IO [Permission] Source
Getting permission of a group and all it parent groups
getUserGroupPermissions :: UserImplId -> SqlPersistT IO [Permission] Source
Get user permissions that are assigned to him/her via groups only
getUserAllPermissions :: UserImplId -> SqlPersistT IO [Permission] Source
Get user permissions that are assigned to him/her either by direct way or by his/her groups.
readUserGroup :: UserGroupId -> SqlPersistT IO (Maybe UserGroup) Source
Collect full info about user group from RDBMS
toAuthUserGroup :: UserGroup -> (AuthUserGroup, AuthUserGroupId -> [AuthUserGroupUsers], AuthUserGroupId -> [AuthUserGroupPerms]) Source
Helper to convert user group into values of several tables
insertUserGroup :: UserGroup -> SqlPersistT IO UserGroupId Source
Insert user group into RDBMS
updateUserGroup :: UserGroupId -> UserGroup -> SqlPersistT IO () Source
Replace user group with new value
deleteUserGroup :: UserGroupId -> SqlPersistT IO () Source
Erase user group from RDBMS, cascade
patchUserGroup :: UserGroupId -> PatchUserGroup -> SqlPersistT IO () Source
Partial update of user group