orgs are now initialized with a founding member
This commit is contained in:
parent
9d81d57a54
commit
28e31eebc9
@ -144,7 +144,7 @@ end
|
||||
-- ==================================================
|
||||
-- adds a new sub org to the org it is called on
|
||||
-- ex: instance:add_org('town hall')
|
||||
function modpol.orgs:add_org(name)
|
||||
function modpol.orgs:add_org(name, user)
|
||||
if self.id == nil then
|
||||
modpol.ocutil.log('Error in ' .. self.name .. ':add_org -> add_org can only be called by another org')
|
||||
return false
|
||||
@ -175,6 +175,9 @@ function modpol.orgs:add_org(name)
|
||||
-- adding child to org list
|
||||
modpol.orgs.array[child_org.id] = child_org
|
||||
|
||||
-- adding creator of org as the first member
|
||||
child_org:add_member(user)
|
||||
|
||||
self:record('created sub org ' .. name, 'add_org')
|
||||
modpol.ocutil.log('Created ' .. name .. ' (suborg of ' .. self.name .. ')')
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
modpol.orgs.request_params = {
|
||||
add_org = 1,
|
||||
add_org = 2,
|
||||
delete = 0,
|
||||
add_member = 1,
|
||||
remove_member = 1
|
||||
@ -79,6 +79,7 @@ function modpol.orgs:resolve_request(request_id, approve)
|
||||
-- there's probably a way to clean this up, the issue is the varying number of commands
|
||||
-- ex: self['add_member'](self, 'member_name')
|
||||
-- not sure if this is safe, more testing to do
|
||||
print(p[1], p[2])
|
||||
self[request.type](self, p[1], p[2], p[3])
|
||||
|
||||
-- if request.type == "add_org" then
|
||||
@ -127,15 +128,26 @@ function modpol.orgs:make_request(request)
|
||||
|
||||
-- checking to see if user is able to make request
|
||||
local requested_policy = self.policies[request.type]
|
||||
local parent_policy = modpol.orgs.get_org(self.parent).policies[request.type]
|
||||
|
||||
-- tries to use org's policy table, defers to parent otherwise
|
||||
if not requested_policy then
|
||||
modpol.ocutil.log(request.type .. ' policy not found, deferring to parent org')
|
||||
requested_policy = parent_policy
|
||||
-- if not the instance org (instance's don't have parents)
|
||||
if self.id ~= 1 then
|
||||
local parent_policy = modpol.orgs.get_org(self.parent).policies[request.type]
|
||||
|
||||
if not parent_policy then
|
||||
modpol.ocutil.log('Error in ' .. self.name .. ':make_request -> parent policy undefined')
|
||||
-- tries to use org's policy table, defers to parent otherwise
|
||||
if not requested_policy then
|
||||
modpol.ocutil.log(request.type .. ' policy not found, deferring to parent org')
|
||||
requested_policy = parent_policy
|
||||
|
||||
if not parent_policy then
|
||||
modpol.ocutil.log('Error in ' .. self.name .. ':make_request -> parent policy undefined')
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- fails if instance policy undefined
|
||||
else
|
||||
if not requested_policy then
|
||||
modpol.ocutil.log('Error in ' .. self.name .. ':make_request -> policy undefined')
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
@ -2,7 +2,7 @@ dofile('../modpol.lua');
|
||||
|
||||
modpol.orgs.reset()
|
||||
|
||||
test_org = modpol.instance:add_org('test_org')
|
||||
test_org = modpol.instance:add_org('test_org', 'lukvmil')
|
||||
test_org:add_member('luke')
|
||||
test_org:add_member('nathan')
|
||||
|
||||
@ -23,4 +23,23 @@ for id, process in ipairs(test_org.processes) do
|
||||
end
|
||||
-- process = test_org.processes[process_id]
|
||||
-- process:approve("luke", true)
|
||||
-- process:approve("nathan", true)
|
||||
-- process:approve("nathan", true)
|
||||
|
||||
modpol.instance:set_policy("add_org", "consent", false);
|
||||
|
||||
new_request = {
|
||||
user = "lukvmil",
|
||||
type = "add_org",
|
||||
params = {"new_org", "lukvmil"}
|
||||
}
|
||||
|
||||
request_id = modpol.instance:make_request(new_request)
|
||||
|
||||
modpol.instance:add_member('luke')
|
||||
modpol.instance:add_member('josh')
|
||||
modpol.instance:add_member('nathan')
|
||||
|
||||
for id, process in ipairs(modpol.instance.processes) do
|
||||
process:approve('luke', true)
|
||||
process:approve('josh', true)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user