From 01915e6df94121605976e610b2219f552290b9ab Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Wed, 25 May 2016 06:53:22 +0000 Subject: [PATCH] Reduce verbosity of isAuthorized --- src/Vervis/Foundation.hs | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Vervis/Foundation.hs b/src/Vervis/Foundation.hs index e0dd891..83955a4 100644 --- a/src/Vervis/Foundation.hs +++ b/src/Vervis/Foundation.hs @@ -116,24 +116,25 @@ instance Yesod App where authRoute _ = Just $ AuthR LoginR -- Who can access which pages. - isAuthorized (ProjectNewR user) _ = - loggedInAs user "You can’t create projects for other users" - isAuthorized (RepoNewR user) _ = - loggedInAs user "You can’t create repos for other users" - isAuthorized KeysR _ = loggedIn - isAuthorized (KeyR _key) _ = loggedIn - isAuthorized KeyNewR _ = loggedIn - isAuthorized (RepoR shar _) True = - loggedInAs shar "You can’t modify repos for other users" - isAuthorized (TicketNewR _ _) _ = loggedIn - isAuthorized (TicketR user _ _) True = - loggedInAs user "Only project members can modify this ticket" - isAuthorized (TicketEditR user _ _) _ = - loggedInAs user "Only project members can modify this ticket" - isAuthorized (TicketDiscussionR _ _ _) True = loggedIn - isAuthorized (TicketTopReplyR _ _ _) _ = loggedIn - isAuthorized (TicketReplyR _ _ _ _) _ = loggedIn - isAuthorized _ _ = return Authorized + isAuthorized r w = case (r, w) of + (ProjectNewR user , _) -> + loggedInAs user "You can’t create projects for other users" + (RepoNewR user , _) -> + loggedInAs user "You can’t create repos for other users" + (KeysR , _) -> loggedIn + (KeyR _key , _) -> loggedIn + (KeyNewR , _) -> loggedIn + (RepoR shar _ , True) -> + loggedInAs shar "You can’t modify repos for other users" + (TicketNewR _ _ , _) -> loggedIn + (TicketR user _ _ , True) -> + loggedInAs user "Only project members can modify this ticket" + (TicketEditR user _ _ , _) -> + loggedInAs user "Only project members can modify this ticket" + (TicketDiscussionR _ _ _ , True) -> loggedIn + (TicketTopReplyR _ _ _ , _) -> loggedIn + (TicketReplyR _ _ _ _ , _) -> loggedIn + _ -> return Authorized -- This function creates static content files in the static folder -- and names them based on a hash of their content. This allows