2016-02-14 18:10:21 +09:00
|
|
|
{- This file is part of Vervis.
|
|
|
|
-
|
2019-02-03 22:58:14 +09:00
|
|
|
- Written in 2016, 2018, 2019 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 Yesod hiding (Header, parseTime)
|
|
|
|
|
2019-06-15 17:24:08 +09:00
|
|
|
import Data.ByteString (ByteString)
|
|
|
|
import Data.Hashable
|
|
|
|
import Data.Text (Text)
|
|
|
|
import Data.Time.Clock
|
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-06 11:26:27 +09:00
|
|
|
import Text.Email.Validate (EmailAddress)
|
2018-03-04 06:33:59 +09:00
|
|
|
import Yesod.Auth.Account (PersistUserCredentials (..))
|
2016-02-14 18:10:21 +09:00
|
|
|
|
2019-03-11 08:15:42 +09:00
|
|
|
import Crypto.PublicVerifKey
|
2018-03-06 11:26:27 +09:00
|
|
|
import Database.Persist.EmailAddress
|
2019-01-27 07:20:19 +09:00
|
|
|
import Database.Persist.Graph.Class
|
2019-03-24 00:29:50 +09:00
|
|
|
import Database.Persist.JSON
|
2019-02-22 08:59:53 +09:00
|
|
|
import Network.FedURI (FedURI, LocalURI)
|
2019-03-29 06:08:30 +09:00
|
|
|
import Web.ActivityPub (Doc, Activity)
|
2018-03-06 11:26:27 +09:00
|
|
|
|
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
|
2018-03-27 23:28:56 +09:00
|
|
|
import Vervis.Model.TH
|
2016-08-08 23:01:06 +09:00
|
|
|
import Vervis.Model.Workflow
|
2016-05-03 08:51:53 +09:00
|
|
|
|
2019-03-29 06:08:30 +09:00
|
|
|
type PersistActivity = PersistJSON (Doc Activity)
|
|
|
|
|
2018-03-27 23:28:56 +09:00
|
|
|
makeEntities $(modelFile "config/models")
|
2016-02-16 20:41:13 +09:00
|
|
|
|
2018-03-04 06:33:59 +09:00
|
|
|
instance PersistUserCredentials Person where
|
2018-04-01 12:02:35 +09:00
|
|
|
userUsernameF = PersonLogin
|
|
|
|
userPasswordHashF = PersonPassphraseHash
|
|
|
|
userEmailF = PersonEmail
|
|
|
|
userEmailVerifiedF = PersonVerified
|
|
|
|
userEmailVerifyKeyF = PersonVerifiedKey
|
|
|
|
userEmailVerifyKeyCreatedF = Just PersonVerifiedKeyCreated
|
|
|
|
userResetPwdKeyF = PersonResetPassKey
|
|
|
|
userResetPwdKeyCreatedF = Just PersonResetPassKeyCreated
|
|
|
|
uniqueUsername = UniquePersonLogin
|
2018-04-11 20:09:42 +09:00
|
|
|
uniqueEmail = Just UniquePersonEmail
|
2018-03-04 06:33:59 +09:00
|
|
|
-- '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 'ProjectRoleId'
|
2019-06-01 00:02:57 +09:00
|
|
|
instance Hashable RoleId where
|
2016-06-21 16:35:19 +09:00
|
|
|
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
|
2018-05-16 09:02:54 +09:00
|
|
|
numberParam _ = ticketNumber
|
|
|
|
numberField _ = TicketNumber
|
|
|
|
uniqueNode _ = UniqueTicket
|