prepare roles
This commit is contained in:
parent
465c73ff6e
commit
c98487318a
4 changed files with 101 additions and 0 deletions
|
@ -89,6 +89,8 @@ main = do
|
||||||
void $ execute_ conn initAuthData
|
void $ execute_ conn initAuthData
|
||||||
void $ execute_ conn initAmount
|
void $ execute_ conn initAmount
|
||||||
void $ execute_ conn initJournal
|
void $ execute_ conn initJournal
|
||||||
|
void $ execute_ conn initRole
|
||||||
|
void $ execute_ conn initUserToRole
|
||||||
forkCleanProcess conn store
|
forkCleanProcess conn store
|
||||||
withStdoutLogger $ \ilog -> do
|
withStdoutLogger $ \ilog -> do
|
||||||
let settings = setPort (fromIntegral lport) $
|
let settings = setPort (fromIntegral lport) $
|
||||||
|
|
|
@ -69,6 +69,7 @@ library
|
||||||
, Model.Amount
|
, Model.Amount
|
||||||
, Model.Journal
|
, Model.Journal
|
||||||
, Model.Avatar
|
, Model.Avatar
|
||||||
|
, Model.Role
|
||||||
, Types
|
, Types
|
||||||
, Types.Auth
|
, Types.Auth
|
||||||
, Types.Product
|
, Types.Product
|
||||||
|
|
|
@ -8,3 +8,4 @@ import Model.Auth as M
|
||||||
import Model.Amount as M
|
import Model.Amount as M
|
||||||
import Model.Journal as M
|
import Model.Journal as M
|
||||||
import Model.Avatar as M
|
import Model.Avatar as M
|
||||||
|
import Model.Role as M
|
||||||
|
|
|
@ -3,3 +3,100 @@
|
||||||
{-# LANGUAGE Arrows #-}
|
{-# LANGUAGE Arrows #-}
|
||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
module Model.Role where
|
module Model.Role where
|
||||||
|
|
||||||
|
import qualified Database.PostgreSQL.Simple as PGS
|
||||||
|
|
||||||
|
import Data.Profunctor.Product (p2, p13)
|
||||||
|
|
||||||
|
import Opaleye as O hiding (null, not)
|
||||||
|
import Opaleye.Constant as C
|
||||||
|
|
||||||
|
initRole :: PGS.Query
|
||||||
|
initRole = mconcat
|
||||||
|
[ "CREATE TABLE IF NOT EXISTS \"role\" ("
|
||||||
|
, "role_id SERIAL NOT NULL,"
|
||||||
|
, "role_name TEXT NOT NULL,"
|
||||||
|
, "role_can_refill_stock BOOLEAN NOT NULL,"
|
||||||
|
, "role_can_add_product BOOLEAN NOT NULL,"
|
||||||
|
, "role_can_view_journal BOOLEAN NOT NULL,"
|
||||||
|
, "role_can_pay_invoice BOOLEAN NOT NULL,"
|
||||||
|
, "role_can_pay_out BOOLEAN NOT NULL,"
|
||||||
|
, "role_can_manage_products BOOLEAN NOT NULL,"
|
||||||
|
, "role_can_manage_journal BOOLEAN NOT NULL,"
|
||||||
|
, "role_can_manage_users BOOLEAN NOT NULL,"
|
||||||
|
, "role_can_manage_roles BOOLEAN NOT NULL,"
|
||||||
|
, "role_can_manage_suppliers BOOLEAN NOT NULL,"
|
||||||
|
, "role_can_manage_settings BOOLEAN NOT NULL,"
|
||||||
|
, "PRIMARY KEY (role_id)"
|
||||||
|
, ")"
|
||||||
|
]
|
||||||
|
|
||||||
|
initUserToRole :: PGS.Query
|
||||||
|
initUserToRole = mconcat
|
||||||
|
[ "CREATE TABLE IF NOT EXISTS \"user_to_role\" ("
|
||||||
|
, "user_id INTEGER NOT NULL,"
|
||||||
|
, "role_id INTEGER NOT NULL,"
|
||||||
|
, "PRIMARY KEY (user_id, role_id)"
|
||||||
|
, ")"
|
||||||
|
]
|
||||||
|
|
||||||
|
roleTable :: Table
|
||||||
|
( Maybe (Field SqlInt4)
|
||||||
|
, Field SqlText
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
)
|
||||||
|
( Field SqlInt4
|
||||||
|
, Field SqlText
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
, Field SqlBool
|
||||||
|
)
|
||||||
|
roleTable = table "role" (
|
||||||
|
p13
|
||||||
|
( tableField "role_id"
|
||||||
|
, tableField "role_name"
|
||||||
|
, tableField "role_can_refill_stock"
|
||||||
|
, tableField "role_can_add_product"
|
||||||
|
, tableField "role_can_view_journal"
|
||||||
|
, tableField "role_can_pay_invoice"
|
||||||
|
, tableField "role_can_pay_out"
|
||||||
|
, tableField "role_can_manage_products"
|
||||||
|
, tableField "role_can_manage_journal"
|
||||||
|
, tableField "role_can_manage_users"
|
||||||
|
, tableField "role_can_manage_roles"
|
||||||
|
, tableField "role_can_manage_suppliers"
|
||||||
|
, tableField "role_can_manage_settings"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
userToRoleTable :: Table
|
||||||
|
( Field SqlInt4
|
||||||
|
, Field SqlInt4
|
||||||
|
)
|
||||||
|
( Field SqlInt4
|
||||||
|
, Field SqlInt4
|
||||||
|
)
|
||||||
|
userToRoleTable = table "user_to_role" (
|
||||||
|
p2
|
||||||
|
( tableField "user_id"
|
||||||
|
, tableField "role_id"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue