Would the following serve as a good example of how to model the way that employers assign roles to employees?
import Daml.Script
import DA.List
template DocumentManager with
employer : Party
employee : Party
where
signatory employer
observer employee
nonconsuming choice CreateDocument : ContractId Document with
controller employee
do create Document with
observers = [employee]
value = 1
..
nonconsuming choice EditDocument : ContractId Document with
doc : ContractId Document
controller employee
do exercise doc Edit
template Document with
employer : Party
value : Int
observers : [Party]
where
signatory employer
observer observers
choice Edit : ContractId Document
controller employer
do create this with value = value + 1
choice ChangeAcceess : ContractId Document with
removes : [Party]
adds : [Party]
controller employer
do
create this with
observers = dedup $ foldr delete (adds ++ observers) removes
demo : Script ()
demo = script do
bank <- allocateParty "Bank"
-- bob joins the company and does some work
bob <- allocateParty "Bob"
bobRole <- submit bank $ createCmd DocumentManager with employer = bank, employee = bob
doc1 <- submit bob $ exerciseCmd bobRole CreateDocument
doc1 <- submit bob $ exerciseCmd bobRole EditDocument with doc = doc1
doc1 <- submit bob $ exerciseCmd bobRole EditDocument with doc = doc1
doc1 <- submit bob $ exerciseCmd bobRole EditDocument with doc = doc1
doc1 <- submit bob $ exerciseCmd bobRole EditDocument with doc = doc1
-- alice joins the company and does some work
alice <- allocateParty "Alice"
aliceRole <- submit bank $ createCmd DocumentManager with employer = bank, employee = alice
doc2 <- submit alice $ exerciseCmd aliceRole CreateDocument
doc2 <- submit alice $ exerciseCmd aliceRole EditDocument with doc = doc2
doc2 <- submit alice $ exerciseCmd aliceRole EditDocument with doc = doc2
-- alice initially cannot edit bob's docs
submitMustFail alice $ exerciseCmd aliceRole EditDocument with doc = doc1
-- alice get's access to bob's docs and does some work
doc1 <- submit bank $ exerciseCmd doc1 ChangeAcceess with adds = [alice], removes = []
doc1 <- submit alice $ exerciseCmd aliceRole EditDocument with doc = doc1
-- bob leaves the company
submit bank $ archiveCmd bobRole
doc1 <- submit bank $ exerciseCmd doc1 ChangeAcceess with removes = [bob], adds = []
submitMustFail bob $ exerciseCmd bobRole EditDocument with doc = doc1
-- alice continues work
doc1 <- submit alice $ exerciseCmd aliceRole EditDocument with doc = doc1
doc2 <- submit alice $ exerciseCmd aliceRole EditDocument with doc = doc2
pure()