added some notes to the modules, some not currently functional. rewriting process.lua to work with new modules, support pending actions
This commit is contained in:
parent
db43df6ce2
commit
f381845d21
@ -12,20 +12,20 @@ function join_org.initiate(initiator, org, result)
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
-- for i, member in ipairs(org.members) do
|
for i, member in ipairs(org.members) do
|
||||||
-- org:add_pending_action(
|
org:add_pending_action(
|
||||||
-- member,
|
member,
|
||||||
-- function ()
|
function ()
|
||||||
-- modpol.interactions.binary_poll_user(
|
modpol.interactions.binary_poll_user(
|
||||||
-- member,
|
member,
|
||||||
-- "Let " .. initiator .. " join " .. org.name .. "?",
|
"Let " .. initiator .. " join " .. org.name .. "?",
|
||||||
-- function (resp)
|
function (resp)
|
||||||
|
|
||||||
-- end
|
end
|
||||||
-- )
|
)
|
||||||
-- end
|
end
|
||||||
-- )
|
)
|
||||||
-- end
|
end
|
||||||
|
|
||||||
if result then result() end
|
if result then result() end
|
||||||
end
|
end
|
||||||
|
@ -23,11 +23,44 @@ function JoinOrg:initiate(result)
|
|||||||
"Would you like to join",
|
"Would you like to join",
|
||||||
function (resp)
|
function (resp)
|
||||||
if resp == "Yes" then
|
if resp == "Yes" then
|
||||||
self:implement()
|
|
||||||
|
modpol.call_module(
|
||||||
|
"consent",
|
||||||
|
"",
|
||||||
|
org,
|
||||||
|
result
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
modpol.modules.consent(
|
||||||
|
"Let " .. initiator .. " join " .. org.name .. "?",
|
||||||
|
org,
|
||||||
|
params,
|
||||||
|
self:on_failure,
|
||||||
|
self:on_success
|
||||||
|
)
|
||||||
|
|
||||||
|
-- for i, member in ipairs(org.members) do
|
||||||
|
-- org:add_pending_action(
|
||||||
|
-- member,
|
||||||
|
-- function ()
|
||||||
|
-- modpol.interactions.binary_poll_user(
|
||||||
|
-- member,
|
||||||
|
-- "Let " .. initiator .. " join " .. org.name .. "?",
|
||||||
|
-- function (resp)
|
||||||
|
-- self:vote()
|
||||||
|
-- end
|
||||||
|
-- )
|
||||||
|
-- end
|
||||||
|
-- )
|
||||||
|
-- end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if result then result() end
|
if result then result() end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -36,7 +69,7 @@ function JoinOrg:request()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function JoinOrg:implement()
|
function JoinOrg:on_success()
|
||||||
self.org:add_member(self.initiator)
|
self.org:add_member(self.initiator)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ function temp_org()
|
|||||||
remove_member={process_type='consent', must_be_member=false}
|
remove_member={process_type='consent', must_be_member=false}
|
||||||
},
|
},
|
||||||
processes = {},
|
processes = {},
|
||||||
requests = {},
|
-- requests = {},
|
||||||
pending = {},
|
pending = {},
|
||||||
members = {},
|
members = {},
|
||||||
parent = nil,
|
parent = nil,
|
||||||
|
@ -1,153 +1,33 @@
|
|||||||
old_request_format = {
|
function modpol.orgs:call_module(module_name, initiator)
|
||||||
user=user, -- requesting user
|
if not modpol.modules[module_name] then
|
||||||
type="add_member", -- action
|
modpol.ocutil.log('Error in ' .. self.name .. ':call_module -> module "' .. name .. '" not found')
|
||||||
params={user} -- action params
|
return
|
||||||
}
|
|
||||||
|
|
||||||
old_process_format = {
|
|
||||||
type = "consent", -- delete
|
|
||||||
id = nil,
|
|
||||||
org_id = nil,
|
|
||||||
request_id = nil, -- delete
|
|
||||||
|
|
||||||
-- consent config
|
|
||||||
majority_to_pass = 0.51, -- voting threshold
|
|
||||||
votes_needed = nil,
|
|
||||||
|
|
||||||
-- consent data
|
|
||||||
total_votes = 0,
|
|
||||||
votes_yes = {},
|
|
||||||
votes_no = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
new_process_format = {
|
|
||||||
initiator = "user",
|
|
||||||
status = "request",
|
|
||||||
org_id = 12314,
|
|
||||||
module = "create_child_org", -- policy table lookup
|
|
||||||
process_id = 8347,
|
|
||||||
timestamp = 1632850133, -- look into supporting other formats, overrides (turn based, etc.)
|
|
||||||
|
|
||||||
data = {
|
|
||||||
child_org_name = "oligarchy"
|
|
||||||
},
|
|
||||||
|
|
||||||
consent = {
|
|
||||||
-- voter eligibilty frozen by action table invites
|
|
||||||
start_time = 384179234,
|
|
||||||
member_count = 14,
|
|
||||||
votes_yes = {},
|
|
||||||
votes_no = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
-- initialize values
|
|
||||||
function init_consent(policy) {
|
|
||||||
self.start_time = os.time()
|
|
||||||
self.member_count = modpol.orgs.get_org(self.org_id):get_member_count()
|
|
||||||
|
|
||||||
if policy.duration then
|
|
||||||
-- mintest.after(time, func, ...args)
|
|
||||||
-- should override modpol callback function
|
|
||||||
register_callback(self.start_time + policy.duration)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if (duration and (consent_ratio or yes_threshold or no_threshold)) or (yes_threshold) or (consent_ratio) then
|
local module = modpol.modules[module_name]
|
||||||
-- well formed policy
|
local new_process = module.create(initiator, self)
|
||||||
else
|
|
||||||
-- invalid
|
|
||||||
end
|
|
||||||
|
|
||||||
}
|
table.insert(self.processes, new_process)
|
||||||
|
|
||||||
|
return new_process
|
||||||
|
end
|
||||||
|
|
||||||
-- update vote count
|
function modpol.orgs:create_process()
|
||||||
function update_consent(user, approve) {
|
|
||||||
if approve then
|
|
||||||
table.insert(yes_votes, user)
|
|
||||||
else
|
|
||||||
table.insert(no_votes, user)
|
|
||||||
|
|
||||||
if not duration then
|
end
|
||||||
eval_consent()
|
|
||||||
end
|
|
||||||
|
|
||||||
}
|
function modpol.orgs:add_pending_action()
|
||||||
|
|
||||||
-- evaluate state of vote
|
end
|
||||||
function eval_consent() {
|
|
||||||
consent_ratio = #yes_votes / (#yes_votes + #no_votes)
|
|
||||||
quorum = (#yes_votes + #no_votes) / member_count
|
|
||||||
|
|
||||||
if policy.duration then
|
function mopdol.orgs:remove_pending_action()
|
||||||
|
|
||||||
if policy.consent_ratio then
|
end
|
||||||
if policy.quorum then
|
|
||||||
if quorum < policy.quorum then
|
|
||||||
fail()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if consent_ratio >= policy.consent_ratio then
|
|
||||||
pass()
|
|
||||||
else
|
|
||||||
fail()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif policy.yes_threshold then
|
function modpol.orgs:wipe_pending_actions()
|
||||||
if #yes_votes >= policy.yes_threshold then
|
|
||||||
pass()
|
|
||||||
else
|
|
||||||
fail()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif policy.no_threshold then
|
end
|
||||||
if #no_votes <= policy.no_threshold then
|
|
||||||
fail()
|
|
||||||
else
|
|
||||||
pass()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif policy.yes_threshold then
|
function modpol.orgs:has_pending_actions()
|
||||||
if policy.no_threshold then
|
|
||||||
if #no_votes >= policy.no_threshold then
|
|
||||||
fail()
|
|
||||||
end
|
|
||||||
if #yes_votes >= policy.yes_threshold then
|
|
||||||
pass()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif policy.consent_ratio and policy.quorum then
|
end
|
||||||
if quorum >= policy.quorum then
|
|
||||||
if consent_ratio >= policy.consent_ratio then
|
|
||||||
pass()
|
|
||||||
else
|
|
||||||
fail()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
policy_table_format = {
|
|
||||||
"create_child_org": {
|
|
||||||
defer_to = nil,
|
|
||||||
|
|
||||||
-- duration
|
|
||||||
duration = nil, -- evaluates end conditions when reached
|
|
||||||
|
|
||||||
-- thesholds
|
|
||||||
no_threshold = nil, -- fails if reached
|
|
||||||
yes_threshold = nil, -- succeeds if reached
|
|
||||||
|
|
||||||
--ratios
|
|
||||||
consent_ratio = nil, -- % of voters
|
|
||||||
quorum = nil, -- % of members that vote
|
|
||||||
}
|
|
||||||
"create_child_org": {
|
|
||||||
consent_threshold = 0.51,
|
|
||||||
max_duration = 89324, -- seconds until vote closes if threshold not reached, or nil for no limit
|
|
||||||
defer = nil, -- org id to defer to, or nil
|
|
||||||
}
|
|
||||||
}
|
|
153
modpol/orgs/process_old.lua
Normal file
153
modpol/orgs/process_old.lua
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
old_request_format = {
|
||||||
|
user=user, -- requesting user
|
||||||
|
type="add_member", -- action
|
||||||
|
params={user} -- action params
|
||||||
|
}
|
||||||
|
|
||||||
|
old_process_format = {
|
||||||
|
type = "consent", -- delete
|
||||||
|
id = nil,
|
||||||
|
org_id = nil,
|
||||||
|
request_id = nil, -- delete
|
||||||
|
|
||||||
|
-- consent config
|
||||||
|
majority_to_pass = 0.51, -- voting threshold
|
||||||
|
votes_needed = nil,
|
||||||
|
|
||||||
|
-- consent data
|
||||||
|
total_votes = 0,
|
||||||
|
votes_yes = {},
|
||||||
|
votes_no = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
new_process_format = {
|
||||||
|
initiator = "user",
|
||||||
|
status = "request",
|
||||||
|
org_id = 12314,
|
||||||
|
module = "create_child_org", -- policy table lookup
|
||||||
|
process_id = 8347,
|
||||||
|
timestamp = 1632850133, -- look into supporting other formats, overrides (turn based, etc.)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
child_org_name = "oligarchy"
|
||||||
|
},
|
||||||
|
|
||||||
|
consent = {
|
||||||
|
-- voter eligibilty frozen by action table invites
|
||||||
|
start_time = 384179234,
|
||||||
|
member_count = 14,
|
||||||
|
votes_yes = {},
|
||||||
|
votes_no = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
-- initialize values
|
||||||
|
function init_consent(policy) {
|
||||||
|
self.start_time = os.time()
|
||||||
|
self.member_count = modpol.orgs.get_org(self.org_id):get_member_count()
|
||||||
|
|
||||||
|
if policy.duration then
|
||||||
|
-- mintest.after(time, func, ...args)
|
||||||
|
-- should override modpol callback function
|
||||||
|
register_callback(self.start_time + policy.duration)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (duration and (consent_ratio or yes_threshold or no_threshold)) or (yes_threshold) or (consent_ratio) then
|
||||||
|
-- well formed policy
|
||||||
|
else
|
||||||
|
-- invalid
|
||||||
|
end
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
-- update vote count
|
||||||
|
function update_consent(user, approve) {
|
||||||
|
if approve then
|
||||||
|
table.insert(yes_votes, user)
|
||||||
|
else
|
||||||
|
table.insert(no_votes, user)
|
||||||
|
|
||||||
|
if not duration then
|
||||||
|
eval_consent()
|
||||||
|
end
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
-- evaluate state of vote
|
||||||
|
function eval_consent() {
|
||||||
|
consent_ratio = #yes_votes / (#yes_votes + #no_votes)
|
||||||
|
quorum = (#yes_votes + #no_votes) / member_count
|
||||||
|
|
||||||
|
if policy.duration then
|
||||||
|
|
||||||
|
if policy.consent_ratio then
|
||||||
|
if policy.quorum then
|
||||||
|
if quorum < policy.quorum then
|
||||||
|
fail()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if consent_ratio >= policy.consent_ratio then
|
||||||
|
pass()
|
||||||
|
else
|
||||||
|
fail()
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif policy.yes_threshold then
|
||||||
|
if #yes_votes >= policy.yes_threshold then
|
||||||
|
pass()
|
||||||
|
else
|
||||||
|
fail()
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif policy.no_threshold then
|
||||||
|
if #no_votes <= policy.no_threshold then
|
||||||
|
fail()
|
||||||
|
else
|
||||||
|
pass()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif policy.yes_threshold then
|
||||||
|
if policy.no_threshold then
|
||||||
|
if #no_votes >= policy.no_threshold then
|
||||||
|
fail()
|
||||||
|
end
|
||||||
|
if #yes_votes >= policy.yes_threshold then
|
||||||
|
pass()
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif policy.consent_ratio and policy.quorum then
|
||||||
|
if quorum >= policy.quorum then
|
||||||
|
if consent_ratio >= policy.consent_ratio then
|
||||||
|
pass()
|
||||||
|
else
|
||||||
|
fail()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
policy_table_format = {
|
||||||
|
"create_child_org": {
|
||||||
|
defer_to = nil,
|
||||||
|
|
||||||
|
-- duration
|
||||||
|
duration = nil, -- evaluates end conditions when reached
|
||||||
|
|
||||||
|
-- thesholds
|
||||||
|
no_threshold = nil, -- fails if reached
|
||||||
|
yes_threshold = nil, -- succeeds if reached
|
||||||
|
|
||||||
|
--ratios
|
||||||
|
consent_ratio = nil, -- % of voters
|
||||||
|
quorum = nil, -- % of members that vote
|
||||||
|
}
|
||||||
|
"create_child_org": {
|
||||||
|
consent_threshold = 0.51,
|
||||||
|
max_duration = 89324, -- seconds until vote closes if threshold not reached, or nil for no limit
|
||||||
|
defer = nil, -- org id to defer to, or nil
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ function completion()
|
|||||||
print("completed")
|
print("completed")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- modpol.modules.join_org.initiate("paul", test_org, completion)
|
modpol.modules.join_org.initiate("paul", test_org, completion)
|
||||||
|
|
||||||
process = modpol.modules.join_org_class.create("paul", test_org)
|
-- process = modpol.modules.join_org_class.create("paul", test_org)
|
||||||
process:initiate(completion)
|
-- process:initiate(completion)
|
Loading…
x
Reference in New Issue
Block a user