diff --git a/config/models b/config/models index e4c093f..f63d92b 100644 --- a/config/models +++ b/config/models @@ -48,6 +48,7 @@ Group GroupMember person PersonId group GroupId + role GroupRole UniqueGroupMember person group diff --git a/src/Vervis/Handler/Group.hs b/src/Vervis/Handler/Group.hs index 5ece8b9..ceb69c6 100644 --- a/src/Vervis/Handler/Group.hs +++ b/src/Vervis/Handler/Group.hs @@ -28,6 +28,7 @@ import Data.Maybe (fromMaybe) import Data.Time.Clock (getCurrentTime) import Database.Esqueleto import Text.Blaze.Html (Html) +import Yesod.Auth (requireAuthId) import Yesod.Core (defaultLayout, setMessage) import Yesod.Core.Handler (redirect) import Yesod.Form.Functions (runFormPost) @@ -37,6 +38,7 @@ import Yesod.Persist.Core (runDB, getBy404) import Vervis.Form.Group import Vervis.Foundation import Vervis.Model +import Vervis.Model.Group import Vervis.Model.Ident (ShrIdent, shr2text) import Vervis.Settings (widgetFile) import Vervis.Time (showDate) @@ -56,6 +58,7 @@ postGroupsR = do case result of FormSuccess ng -> do now <- liftIO getCurrentTime + pid <- requireAuthId runDB $ do let sharer = Sharer { sharerIdent = ngIdent ng @@ -66,7 +69,13 @@ postGroupsR = do let group = Group { groupIdent = sid } - insert_ group + gid <- insert group + let member = GroupMember + { groupMemberPerson = pid + , groupMemberGroup = gid + , groupMemberRole = GRAdmin + } + insert_ member redirect $ GroupR $ ngIdent ng FormMissing -> do setMessage "Field(s) missing" @@ -90,7 +99,10 @@ getGroupR shar = do member ^. GroupMemberGroup ==. val gid &&. member ^. GroupMemberPerson ==. person ^. PersonId &&. person ^. PersonIdent ==. sharer ^. SharerId - orderBy [asc $ sharer ^. SharerIdent] + orderBy + [ asc $ member ^. GroupMemberRole + , asc $ sharer ^. SharerIdent + ] return sharer return (s, ms) defaultLayout $(widgetFile "group/one") diff --git a/src/Vervis/Model.hs b/src/Vervis/Model.hs index 90e3ab9..01cb914 100644 --- a/src/Vervis/Model.hs +++ b/src/Vervis/Model.hs @@ -24,6 +24,7 @@ import Database.Persist.Quasi import Database.Persist.Sql (fromSqlKey) import Yesod.Auth.HashDB (HashDBUser (..)) +import Vervis.Model.Group import Vervis.Model.Ident import Vervis.Model.Repo diff --git a/src/Vervis/Model/Group.hs b/src/Vervis/Model/Group.hs new file mode 100644 index 0000000..6afcb47 --- /dev/null +++ b/src/Vervis/Model/Group.hs @@ -0,0 +1,28 @@ +{- This file is part of Vervis. + - + - Written in 2016 by fr33domlover . + - + - ♡ Copying is an act of love. Please copy, reuse and share. + - + - The author(s) have dedicated all copyright and related and neighboring + - rights to this software to the public domain worldwide. This software is + - distributed without any warranty. + - + - You should have received a copy of the CC0 Public Domain Dedication along + - with this software. If not, see + - . + -} + +module Vervis.Model.Group + ( GroupRole (..) + ) +where + +import Prelude + +import Database.Persist.TH + +data GroupRole = GRMember | GRAdmin + deriving (Eq, Show, Read) + +derivePersistField "GroupRole" diff --git a/vervis.cabal b/vervis.cabal index cf06a67..d73b9a7 100644 --- a/vervis.cabal +++ b/vervis.cabal @@ -112,6 +112,7 @@ library Vervis.Import.NoFoundation Vervis.MediaType Vervis.Model + Vervis.Model.Group Vervis.Model.Ident Vervis.Model.Repo Vervis.Paginate