123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- 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
- }
- }
|