2021-05-06 01:05:57 -04:00
|
|
|
modpol.modules = modpol.modules or {}
|
|
|
|
|
|
2021-05-06 00:36:30 -04:00
|
|
|
modpol.modules.consent = {
|
2021-05-02 23:34:05 -04:00
|
|
|
type = "consent",
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-06 00:36:30 -04:00
|
|
|
-- sets consent to its own callback
|
|
|
|
|
modpol.modules.consent.__index = modpol.modules.consent
|
|
|
|
|
|
|
|
|
|
function temp_consent_process()
|
|
|
|
|
return {
|
|
|
|
|
org_id = nil,
|
|
|
|
|
request_id = nil,
|
2021-05-06 01:05:57 -04:00
|
|
|
total_votes = 0,
|
2021-05-06 00:36:30 -04:00
|
|
|
votes_yes = {},
|
|
|
|
|
votes_no = {}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- ===============================================
|
|
|
|
|
-- function to create a new consent process to resolve a pending process
|
2021-05-06 01:05:57 -04:00
|
|
|
function modpol.modules.consent:new_process(request_id, org_id)
|
2021-05-06 00:36:30 -04:00
|
|
|
local process = temp_consent_process()
|
|
|
|
|
process.request_id = request_id
|
|
|
|
|
process.org_id = org_id
|
|
|
|
|
|
|
|
|
|
setmetatable(process, modpol.modules.consent)
|
2021-05-06 01:05:57 -04:00
|
|
|
modpol.ocutil.log('Created new process for request id #' .. request_id)
|
2021-05-06 00:36:30 -04:00
|
|
|
|
2021-05-06 01:05:57 -04:00
|
|
|
return process
|
2021-05-06 00:36:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- ======================================================
|
|
|
|
|
-- function for users to vote on a pending request
|
|
|
|
|
function modpol.modules.consent:approve(user, decision)
|
|
|
|
|
if decision then
|
|
|
|
|
table.insert(self.votes_yes, user)
|
|
|
|
|
modpol.ocutil.log('User ' .. user .. ' voted yes on request #' .. self.request_id)
|
2021-05-02 23:34:05 -04:00
|
|
|
else
|
2021-05-06 00:36:30 -04:00
|
|
|
table.insert(self.votes_no, user)
|
|
|
|
|
modpol.ocutil.log('User ' .. user .. ' voted no on request #' .. self.request_id)
|
2021-05-06 01:05:57 -04:00
|
|
|
end
|
2021-05-06 00:36:30 -04:00
|
|
|
|
|
|
|
|
self.total_votes = self.total_votes + 1
|
|
|
|
|
|
2021-05-02 23:34:05 -04:00
|
|
|
end
|
|
|
|
|
|
2021-05-06 00:36:30 -04:00
|
|
|
-- ===================================================
|
|
|
|
|
-- determines whether process has finished and resolves request if it has (unfinished)
|
2021-05-06 01:05:57 -04:00
|
|
|
-- function modpol.modules.consent.call_vote_check(process)
|
|
|
|
|
-- if votes_yes > to_pass then
|
|
|
|
|
-- call_success()
|
|
|
|
|
-- elseif votes_no > to_pass then
|
|
|
|
|
-- call_failure()
|
|
|
|
|
-- end
|
|
|
|
|
-- end
|
2021-05-06 00:36:30 -04:00
|
|
|
|