Merge branch 'join-created-orgs' into 'master'
created orgs start with a member See merge request medlabboulder/modpol!23
This commit is contained in:
commit
f837e99077
@ -75,6 +75,10 @@ function modpol.orgs.reset()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
modpol.orgs.array[1] = nil
|
||||||
|
modpol.instance = modpol.orgs.init_instance()
|
||||||
|
|
||||||
|
|
||||||
modpol.ocutil.log('Reset all orgs')
|
modpol.ocutil.log('Reset all orgs')
|
||||||
modpol.orgs:record('Resetting all orgs', 'org_reset')
|
modpol.orgs:record('Resetting all orgs', 'org_reset')
|
||||||
end
|
end
|
||||||
@ -144,7 +148,7 @@ end
|
|||||||
-- ==================================================
|
-- ==================================================
|
||||||
-- adds a new sub org to the org it is called on
|
-- adds a new sub org to the org it is called on
|
||||||
-- ex: instance:add_org('town hall')
|
-- ex: instance:add_org('town hall')
|
||||||
function modpol.orgs:add_org(name)
|
function modpol.orgs:add_org(name, user)
|
||||||
if self.id == nil then
|
if self.id == nil then
|
||||||
modpol.ocutil.log('Error in ' .. self.name .. ':add_org -> add_org can only be called by another org')
|
modpol.ocutil.log('Error in ' .. self.name .. ':add_org -> add_org can only be called by another org')
|
||||||
return false
|
return false
|
||||||
@ -175,6 +179,9 @@ function modpol.orgs:add_org(name)
|
|||||||
-- adding child to org list
|
-- adding child to org list
|
||||||
modpol.orgs.array[child_org.id] = child_org
|
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')
|
self:record('created sub org ' .. name, 'add_org')
|
||||||
modpol.ocutil.log('Created ' .. name .. ' (suborg of ' .. self.name .. ')')
|
modpol.ocutil.log('Created ' .. name .. ' (suborg of ' .. self.name .. ')')
|
||||||
|
|
||||||
|
@ -79,17 +79,18 @@ 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
|
-- there's probably a way to clean this up, the issue is the varying number of commands
|
||||||
-- ex: self['add_member'](self, 'member_name')
|
-- ex: self['add_member'](self, 'member_name')
|
||||||
-- not sure if this is safe, more testing to do
|
-- not sure if this is safe, more testing to do
|
||||||
self[request.type](self, p[1], p[2], p[3])
|
|
||||||
|
|
||||||
-- if request.type == "add_org" then
|
-- self[request.type](self, p[1], p[2], p[3])
|
||||||
-- self:add_org(p[1])
|
|
||||||
-- elseif request.type == "delete" then
|
if request.type == "add_org" then
|
||||||
-- self:delete()
|
self:add_org(request.params[1], request.user)
|
||||||
-- elseif request.type == "add_member" then
|
elseif request.type == "delete" then
|
||||||
-- self:add_member(p[1])
|
self:delete()
|
||||||
-- elseif request.type == "remove_member" then
|
elseif request.type == "add_member" then
|
||||||
-- self:remove_member(p[1])
|
self:add_member(request.params[1])
|
||||||
-- end
|
elseif request.type == "remove_member" then
|
||||||
|
self:remove_member(request.params[1])
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -127,6 +128,9 @@ function modpol.orgs:make_request(request)
|
|||||||
|
|
||||||
-- checking to see if user is able to make request
|
-- checking to see if user is able to make request
|
||||||
local requested_policy = self.policies[request.type]
|
local requested_policy = self.policies[request.type]
|
||||||
|
|
||||||
|
-- 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]
|
local parent_policy = modpol.orgs.get_org(self.parent).policies[request.type]
|
||||||
|
|
||||||
-- tries to use org's policy table, defers to parent otherwise
|
-- tries to use org's policy table, defers to parent otherwise
|
||||||
@ -140,6 +144,14 @@ function modpol.orgs:make_request(request)
|
|||||||
end
|
end
|
||||||
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
|
||||||
|
|
||||||
-- make sure user is allowed to make request
|
-- make sure user is allowed to make request
|
||||||
if requested_policy.must_be_member and not self:has_member(request.user) then
|
if requested_policy.must_be_member and not self:has_member(request.user) then
|
||||||
modpol.ocutil.log('Error in ' .. self.name .. ':make_request -> user must be org member to make this request')
|
modpol.ocutil.log('Error in ' .. self.name .. ':make_request -> user must be org member to make this request')
|
||||||
|
@ -4,20 +4,20 @@ print('\nRemoving existing orgs')
|
|||||||
modpol.orgs.reset()
|
modpol.orgs.reset()
|
||||||
|
|
||||||
print('\nCreating an org called "test_org"')
|
print('\nCreating an org called "test_org"')
|
||||||
test_org = modpol.instance:add_org('test_org')
|
test_org = modpol.instance:add_org('test_org', 'luke')
|
||||||
|
|
||||||
print('\nTrying to create an org with the same name')
|
print('\nTrying to create an org with the same name')
|
||||||
duplicate = modpol.instance:add_org('test_org')
|
duplicate = modpol.instance:add_org('test_org', 'luke')
|
||||||
|
|
||||||
print('\nAdding user "luke" to test_org')
|
print('\nAdding user "nathan" to test_org')
|
||||||
test_org:add_member('luke')
|
test_org:add_member('nathan')
|
||||||
|
|
||||||
print('\nTrying to add duplicate user to test_org')
|
print('\nTrying to add duplicate user to test_org')
|
||||||
test_org:add_member('luke')
|
test_org:add_member('nathan')
|
||||||
|
|
||||||
print('\nRemoving user "luke" from test_org')
|
print('\nRemoving user "nathan" from test_org')
|
||||||
test_org:remove_member('luke')
|
test_org:remove_member('nathan')
|
||||||
|
|
||||||
print('\nTrying to remove user "luke" from empty member list')
|
print('\nTrying to remove user "nathan" from empty member list')
|
||||||
test_org:remove_member('luke')
|
test_org:remove_member('nathan')
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ dofile('../modpol.lua');
|
|||||||
|
|
||||||
modpol.orgs.reset()
|
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('luke')
|
||||||
test_org:add_member('nathan')
|
test_org:add_member('nathan')
|
||||||
|
|
||||||
@ -24,3 +24,22 @@ end
|
|||||||
-- process = test_org.processes[process_id]
|
-- process = test_org.processes[process_id]
|
||||||
-- process:approve("luke", true)
|
-- 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"}
|
||||||
|
}
|
||||||
|
|
||||||
|
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