diff --git a/modpol_core/api.lua b/modpol_core/api.lua index dea3ba3..6af2d5a 100644 --- a/modpol_core/api.lua +++ b/modpol_core/api.lua @@ -25,6 +25,7 @@ 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/remove_process.lua") dofile (localdir .. "/modules/rename_org_consent.lua") dofile (localdir .. "/modules/send_token.lua") dofile (localdir .. "/modules/tokenomics.lua") diff --git a/modpol_core/interactions/interactions.lua b/modpol_core/interactions/interactions.lua index 451d7fd..498dda4 100644 --- a/modpol_core/interactions/interactions.lua +++ b/modpol_core/interactions/interactions.lua @@ -49,7 +49,7 @@ function modpol.interactions.dashboard(user) print('All users: ' .. table.concat(all_users, ', ')) print() - print("Commands: (O)rg, (U)ser, (R)eset, Enter to close") + print("Commands: (O)rg, (U)ser, (R)eset, (Q)uit") local sel = io.read() @@ -75,20 +75,21 @@ function modpol.interactions.dashboard(user) function() modpol.interactions.dashboard(user) end - ) - - elseif sel == "" then - return - + ) else print("User name not found") modpol.interactions.dashboard(user) end + elseif sel == "R" or sel == "r" then modpol.instance.members = {} modpol.orgs.reset() print("Orgs and users reset") modpol.interactions.dashboard(user) + + elseif sel == "Q" or "q" then + return + else print("Invalid input, try again") modpol.interactions.dashboard(user) diff --git a/modpol_core/modules/consent.lua b/modpol_core/modules/consent.lua index c46806e..8e7f7dc 100644 --- a/modpol_core/modules/consent.lua +++ b/modpol_core/modules/consent.lua @@ -41,6 +41,12 @@ function consent:callback(member) if resp == "Yes" then self.data.votes = self.data.votes + 1 end + modpol.interactions.message_org( + "consent", self.org.id, + member.." decided "..resp.." on: ".. + self.config.prompt.." ("..self.data.votes.. + "/"..self.config.votes_required..")" + ) if self.data.votes >= self.config.votes_required then if self.data.result then self.data.result() end diff --git a/modpol_core/modules/remove_process.lua b/modpol_core/modules/remove_process.lua new file mode 100644 index 0000000..d382284 --- /dev/null +++ b/modpol_core/modules/remove_process.lua @@ -0,0 +1,113 @@ +--- remove_process +-- @module remove_process + +local remove_process = { + name = "Remove process", + slug = "remove_process", + desc = "User can remove own processes, consent required for those of others", + hide = false; +} + +--- (Required) Data for module +-- Variables that module uses during the course of a process +-- Can be blank +remove_process.data = { +} + +remove_process.config = { +} + +--- (Required): initiate function +-- @param result (optional) Callback if this module is embedded in other modules +-- @function initiate +function remove_process:initiate(result) + -- prepare process options + local available_processes = {} + for k,process in pairs(self.org.processes) do + if process ~= "deleted" then + available_processes[process.id] = modpol.util.copy_table(process) + end + end + local process_list = {} + local process_count = 0 + for k,v in pairs(available_processes) do + local mine = "" + if v.initiator == self.initiator then mine = "*" end + table.insert(process_list,"["..v.id.."] "..v.slug..mine) + process_count = process_count + 1 + end + -- abort if no processes to remove + if process_count == 0 then + modpol.interactions.message( + self.initiator, "Org has no modules") + modpol.interactions.org_dashboard( + self.initiator, self.org.id) + if result then result() end + self.org:delete_process(self.id) + return + end + table.sort(process_list) + -- now ask which to remove + modpol.interactions.dropdown_query( + self.initiator, "Choose a process to remove (* marks yours, no consent required):", + process_list, + function(process_choice) + -- confirm choice + local process_id = tonumber( + string.match(process_choice, "%d+")) + local process_mine = string.match(process_choice, + "%*") + modpol.interactions.binary_poll_user( + self.initiator, + "Confirm: Remove process \"".. + process_choice .. "\"?", + function(input) + if input == "Yes" then + if process_mine then + self.org:delete_process(process_id) + modpol.interactions.message( + self.initiator, + "Removed process: "..process_choice) + modpol.interactions.org_dashboard( + self.initiator, self.org.id) + if result then result() end + self.org:delete_process(self.id) + else + self.org:call_module( + "consent", + self.initiator, + { + prompt = "Approve removal of process "..process_choice.."?", + votes_required = #self.org.members + }, + function(input) + modpol.interactions.message_org( + self.initiator, + self.org.id, + "Removing process: ".. + process_choice) + self.org:delete_process(process_id) + modpol.interactions.org_dashboard( + self.initiator, self.org.id) + if result then result() end + self.org:delete_process(self.id) + end + ) + end + modpol.interactions.org_dashboard( + self.initiator, self.org.id) + else + modpol.interactions.org_dashboard( + self.initiator, self.org.id) + if result then result() end + self.org:delete_process(self.id) + end + end + ) + end + ) +end + + +--- (Required) Add to module table +modpol.modules.remove_process = remove_process diff --git a/modpol_core/orgs/process.lua b/modpol_core/orgs/process.lua index cb5ae0a..9ebb03b 100644 --- a/modpol_core/orgs/process.lua +++ b/modpol_core/orgs/process.lua @@ -57,11 +57,14 @@ function modpol.orgs:call_module(module_slug, initiator, config, result) end function modpol.orgs:delete_process(id) - local msg = "Deleting "..self.processes[id].slug.. - " process id "..id.." in org "..self.name - self:record(msg, self.processes[id].slug) - self:wipe_pending_actions(id) - self.processes[id] = 'deleted' + if self.processes[id] + and self.processes[id] ~= "deleted" then + local msg = "Deleting "..self.processes[id].slug.. + " process id "..id.." in org "..self.name + self:record(msg, self.processes[id].slug) + self:wipe_pending_actions(id) + self.processes[id] = 'deleted' + end end function modpol.orgs:add_pending_action(process_id, user, callback) @@ -101,7 +104,7 @@ function modpol.orgs:interact(process_id, user) local process = self.processes[process_id] if self.pending[user] then local callback = self.pending[user][process_id] - if callback then + if callback and process ~= "deleted" then -- get data in case callback ends process local slug = self.processes[process_id].slug -- run callback