Removed child org from parent children list

This commit is contained in:
Nathan Schneider
2022-08-26 15:59:38 -07:00
parent ec0e4aa9c1
commit 13eb58a3ee
5 changed files with 42 additions and 18 deletions

View File

@ -152,8 +152,10 @@ function modpol.interactions.org_dashboard(user, org_string)
local children = {} local children = {}
for k,v in ipairs(org.children) do for k,v in ipairs(org.children) do
local this_child = modpol.orgs.get_org(v) local this_child = modpol.orgs.get_org(v)
if this_child then
table.insert(children, this_child.name) table.insert(children, this_child.name)
end end
end
-- prepare modules menu -- prepare modules menu
local modules = {} local modules = {}

View File

@ -40,6 +40,8 @@ function defer:initiate(result)
function() function()
if result then result() end if result then result() end
end) end)
modpol.interactions.message(
self.initiator, "Defer: action sent to " .. defer_org.name)
end end
modpol.interactions.org_dashboard( modpol.interactions.org_dashboard(
self.initiator, self.org.id) self.initiator, self.org.id)

View File

@ -25,19 +25,24 @@ end
--- Return org when given its id or name --- Return org when given its id or name
-- @function modpol.orgs.get_org -- @function modpol.orgs.get_org
-- @param arg string for name of org or id of org -- @param arg string for name of org or id of org, or nil if no org
-- @return org specified by id or name -- @return org specified by id or name
function modpol.orgs.get_org(arg) function modpol.orgs.get_org(arg)
local output = nil
if type(arg) == 'string' then if type(arg) == 'string' then
for id, org in ipairs(modpol.orgs.array) do for id, org in ipairs(modpol.orgs.array) do
if org ~= "deleted" then
if org.name == arg then if org.name == arg then
return org output = org
end
end end
end end
elseif type(arg) == 'number' then elseif type(arg) == 'number' then
return modpol.orgs.array[arg] if modpol.orgs.array[arg] ~= "deleted" then
output = modpol.orgs.array[arg]
end end
return nil end
return output
end end
--- Return a table list of all org names --- Return a table list of all org names
@ -80,7 +85,7 @@ function modpol.orgs.reset()
modpol.util.copy_table(modpol.instance.members) modpol.util.copy_table(modpol.instance.members)
for id, org in ipairs(modpol.orgs.array) do for id, org in ipairs(modpol.orgs.array) do
if id > 1 then if id > 1 then
modpol.orgs.array[id] = "removed" modpol.orgs.array[id] = "deleted"
end end
end end
@ -215,6 +220,17 @@ function modpol.orgs:delete()
return false return false
end end
-- remove from parent's list
local parent = modpol.orgs.get_org(self.id)
if parent then
for k,v in ipairs(parent.children) do
if v == self.id then
v = "deleted"
end
end
end
-- remove children
if #self.children > 0 then if #self.children > 0 then
for i, child_id in pairs(self.children) do for i, child_id in pairs(self.children) do
local child = modpol.orgs.get_org(child_id) local child = modpol.orgs.get_org(child_id)
@ -223,7 +239,7 @@ function modpol.orgs:delete()
end end
end end
modpol.orgs.array[self.id] = 'removed' modpol.orgs.array[self.id] = 'deleted'
modpol.orgs.count = modpol.orgs.count - 1 modpol.orgs.count = modpol.orgs.count - 1
modpol.ocutil.log('Deleted org ' .. self.name .. ': ' .. self.id) modpol.ocutil.log('Deleted org ' .. self.name .. ': ' .. self.id)

View File

@ -134,7 +134,7 @@ end
-- @param user -- @param user
function modpol.orgs:remove_pending_action(process_id, user) function modpol.orgs:remove_pending_action(process_id, user)
if self.pending[user] then if self.pending[user] then
self.pending[user][process_id] = nil self.pending[user][process_id] = "deleted"
end end
end end
@ -143,7 +143,7 @@ end
-- @param process_id -- @param process_id
function modpol.orgs:wipe_pending_actions(process_id) function modpol.orgs:wipe_pending_actions(process_id)
for user in pairs(self.pending) do for user in pairs(self.pending) do
self.pending[user][process_id] = nil self.pending[user][process_id] = "deleted"
end end
end end

View File

@ -137,11 +137,15 @@ function modpol.interactions.org_dashboard(user, org_string)
-- prepare children menu -- prepare children menu
local children = {} local children = {}
if org.children then
for k,v in ipairs(org.children) do for k,v in ipairs(org.children) do
local this_child = modpol.orgs.get_org(v) local this_child = modpol.orgs.get_org(v)
if this_child then
table.insert(children, this_child.name) table.insert(children, this_child.name)
end end
end
table.sort(children) table.sort(children)
end
-- prepare modules menu -- prepare modules menu
local modules = {} local modules = {}