1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-29 01:34:52 +09:00

Add group roles and make a group's creator its admin

This commit is contained in:
fr33domlover 2016-05-25 15:52:15 +00:00
parent b7d443d031
commit 4c3aa8b269
5 changed files with 45 additions and 2 deletions

View file

@ -48,6 +48,7 @@ Group
GroupMember GroupMember
person PersonId person PersonId
group GroupId group GroupId
role GroupRole
UniqueGroupMember person group UniqueGroupMember person group

View file

@ -28,6 +28,7 @@ import Data.Maybe (fromMaybe)
import Data.Time.Clock (getCurrentTime) import Data.Time.Clock (getCurrentTime)
import Database.Esqueleto import Database.Esqueleto
import Text.Blaze.Html (Html) import Text.Blaze.Html (Html)
import Yesod.Auth (requireAuthId)
import Yesod.Core (defaultLayout, setMessage) import Yesod.Core (defaultLayout, setMessage)
import Yesod.Core.Handler (redirect) import Yesod.Core.Handler (redirect)
import Yesod.Form.Functions (runFormPost) import Yesod.Form.Functions (runFormPost)
@ -37,6 +38,7 @@ import Yesod.Persist.Core (runDB, getBy404)
import Vervis.Form.Group import Vervis.Form.Group
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Group
import Vervis.Model.Ident (ShrIdent, shr2text) import Vervis.Model.Ident (ShrIdent, shr2text)
import Vervis.Settings (widgetFile) import Vervis.Settings (widgetFile)
import Vervis.Time (showDate) import Vervis.Time (showDate)
@ -56,6 +58,7 @@ postGroupsR = do
case result of case result of
FormSuccess ng -> do FormSuccess ng -> do
now <- liftIO getCurrentTime now <- liftIO getCurrentTime
pid <- requireAuthId
runDB $ do runDB $ do
let sharer = Sharer let sharer = Sharer
{ sharerIdent = ngIdent ng { sharerIdent = ngIdent ng
@ -66,7 +69,13 @@ postGroupsR = do
let group = Group let group = Group
{ groupIdent = sid { groupIdent = sid
} }
insert_ group gid <- insert group
let member = GroupMember
{ groupMemberPerson = pid
, groupMemberGroup = gid
, groupMemberRole = GRAdmin
}
insert_ member
redirect $ GroupR $ ngIdent ng redirect $ GroupR $ ngIdent ng
FormMissing -> do FormMissing -> do
setMessage "Field(s) missing" setMessage "Field(s) missing"
@ -90,7 +99,10 @@ getGroupR shar = do
member ^. GroupMemberGroup ==. val gid &&. member ^. GroupMemberGroup ==. val gid &&.
member ^. GroupMemberPerson ==. person ^. PersonId &&. member ^. GroupMemberPerson ==. person ^. PersonId &&.
person ^. PersonIdent ==. sharer ^. SharerId person ^. PersonIdent ==. sharer ^. SharerId
orderBy [asc $ sharer ^. SharerIdent] orderBy
[ asc $ member ^. GroupMemberRole
, asc $ sharer ^. SharerIdent
]
return sharer return sharer
return (s, ms) return (s, ms)
defaultLayout $(widgetFile "group/one") defaultLayout $(widgetFile "group/one")

View file

@ -24,6 +24,7 @@ import Database.Persist.Quasi
import Database.Persist.Sql (fromSqlKey) import Database.Persist.Sql (fromSqlKey)
import Yesod.Auth.HashDB (HashDBUser (..)) import Yesod.Auth.HashDB (HashDBUser (..))
import Vervis.Model.Group
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Vervis.Model.Repo

28
src/Vervis/Model/Group.hs Normal file
View 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"

View file

@ -112,6 +112,7 @@ library
Vervis.Import.NoFoundation Vervis.Import.NoFoundation
Vervis.MediaType Vervis.MediaType
Vervis.Model Vervis.Model
Vervis.Model.Group
Vervis.Model.Ident Vervis.Model.Ident
Vervis.Model.Repo Vervis.Model.Repo
Vervis.Paginate Vervis.Paginate