Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Separate CanDelegate, CanDelegateInClass and CanDelegateInSchool.
Browse files Browse the repository at this point in the history
  • Loading branch information
andorp committed Jun 24, 2016
1 parent 421b76e commit ce2dbd7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/Access.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ data Capability
= CanView
| CanLike
| CanVote
| CanDelegate
| CanComment
| CanVoteComment
| CanJudge -- also can add jury statement
Expand All @@ -106,6 +105,9 @@ data Capability
| CanCreateIdea
-- User
| CanCreateTopic
| CanDelegate
| CanDelegateInClass
| CanDelegateInSchool
| CanEditUser
deriving (Enum, Bounded, Eq, Ord, Show, Read, Generic)

Expand Down Expand Up @@ -160,14 +162,22 @@ capabilities :: CapCtx -> [Capability]
capabilities (CapCtx u ms mp mi mc mup mdt)
| not . checkSpace ms $ rs ^. each . roleScope = []
| otherwise = mconcat . mconcat $
[ [ userCapabilities r | r <- rs ]
[ userCapabilities'
, [ ideaCapabilities (u ^. _Id) r i p | r <- rs, i <- l mi, p <- l mp ]
, [ commentCapabilities (u ^. _Id) r c p | r <- rs, c <- l mc, p <- l mp ]
, [ topicCapabilities p r | r <- rs, p <- l mp ]
, [ [CanEditUser] | up <- l mup, isOwnProfile u up ]
, [ [CanDelegate] | dtu <- l mdt, haveCommonSchoolClass u dtu ]
, [ [CanDelegateInClass] | dtu <- l mdt, haveCommonSchoolClass u dtu, canDelegateToUser]
, [ [CanDelegateInSchool] | canDelegateToUser ]
]
where
userCapabilities' = userCapabilities <$> rs
canDelegateToUser =
maybe
False
(\dtu -> CanDelegate `elem` concat userCapabilities'
&& CanDelegate `elem` (userCapabilities =<< (dtu ^.. userRoles)))
mdt
rs = u ^.. userRoles
l = maybeToList

Expand Down
12 changes: 10 additions & 2 deletions src/Frontend/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,25 @@ instance Page (NeedCap 'CanEditAndDeleteIdea) where isAuthorized = needCap Can
instance Page (NeedCap 'CanVote) where isAuthorized = needCap CanVote
instance Page (NeedCap 'CanMarkWinner) where isAuthorized = needCap CanMarkWinner
instance Page (NeedCap 'CanDelegate) where isAuthorized = needCap CanDelegate
instance Page (NeedCap 'CanDelegateInSchool) where isAuthorized = needCap CanDelegateInSchool
instance Page (NeedCap 'CanDelegateInClass) where isAuthorized = needCap CanDelegateInClass
instance Page (NeedCap 'CanPhaseForwardTopic) where isAuthorized = needCap CanPhaseForwardTopic
instance Page (NeedCap 'CanPhaseBackwardTopic) where isAuthorized = needCap CanPhaseBackwardTopic

instance Page NeedAdmin where isAuthorized = adminPage

-- FIXME: move this to the rest of the delegation logic? (where's that?)
instance Page DelegateTo where
isAuthorized = authNeedCaps [CanDelegate] delegateToCapCtx
isAuthorized =
authNeedCapsAnyOf
[CanDelegateInClass, CanDelegateInSchool, CanDelegate]
delegateToCapCtx

instance Page WithdrawDelegationFrom where
isAuthorized = authNeedCaps [CanDelegate] withdrawDelegationFromCapCtx
isAuthorized =
authNeedCapsAnyOf
[CanDelegateInClass, CanDelegateInSchool, CanDelegate]
withdrawDelegationFromCapCtx

formPageHandler
:: Applicative m
Expand Down
2 changes: 1 addition & 1 deletion src/Frontend/Page/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ userHeaderDiv ctx (Right (user, delegations)) =

div_ [class_ "heroic-btn-group"] $ do
let caps = capabilities ctx
when (CanDelegate `elem` caps) $ do
when (CanDelegateInClass `elem` caps || CanDelegateInSchool `elem` caps) $ do
delegationButtons ctx user delegations
btn (U.reportUser user) "melden"
when (CanEditUser `elem` caps) $ do
Expand Down

0 comments on commit ce2dbd7

Please sign in to comment.