Add group roles and make a group's creator its admin
This commit is contained in:
parent
b7d443d031
commit
4c3aa8b269
5 changed files with 45 additions and 2 deletions
|
@ -48,6 +48,7 @@ Group
|
|||
GroupMember
|
||||
person PersonId
|
||||
group GroupId
|
||||
role GroupRole
|
||||
|
||||
UniqueGroupMember person group
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
28
src/Vervis/Model/Group.hs
Normal file
28
src/Vervis/Model/Group.hs
Normal file
|
@ -0,0 +1,28 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ 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
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
module Vervis.Model.Group
|
||||
( GroupRole (..)
|
||||
)
|
||||
where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Database.Persist.TH
|
||||
|
||||
data GroupRole = GRMember | GRAdmin
|
||||
deriving (Eq, Show, Read)
|
||||
|
||||
derivePersistField "GroupRole"
|
|
@ -112,6 +112,7 @@ library
|
|||
Vervis.Import.NoFoundation
|
||||
Vervis.MediaType
|
||||
Vervis.Model
|
||||
Vervis.Model.Group
|
||||
Vervis.Model.Ident
|
||||
Vervis.Model.Repo
|
||||
Vervis.Paginate
|
||||
|
|
Loading…
Reference in a new issue