From 5aba62400ba0619f5787ad2b951ee9b13a23c775 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Tue, 6 Oct 2015 22:56:57 +0200 Subject: [PATCH] accept all, add admin role --- Foundation.hs | 3 ++- Handler/CreateChallenge.hs | 8 +++++++- config/models | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Foundation.hs b/Foundation.hs index 518bbfe..ec58c62 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -63,7 +63,7 @@ isTrusted user = "romang@amu.edu.pl" -> True "junczys@amu.edu.pl" -> True "rafalj@amu.edu.pl" -> True - _ -> False + _ -> True @@ -172,6 +172,7 @@ instance YesodAuth App where { userIdent = credsIdent creds , userPassword = Nothing , userName = Nothing + , userIsAdmin = False } -- You can add other plugins like BrowserID, email or OAuth here diff --git a/Handler/CreateChallenge.hs b/Handler/CreateChallenge.hs index 6e100a8..2612e17 100644 --- a/Handler/CreateChallenge.hs +++ b/Handler/CreateChallenge.hs @@ -33,7 +33,13 @@ postCreateChallengeR = do _ -> Nothing Just (name, publicUrl, publicBranch, privateUrl, privateBranch) = challengeData - runViewProgress $ doCreateChallenge name publicUrl publicBranch privateUrl privateBranch + userId <- requireAuthId + user <- runDB $ get404 userId + if userIsAdmin user + then + runViewProgress $ doCreateChallenge name publicUrl publicBranch privateUrl privateBranch + else + runViewProgress $ (flip err) "MUST BE AN ADMIN TO CREATE A CHALLENGE" doCreateChallenge :: Text -> Text -> Text -> Text -> Text -> Channel -> Handler () doCreateChallenge name publicUrl publicBranch privateUrl privateBranch chan = do diff --git a/config/models b/config/models index fca6938..f851dde 100644 --- a/config/models +++ b/config/models @@ -3,6 +3,7 @@ User password Text Maybe UniqueUser ident name Text Maybe + isAdmin Bool default=True deriving Typeable Email email Text