AdminSchool no longer nullable; Profile page displays granted rights
This commit is contained in:
parent
4686c63fd9
commit
b363c05c95
2
models
2
models
@ -7,7 +7,7 @@ User
|
|||||||
UniqueAuthentication plugin ident
|
UniqueAuthentication plugin ident
|
||||||
UserAdmin
|
UserAdmin
|
||||||
user UserId
|
user UserId
|
||||||
school SchoolId Maybe
|
school SchoolId
|
||||||
UserLecturer
|
UserLecturer
|
||||||
user UserId
|
user UserId
|
||||||
school SchoolId
|
school SchoolId
|
||||||
|
|||||||
@ -202,11 +202,11 @@ submissionAccess cID = do
|
|||||||
True -> Authorized
|
True -> Authorized
|
||||||
False -> Unauthorized "No access to this submission"
|
False -> Unauthorized "No access to this submission"
|
||||||
|
|
||||||
adminAccess :: Maybe (Maybe SchoolId) -- ^ If @Just@, matched exactly against 'userAdminSchool'
|
adminAccess :: Maybe SchoolId -- ^ If @Just@, matched exactly against 'userAdminSchool'
|
||||||
-> YesodDB UniWorX AuthResult
|
-> YesodDB UniWorX AuthResult
|
||||||
adminAccess school = do
|
adminAccess school = do
|
||||||
authId <- lift requireAuthId
|
authId <- lift requireAuthId
|
||||||
rights <- selectList [UserAdminUser ==. authId, UserAdminSchool <-. catMaybes [school,Just Nothing]] []
|
rights <- selectList ((UserAdminUser ==. authId) : maybe [] (\s -> [UserAdminSchool ==. s]) school) []
|
||||||
return $ if (not $ null rights)
|
return $ if (not $ null rights)
|
||||||
then Authorized
|
then Authorized
|
||||||
else Unauthorized "No admin access"
|
else Unauthorized "No admin access"
|
||||||
|
|||||||
@ -7,9 +7,24 @@ module Handler.Profile where
|
|||||||
|
|
||||||
import Import
|
import Import
|
||||||
|
|
||||||
|
import qualified Database.Esqueleto as E
|
||||||
|
import Database.Esqueleto ((^.))
|
||||||
|
|
||||||
getProfileR :: Handler Html
|
getProfileR :: Handler Html
|
||||||
getProfileR = do
|
getProfileR = do
|
||||||
(_, user) <- requireAuthPair
|
(uid, user) <- requireAuthPair
|
||||||
|
(admin_rights,lecturer_rights) <- runDB $ (,) <$>
|
||||||
|
(E.select $ E.from $ \(adright `E.InnerJoin` school) -> do
|
||||||
|
E.where_ $ adright ^. UserAdminUser E.==. E.val uid
|
||||||
|
E.on $ adright ^. UserAdminSchool E.==. school ^. SchoolId
|
||||||
|
return (school ^. SchoolName)
|
||||||
|
)
|
||||||
|
<*>
|
||||||
|
(E.select $ E.from $ \(lecright `E.InnerJoin` school) -> do
|
||||||
|
E.where_ $ lecright ^. UserLecturerUser E.==. E.val uid
|
||||||
|
E.on $ lecright ^. UserLecturerSchool E.==. school ^. SchoolId
|
||||||
|
return (school ^. SchoolName)
|
||||||
|
)
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitle . toHtml $ userIdent user <> "'s User page"
|
setTitle . toHtml $ userIdent user <> "'s User page"
|
||||||
$(widgetFile "profile")
|
$(widgetFile "profile")
|
||||||
|
|||||||
@ -8,3 +8,16 @@
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
Your data is protected with us <strong><span class="username">#{userIdent user}</span></strong>!
|
Your data is protected with us <strong><span class="username">#{userIdent user}</span></strong>!
|
||||||
|
|
||||||
|
$if not $ null admin_rights
|
||||||
|
<h1>
|
||||||
|
Administrator für die Institute
|
||||||
|
<ul>
|
||||||
|
$forall institute <- admin_rights
|
||||||
|
<li>#{show institute}
|
||||||
|
$if not $ null lecturer_rights
|
||||||
|
<h1>
|
||||||
|
Lehrberechtigung für die Institute
|
||||||
|
<ul>
|
||||||
|
$forall institute <- lecturer_rights
|
||||||
|
<li>#{show institute}
|
||||||
|
|||||||
Reference in New Issue
Block a user