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,7 +152,9 @@ function modpol.interactions.org_dashboard(user, org_string)
local children = {}
for k,v in ipairs(org.children) do
local this_child = modpol.orgs.get_org(v)
table.insert(children, this_child.name)
if this_child then
table.insert(children, this_child.name)
end
end
-- prepare modules menu

View File

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

View File

@ -25,19 +25,24 @@ end
--- Return org when given its id or name
-- @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
function modpol.orgs.get_org(arg)
if type(arg) == 'string' then
for id, org in ipairs(modpol.orgs.array) do
local output = nil
if type(arg) == 'string' then
for id, org in ipairs(modpol.orgs.array) do
if org ~= "deleted" then
if org.name == arg then
return org
output = org
end
end
elseif type(arg) == 'number' then
return modpol.orgs.array[arg]
end
return nil
end
end
elseif type(arg) == 'number' then
if modpol.orgs.array[arg] ~= "deleted" then
output = modpol.orgs.array[arg]
end
end
return output
end
--- Return a table list of all org names
@ -80,7 +85,7 @@ function modpol.orgs.reset()
modpol.util.copy_table(modpol.instance.members)
for id, org in ipairs(modpol.orgs.array) do
if id > 1 then
modpol.orgs.array[id] = "removed"
modpol.orgs.array[id] = "deleted"
end
end
@ -214,7 +219,18 @@ function modpol.orgs:delete()
modpol.ocutil.log('Error in ' .. self.name .. ':delete -> cannot delete instance')
return false
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
for i, child_id in pairs(self.children) do
local child = modpol.orgs.get_org(child_id)
@ -223,7 +239,7 @@ function modpol.orgs:delete()
end
end
modpol.orgs.array[self.id] = 'removed'
modpol.orgs.array[self.id] = 'deleted'
modpol.orgs.count = modpol.orgs.count - 1
modpol.ocutil.log('Deleted org ' .. self.name .. ': ' .. self.id)

View File

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

View File

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