Adding and fixing basic modules for renaming, removing, and adding orgs
This commit is contained in:
@ -11,9 +11,12 @@ dofile (localdir .. "/interactions/interactions.lua")
|
||||
|
||||
--modules
|
||||
--TODO make this automatic and directory-based
|
||||
dofile (localdir .. "/modules/add_child_org.lua")
|
||||
dofile (localdir .. "/modules/add_child_org_consent.lua")
|
||||
dofile (localdir .. "/modules/consent.lua")
|
||||
dofile (localdir .. "/modules/join_org_consent.lua")
|
||||
dofile (localdir .. "/modules/leave_org.lua")
|
||||
dofile (localdir .. "/modules/remove_child_consent.lua")
|
||||
dofile (localdir .. "/modules/remove_member_consent.lua")
|
||||
dofile (localdir .. "/modules/remove_org_consent.lua")
|
||||
dofile (localdir .. "/modules/remove_org.lua")
|
||||
dofile (localdir .. "/modules/rename_org_consent.lua")
|
||||
|
@ -48,10 +48,10 @@ end
|
||||
|
||||
|
||||
-- Function: modpol.interactions.org_dashboard
|
||||
-- Params: user (string), org_name (string)
|
||||
-- Params: user (string), org_string (string or id)
|
||||
-- Output: Displays a menu of org-specific commands to the user
|
||||
function modpol.interactions.org_dashboard(user, org_name)
|
||||
local org = modpol.orgs.get_org(org_name)
|
||||
function modpol.interactions.org_dashboard(user, org_string)
|
||||
local org = modpol.orgs.get_org(org_string)
|
||||
if not org then return nil end
|
||||
|
||||
-- identify parent
|
||||
@ -72,11 +72,13 @@ function modpol.interactions.org_dashboard(user, org_name)
|
||||
-- list available modules
|
||||
local org_modules = {}
|
||||
for k,v in pairs(org.modules) do
|
||||
table.insert(org_modules, v.slug)
|
||||
if not v.hide then
|
||||
table.insert(org_modules, v.slug)
|
||||
end
|
||||
end
|
||||
|
||||
-- list pending actions
|
||||
local process_msg = #org.processes .. " total actions"
|
||||
-- list pending
|
||||
local process_msg = #org.processes .. " total processes"
|
||||
if org.pending[user] then
|
||||
process_msg = process_msg .. " (" .. #org.pending[user] .. " pending)"
|
||||
else
|
||||
@ -84,14 +86,14 @@ function modpol.interactions.org_dashboard(user, org_name)
|
||||
end
|
||||
|
||||
-- set up output
|
||||
print("Org: " .. org_name)
|
||||
print("Org: " .. org.name)
|
||||
print("Parent: " .. parent)
|
||||
print("Members: " .. table.concat(org.members, ", "))
|
||||
print("Children: " .. table.concat(children, ", "))
|
||||
print("Modules: " .. table.concat(org_modules, ", "))
|
||||
print("Actions: " .. process_msg)
|
||||
print("Pending: " .. process_msg)
|
||||
print()
|
||||
print("Commands: (M)odules, (A)ctions")
|
||||
print("Commands: (M)odules, (P)ending")
|
||||
|
||||
local sel = io.read()
|
||||
print()
|
||||
@ -114,7 +116,7 @@ function modpol.interactions.org_dashboard(user, org_name)
|
||||
|
||||
elseif sel == 'a' or sel == 'A' then
|
||||
local processes = {}
|
||||
print("All processes: (* indicates pending action)")
|
||||
print("All processes: (* indicates pending)")
|
||||
for k,v in ipairs(org.processes) do
|
||||
local active = ''
|
||||
if org.pending[user] then
|
||||
@ -135,7 +137,7 @@ function modpol.interactions.org_dashboard(user, org_name)
|
||||
end
|
||||
else
|
||||
print("Command not found")
|
||||
modpol.interactions.org_dashboard(user, org_name)
|
||||
modpol.interactions.org_dashboard(user, org.name)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,20 +1,21 @@
|
||||
--- @module add_child_org
|
||||
--- @module add_child_org_consent
|
||||
-- Adds a child org
|
||||
-- Depends on `consent`
|
||||
|
||||
local add_child_org = {
|
||||
name = "Add child org",
|
||||
slug = "add_child_org",
|
||||
desc = "Create a child org within the current one with consent"
|
||||
local add_child_org_consent = {
|
||||
name = "Add child org (consent)",
|
||||
slug = "add_child_org_consent",
|
||||
desc = "Create a child org in the current one with member consent"
|
||||
}
|
||||
add_child_org.data = {
|
||||
child_name = ""
|
||||
add_child_org_consent.data = {
|
||||
child_name = "",
|
||||
result = nil
|
||||
}
|
||||
add_child_org.config = {
|
||||
add_child_org_consent.config = {
|
||||
}
|
||||
|
||||
-- @function initiate
|
||||
function add_child_org:initiate(config, result)
|
||||
function add_child_org_consent:initiate(result)
|
||||
modpol.interactions.text_query(
|
||||
self.initiator,"Child org name: ",
|
||||
function(input)
|
||||
@ -22,8 +23,21 @@ function add_child_org:initiate(config, result)
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"No name entered for child org")
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.name)
|
||||
self.org:delete_process(self.id)
|
||||
if result then result() end
|
||||
return
|
||||
elseif modpol.orgs.get_org(input) then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"Org name already in use")
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.name)
|
||||
self.org:delete_process(self.id)
|
||||
return end
|
||||
if result then result() end
|
||||
return
|
||||
end
|
||||
self.data.child_name = input
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
@ -47,14 +61,15 @@ function add_child_org:initiate(config, result)
|
||||
)
|
||||
end
|
||||
|
||||
function add_child_org:create_child_org()
|
||||
function add_child_org_consent:create_child_org()
|
||||
self.org:add_org(self.data.child_name, self.initiator)
|
||||
modpol.interactions.message_org(
|
||||
self.initiator,
|
||||
self.org.name,
|
||||
"Child org created: "..self.data.child_name)
|
||||
if self.data.result then self.data.result() end
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
|
||||
--- (Required) Add to module table
|
||||
modpol.modules.add_child_org = add_child_org
|
||||
modpol.modules.add_child_org_consent = add_child_org_consent
|
@ -2,9 +2,10 @@
|
||||
-- A utility module for checking consent
|
||||
|
||||
local consent = {
|
||||
name = "Consent",
|
||||
name = "Consent process utility",
|
||||
slug = "consent",
|
||||
desc = "Other modules can use to implement consent based decision making",
|
||||
desc = "A module other modules use for consent decisions",
|
||||
hide = true
|
||||
}
|
||||
|
||||
consent.data = {
|
||||
@ -46,6 +47,8 @@ function consent:callback(member)
|
||||
self.org:wipe_pending_actions(self.id)
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
modpol.interactions.org_dashboard(
|
||||
member, self.org.name)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
@ -3,21 +3,30 @@
|
||||
-- Depends on the Consent module.
|
||||
|
||||
local join_org_consent = {
|
||||
name = "Join this org",
|
||||
name = "Join this org (consent)",
|
||||
slug = "join_org_consent",
|
||||
desc = "Adds member with consent of all members."
|
||||
desc = "Adds member with consent of all members"
|
||||
}
|
||||
|
||||
join_org_consent.data = {
|
||||
result = nil
|
||||
}
|
||||
|
||||
join_org_consent.config = {
|
||||
}
|
||||
|
||||
function join_org_consent:initiate(result)
|
||||
self.org:call_module(
|
||||
"consent",
|
||||
self.initiator,
|
||||
function join_org_consent:initiate(result)
|
||||
if self.org:has_member(self.initiator) then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"You are already a member of this org")
|
||||
if result then result() end
|
||||
self.org:delete_process(self.id)
|
||||
else
|
||||
self.data.result = result
|
||||
self.org:call_module(
|
||||
"consent",
|
||||
self.initiator,
|
||||
{
|
||||
prompt = "Allow " .. self.initiator .. " to join?",
|
||||
votes_required = #self.org.members
|
||||
@ -26,12 +35,17 @@ function join_org_consent:initiate(result)
|
||||
self:complete()
|
||||
end
|
||||
)
|
||||
if result then result() end
|
||||
end
|
||||
end
|
||||
|
||||
function join_org_consent:complete()
|
||||
self.org:add_member(self.initiator)
|
||||
print("Added " .. self.initiator .. " to the org.")
|
||||
self.org:add_member(self.initiator)
|
||||
modpol.interactions.message_org(
|
||||
self.initiator,self.org.name,
|
||||
"Consent reached: " .. self.initiator ..
|
||||
" joined org " .. self.org.name)
|
||||
if self.data.result then self.data.result() end
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
|
||||
modpol.modules.join_org_consent = join_org_consent
|
||||
|
@ -4,7 +4,7 @@
|
||||
local leave_org = {
|
||||
name = "Leave org",
|
||||
slug = "leave_org",
|
||||
desc = "Leave this org"
|
||||
desc = "Remove yourself from the current org"
|
||||
}
|
||||
|
||||
leave_org.data = {
|
||||
@ -19,9 +19,9 @@ leave_org.config = {
|
||||
-- @function initiate
|
||||
function leave_org:initiate(result)
|
||||
if self.org == modpol.instance then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"You cannot leave the root org")
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"You cannot leave the root org")
|
||||
else
|
||||
self.org:remove_member(self.initiator)
|
||||
modpol.interactions.message_org(
|
||||
@ -32,6 +32,7 @@ function leave_org:initiate(result)
|
||||
"You have left org " .. self.org.name)
|
||||
end
|
||||
if result then result() end
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
|
||||
--- (Required) Add to module table
|
||||
|
71
modpol_core/modules/remove_child_consent.lua
Normal file
71
modpol_core/modules/remove_child_consent.lua
Normal file
@ -0,0 +1,71 @@
|
||||
--- Remove child (consent)
|
||||
-- A simple module that calls a consent process on an org to remove its child
|
||||
-- Depends on the Consent module.
|
||||
|
||||
local remove_child_consent = {
|
||||
name = "Remove child (consent)",
|
||||
slug = "remove_child_consent",
|
||||
desc = "Removes a child org if all members of this org consent."
|
||||
}
|
||||
|
||||
remove_child_consent.data = {
|
||||
result = nil,
|
||||
child_to_remove = nil
|
||||
}
|
||||
|
||||
remove_child_consent.config = {
|
||||
}
|
||||
|
||||
function remove_child_consent:initiate(result)
|
||||
local children = {}
|
||||
for i,v in ipairs(self.org.children) do
|
||||
local child = modpol.orgs.get_org(v)
|
||||
if child then table.insert(children, child.name) end
|
||||
end
|
||||
-- Abort if no child orgs
|
||||
if #children == 0 then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"Org has no children")
|
||||
if result then result() end
|
||||
self.org:delete_process(self.id)
|
||||
else
|
||||
self.data.result = result
|
||||
modpol.interactions.dropdown_query(
|
||||
self.initiator,
|
||||
"Which child of org "..self.org.name..
|
||||
" do you want to remove?",
|
||||
children,
|
||||
function(input)
|
||||
self.data.child_to_remove = modpol.orgs.get_org(input)
|
||||
self.org:call_module(
|
||||
"consent",
|
||||
self.initiator,
|
||||
{
|
||||
prompt = "Remove child org "..input.."?",
|
||||
votes_required = #self.org.members
|
||||
},
|
||||
function()
|
||||
self:complete()
|
||||
end)
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.name)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function remove_child_consent:complete()
|
||||
modpol.interactions.message_org(
|
||||
self.initiator, self.data.child_to_remove.id,
|
||||
"Removing org " .. self.data.child_to_remove.name ..
|
||||
" by parent org consent")
|
||||
modpol.interactions.message_org(
|
||||
self.initiator, self.org.id,
|
||||
"Consent reached: removing org " ..
|
||||
self.data.child_to_remove.name)
|
||||
self.data.child_to_remove:delete()
|
||||
if self.data.result then self.data.result() end
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
|
||||
modpol.modules.remove_child_consent = remove_child_consent
|
64
modpol_core/modules/remove_member_consent.lua
Normal file
64
modpol_core/modules/remove_member_consent.lua
Normal file
@ -0,0 +1,64 @@
|
||||
--- remove_member_consent
|
||||
-- @module remove_member_consent
|
||||
|
||||
local remove_member_consent = {
|
||||
name = "Remove a member (consent)",
|
||||
slug = "remove_member_consent",
|
||||
desc = "Removes org member with consent of other members"
|
||||
}
|
||||
|
||||
remove_member_consent.data = {
|
||||
member_to_remove = "",
|
||||
result = nil
|
||||
}
|
||||
|
||||
remove_member_consent.config = {
|
||||
}
|
||||
|
||||
function remove_member_consent:initiate(result)
|
||||
-- Abort if in root org
|
||||
if self.org == modpol.instance then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"Members cannot be removed from the root org")
|
||||
if result then result() end
|
||||
self.org:delete_process(self.id)
|
||||
else -- proceed if not root
|
||||
self.data.result = result
|
||||
modpol.interactions.dropdown_query(
|
||||
self.initiator,
|
||||
"Which member of org "..self.org.name..
|
||||
" do you want to remove?",
|
||||
self.org.members,
|
||||
function(input)
|
||||
self.data.member_to_remove = input
|
||||
self.org:call_module(
|
||||
"consent",
|
||||
self.initiator,
|
||||
{
|
||||
prompt = "Remove "..input..
|
||||
" from org "..self.org.name.."?",
|
||||
votes_required = #self.org.members - 1
|
||||
},
|
||||
function()
|
||||
self:complete()
|
||||
end)
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.name)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function remove_member_consent:complete()
|
||||
modpol.interactions.message_org(
|
||||
self.initiator, self.org.id,
|
||||
"Consent reached: removing "..
|
||||
self.data.member_to_remove..
|
||||
" from org "..self.org.name)
|
||||
self.org:remove_member(self.data.member_to_remove)
|
||||
self.org:delete_process(self.id)
|
||||
if self.data.result then self.data.result() end
|
||||
end
|
||||
|
||||
--- (Required) Add to module table
|
||||
modpol.modules.remove_member_consent = remove_member_consent
|
@ -18,7 +18,7 @@ function remove_org:initiate(result)
|
||||
if self.org == modpol.instance then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"You cannot remove the root org")
|
||||
"Cannot remove the root org")
|
||||
else
|
||||
modpol.interactions.message_org(
|
||||
self.initiator,self.org.id,
|
||||
|
@ -3,19 +3,28 @@
|
||||
-- Depends on the Consent module.
|
||||
|
||||
local remove_org_consent = {
|
||||
name = "Remove this org",
|
||||
name = "Remove this org (consent)",
|
||||
slug = "remove_org_consent",
|
||||
desc = "Removes an org if all members consent."
|
||||
}
|
||||
|
||||
remove_org_consent.data = {
|
||||
result = nil
|
||||
}
|
||||
|
||||
remove_org_consent.config = {
|
||||
}
|
||||
|
||||
function remove_org_consent:initiate(result)
|
||||
self.org:call_module(
|
||||
function remove_org_consent:initiate(result)
|
||||
if self.org == modpol.instance then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"Cannot remove root org")
|
||||
if result then result() end
|
||||
self.org:delete_process(self.id)
|
||||
else
|
||||
self.data.result = result
|
||||
self.org:call_module(
|
||||
"consent",
|
||||
self.initiator,
|
||||
{
|
||||
@ -25,17 +34,19 @@ function remove_org_consent:initiate(result)
|
||||
function ()
|
||||
self:complete()
|
||||
end
|
||||
)
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.name)
|
||||
if result then result() end
|
||||
)
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.name)
|
||||
end
|
||||
end
|
||||
|
||||
function remove_org_consent:complete()
|
||||
modpol.interactions.message_org(
|
||||
self.initiator, self.org.id,
|
||||
"Removing org: " .. self.org.name)
|
||||
self.org:delete()
|
||||
"Consent reached: removing org " .. self.org.name)
|
||||
if self.data.result then self.data.result() end
|
||||
self.org:delete_process(self.id)
|
||||
self.org:delete()
|
||||
end
|
||||
|
||||
modpol.modules.remove_org_consent = remove_org_consent
|
||||
|
77
modpol_core/modules/rename_org_consent.lua
Normal file
77
modpol_core/modules/rename_org_consent.lua
Normal file
@ -0,0 +1,77 @@
|
||||
--- Rename org (consent)
|
||||
-- A simple module that calls a consent process on an org to rename it.
|
||||
-- Depends on the Consent module.
|
||||
|
||||
local rename_org_consent = {
|
||||
name = "Rename this org (consent)",
|
||||
slug = "rename_org_consent",
|
||||
desc = "Renames an org if all members consent."
|
||||
}
|
||||
|
||||
rename_org_consent.data = {
|
||||
result = nil,
|
||||
new_name = nil
|
||||
}
|
||||
|
||||
rename_org_consent.config = {
|
||||
}
|
||||
|
||||
function rename_org_consent:initiate(result)
|
||||
modpol.interactions.text_query(
|
||||
self.initiator,"New org name: ",
|
||||
function(input)
|
||||
if input == "" then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"No name entered for child org")
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.name)
|
||||
self.org:delete_process(self.id)
|
||||
if result then result() end
|
||||
return
|
||||
elseif modpol.orgs.get_org(input) then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"Org name already in use")
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.name)
|
||||
self.org:delete_process(self.id)
|
||||
if result then result() end
|
||||
return
|
||||
end
|
||||
self.data.new_name = input
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"Proposed to change name of org " ..
|
||||
self.org.name .. " to " .. input)
|
||||
-- initiate consent process
|
||||
self.org:call_module(
|
||||
"consent",
|
||||
self.initiator,
|
||||
{
|
||||
prompt = "Change name of org " ..
|
||||
self.org.name .. " to " .. input .. "?",
|
||||
votes_required = #self.org.members
|
||||
},
|
||||
function()
|
||||
self:complete()
|
||||
end
|
||||
)
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.name)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
function rename_org_consent:complete()
|
||||
modpol.interactions.message_org(
|
||||
self.initiator,
|
||||
self.org.name,
|
||||
"Changing name of org " .. self.org.name ..
|
||||
" to " .. self.data.new_name)
|
||||
self.org.name = self.data.new_name
|
||||
if self.data.result then self.data.result() end
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
|
||||
modpol.modules.rename_org_consent = rename_org_consent
|
@ -1,20 +1,22 @@
|
||||
--- module_template
|
||||
-- @module module_template
|
||||
--- change_modules
|
||||
-- @module change_modules
|
||||
|
||||
--- (Required): data table containing name and description of the module
|
||||
-- @field name "Human-readable name"
|
||||
-- @field slug "Same as module class name"
|
||||
-- @field desc "Description of the module"
|
||||
local module_template = {
|
||||
-- @field hide "Whether this is a hidden utility module"
|
||||
local change_modules = {
|
||||
name = "Module Human-Readable Name",
|
||||
slug = "template",
|
||||
desc = "Description of the module"
|
||||
desc = "Description of the module",
|
||||
hide = false;
|
||||
}
|
||||
|
||||
--- (Required) Data for module
|
||||
-- Variables that module uses during the course of a process
|
||||
-- Can be blank
|
||||
module_template.data = {
|
||||
change_modules.data = {
|
||||
}
|
||||
|
||||
--- (Required): config for module
|
||||
@ -25,7 +27,7 @@ module_template.data = {
|
||||
-- Default values set in config can be overridden
|
||||
-- @field field_1 ex: votes_required, default = 5
|
||||
-- @field field_2 ex: voting_type, default = "majority"
|
||||
module_template.config = {
|
||||
change_modules.config = {
|
||||
field_1 = 5
|
||||
field_2 = "majority"
|
||||
}
|
||||
@ -37,12 +39,16 @@ module_template.config = {
|
||||
-- <li><code>self.id</code> (the process id of the module instance)</li>
|
||||
-- @param result (optional) Callback if this module is embedded in other modules
|
||||
-- @function initiate
|
||||
function module_template:initiate(result)
|
||||
-- call interaction functions here!
|
||||
function change_modules:initiate(result)
|
||||
-- call interaction functions here!
|
||||
|
||||
-- call result function
|
||||
if result then result() end
|
||||
-- concluding functions:
|
||||
-- call these wherever process might end;
|
||||
-- may need to put result in self.data.result
|
||||
-- if process ends in another function
|
||||
if result then result() end
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
|
||||
--- (Required) Add to module table
|
||||
modpol.modules.module_template = module_template
|
||||
modpol.modules.change_modules = change_modules
|
||||
|
Reference in New Issue
Block a user