2016-02-14 18:10:21 +09:00
|
|
|
{- This file is part of Vervis.
|
|
|
|
-
|
2018-03-04 06:33:59 +09:00
|
|
|
- Written in 2016, 2018 by fr33domlover <fr33domlover@riseup.net>.
|
2016-02-14 18:10:21 +09:00
|
|
|
-
|
|
|
|
- ♡ 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/>.
|
|
|
|
-}
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
{-# LANGUAGE FlexibleInstances #-}
|
2016-02-14 18:10:21 +09:00
|
|
|
|
2016-02-23 17:45:03 +09:00
|
|
|
module Vervis.Model where
|
2016-02-14 18:10:21 +09:00
|
|
|
|
2016-02-29 23:04:23 +09:00
|
|
|
import ClassyPrelude.Conduit
|
|
|
|
import Yesod hiding (Header, parseTime)
|
|
|
|
|
2016-02-14 18:10:21 +09:00
|
|
|
import Database.Persist.Quasi
|
2016-05-19 21:06:27 +09:00
|
|
|
import Database.Persist.Sql (fromSqlKey)
|
2018-03-04 06:33:59 +09:00
|
|
|
import Yesod.Auth.Account (PersistUserCredentials (..))
|
2016-02-14 18:10:21 +09:00
|
|
|
|
2016-07-29 01:40:10 +09:00
|
|
|
import Database.Persist.Local.Class.PersistEntityGraph
|
2016-05-26 00:52:15 +09:00
|
|
|
import Vervis.Model.Group
|
2016-05-23 21:24:14 +09:00
|
|
|
import Vervis.Model.Ident
|
2016-05-03 08:51:53 +09:00
|
|
|
import Vervis.Model.Repo
|
2016-05-29 22:17:55 +09:00
|
|
|
import Vervis.Model.Role
|
2016-08-11 09:44:11 +09:00
|
|
|
import Vervis.Model.Ticket
|
2016-08-08 23:01:06 +09:00
|
|
|
import Vervis.Model.Workflow
|
2016-05-03 08:51:53 +09:00
|
|
|
|
2016-02-14 18:10:21 +09:00
|
|
|
-- You can define all of your database entities in the entities file.
|
2016-02-16 20:41:13 +09:00
|
|
|
-- You can find more information on persistent and how to declare entities at:
|
2016-02-14 18:10:21 +09:00
|
|
|
-- http://www.yesodweb.com/book/persistent/
|
2016-09-01 01:51:02 +09:00
|
|
|
share [mkPersist sqlSettings{-, mkMigrate "migrateAll"-}]
|
2016-02-14 18:10:21 +09:00
|
|
|
$(persistFileWith lowerCaseSettings "config/models")
|
2016-02-16 20:41:13 +09:00
|
|
|
|
2018-03-04 06:33:59 +09:00
|
|
|
instance PersistUserCredentials Person where
|
|
|
|
userUsernameF = PersonLogin
|
|
|
|
userPasswordHashF = PersonPassphraseHash
|
|
|
|
userEmailF = PersonEmail
|
|
|
|
userEmailVerifiedF = PersonVerified
|
|
|
|
userEmailVerifyKeyF = PersonVerifiedKey
|
|
|
|
userResetPwdKeyF = PersonResetPassphraseKey
|
|
|
|
uniqueUsername = UniquePersonLogin
|
|
|
|
-- 'Person' contains a sharer ID, so we can't let yesod-auth-account use
|
|
|
|
-- 'userCreate' to create a new user. Instead, override the default
|
|
|
|
-- implementation, where we can make sure to create a 'Sharer' and then a
|
|
|
|
-- 'Person' that refers to its 'SharerId'.
|
|
|
|
-- userCreate name email key pwd = Person {-?-} name pwd email False key ""
|
|
|
|
userCreate =
|
|
|
|
error
|
|
|
|
"userCreate: addNewUser is supposed to be overridden so that this \
|
|
|
|
\function is never used!"
|
2016-05-19 21:06:27 +09:00
|
|
|
|
|
|
|
-- "Vervis.Discussion" uses a 'HashMap' where the key type is 'MessageId'
|
|
|
|
instance Hashable MessageId where
|
|
|
|
hashWithSalt salt = hashWithSalt salt . fromSqlKey
|
|
|
|
hash = hash . fromSqlKey
|
2016-06-21 16:35:19 +09:00
|
|
|
|
|
|
|
-- "Vervis.Role" uses a 'HashMap' where the key type is 'RepoRoleId'
|
|
|
|
instance Hashable RepoRoleId where
|
|
|
|
hashWithSalt salt = hashWithSalt salt . fromSqlKey
|
|
|
|
hash = hash . fromSqlKey
|
|
|
|
|
|
|
|
-- "Vervis.Role" uses a 'HashMap' where the key type is 'ProjectRoleId'
|
|
|
|
instance Hashable ProjectRoleId where
|
|
|
|
hashWithSalt salt = hashWithSalt salt . fromSqlKey
|
|
|
|
hash = hash . fromSqlKey
|
2016-07-29 01:40:10 +09:00
|
|
|
|
|
|
|
instance PersistEntityGraph Ticket TicketDependency where
|
|
|
|
sourceParam = ticketDependencyParent
|
|
|
|
sourceField = TicketDependencyParent
|
|
|
|
destParam = ticketDependencyChild
|
|
|
|
destField = TicketDependencyChild
|
2016-08-04 04:32:33 +09:00
|
|
|
|
|
|
|
instance PersistEntityGraphSelect Ticket TicketDependency where
|
|
|
|
type PersistEntityGraphSelector Ticket TicketDependency = ProjectId
|
2016-08-04 06:26:39 +09:00
|
|
|
selectorParam _ = ticketProject
|
|
|
|
selectorField _ = TicketProject
|
2016-08-04 04:32:33 +09:00
|
|
|
|
|
|
|
instance PersistEntityGraphNumbered Ticket TicketDependency where
|
|
|
|
numberParam = ticketNumber
|
|
|
|
numberField = TicketNumber
|
|
|
|
uniqueNode = UniqueTicket
|