Skip to content

Commit 090a027

Browse files
committed
Added voting
1 parent 04e4606 commit 090a027

31 files changed

Lines changed: 3121 additions & 68 deletions

quick-start-simple/quick-start.json

Lines changed: 236 additions & 65 deletions
Large diffs are not rendered by default.

quick-start-simple/quick-start/config.json

Lines changed: 132 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
{
5454
"Conditions": "ContractConditions(\"MainCondition\")",
5555
"Name": "ProfileEditAvatar"
56-
},
56+
},
5757
{
5858
"Conditions": "ContractConditions(\"MainCondition\")",
5959
"Name": "Roles_Unassign"
@@ -81,6 +81,66 @@
8181
{
8282
"Conditions": "ContractConditions(\"MainCondition\")",
8383
"Name": "RolesRequestDecision"
84+
},
85+
{
86+
"Conditions": "ContractConditions(\"MainCondition\")",
87+
"Name": "voting_CheckDecision"
88+
},
89+
{
90+
"Conditions": "ContractConditions(\"MainCondition\")",
91+
"Name": "voting_UpdateDataForGraphs"
92+
},
93+
{
94+
"Conditions": "ContractConditions(\"MainCondition\")",
95+
"Name": "voting_AcceptCandidates"
96+
},
97+
{
98+
"Conditions": "ContractConditions(\"MainCondition\")",
99+
"Name": "voting_Invite"
100+
},
101+
{
102+
"Conditions": "ContractConditions(\"MainCondition\")",
103+
"Name": "voting_Delete"
104+
},
105+
{
106+
"Conditions": "ContractConditions(\"MainCondition\")",
107+
"Name": "voting_CreateNew"
108+
},
109+
{
110+
"Conditions": "ContractConditions(\"MainCondition\")",
111+
"Name": "voting_AcceptDecision"
112+
},
113+
{
114+
"Conditions": "ContractConditions(\"MainCondition\")",
115+
"Name": "voting_SendNotifics"
116+
},
117+
{
118+
"Conditions": "ContractConditions(\"MainCondition\")",
119+
"Name": "voting_SubjectCandidates"
120+
},
121+
{
122+
"Conditions": "ContractConditions(\"MainCondition\")",
123+
"Name": "voting_SubjectCheckFulldata"
124+
},
125+
{
126+
"Conditions": "ContractConditions(\"MainCondition\")",
127+
"Name": "voting_SubjectContract"
128+
},
129+
{
130+
"Conditions": "ContractConditions(\"MainCondition\")",
131+
"Name": "voting_SubjectDocument"
132+
},
133+
{
134+
"Conditions": "ContractConditions(\"MainCondition\")",
135+
"Name": "voting_SubjectFormal"
136+
},
137+
{
138+
"Conditions": "ContractConditions(\"MainCondition\")",
139+
"Name": "voting_SubjectSettings"
140+
},
141+
{
142+
"Conditions": "ContractConditions(\"MainCondition\")",
143+
"Name": "voting_RejectDecision"
84144
},
85145
{
86146
"Conditions": "ContractConditions(\"MainCondition\")",
@@ -197,6 +257,51 @@
197257
"Name": "roles_view",
198258
"Menu": "default_menu"
199259
},
260+
{
261+
"Conditions": "ContractAccess(\"@1EditPage\")",
262+
"Name": "voting_create",
263+
"Menu": "default_menu"
264+
},
265+
{
266+
"Conditions": "ContractAccess(\"@1EditPage\")",
267+
"Name": "voting_decision_candidates",
268+
"Menu": "default_menu"
269+
},
270+
{
271+
"Conditions": "ContractAccess(\"@1EditPage\")",
272+
"Name": "voting_decision_contract",
273+
"Menu": "default_menu"
274+
},
275+
{
276+
"Conditions": "ContractAccess(\"@1EditPage\")",
277+
"Name": "voting_decision_document",
278+
"Menu": "default_menu"
279+
},
280+
{
281+
"Conditions": "ContractAccess(\"@1EditPage\")",
282+
"Name": "voting_decision_election",
283+
"Menu": "default_menu"
284+
},
285+
{
286+
"Conditions": "ContractAccess(\"@1EditPage\")",
287+
"Name": "voting_decision_formal",
288+
"Menu": "default_menu"
289+
},
290+
{
291+
"Conditions": "ContractAccess(\"@1EditPage\")",
292+
"Name": "voting_invite",
293+
"Menu": "default_menu"
294+
},
295+
{
296+
"Conditions": "ContractAccess(\"@1EditPage\")",
297+
"Name": "voting_list",
298+
"Menu": "default_menu"
299+
},
300+
{
301+
"Conditions": "ContractAccess(\"@1EditPage\")",
302+
"Name": "voting_view",
303+
"Menu": "default_menu"
304+
},
200305
{
201306
"Conditions": "ContractAccess(\"@1EditPage\")",
202307
"Name": "tokens_transfer",
@@ -223,7 +328,20 @@
223328
"Menu": "default_menu"
224329
}
225330
],
226-
"tables": null,
331+
"tables": [
332+
{
333+
"Name": "votings",
334+
"Permissions": "{\"insert\": \"true\", \"update\": \"true\", \"new_column\": \"true\"}"
335+
},
336+
{
337+
"Name": "votings_participants",
338+
"Permissions": "{\"insert\": \"ContractAccess(\\\"voting_Invite\\\")\", \"update\": \"ContractAccess(\\\"voting_RejectDecision\\\",\\\"voting_AcceptDecision\\\",\\\"voting_AcceptCandidates\\\")\", \"new_column\": \"true\"}"
339+
},
340+
{
341+
"Name": "votings_subject",
342+
"Permissions": "{\"insert\": \"true\", \"update\": \"true\", \"new_column\": \"true\"}"
343+
}
344+
],
227345
"parameters": [
228346
{
229347
"Conditions": "ContractConditions(\"MainCondition\")",
@@ -248,6 +366,18 @@
248366
{
249367
"Conditions": "ContractConditions(\"MainCondition\")",
250368
"Name": "roles_types_selection"
369+
},
370+
{
371+
"Conditions": "ContractConditions(\"MainCondition\")",
372+
"Name": "type_voting"
373+
},
374+
{
375+
"Conditions": "ContractConditions(\"MainCondition\")",
376+
"Name": "type_voting_decisions"
377+
},
378+
{
379+
"Conditions": "ContractConditions(\"MainCondition\")",
380+
"Name": "type_voting_participants"
251381
}
252382
],
253383
"name": "Basic application"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
contract voting_AcceptCandidates {
2+
data {
3+
votingID int
4+
candidateID int
5+
}
6+
7+
conditions {
8+
$voting_map = DBFind("votings").Columns("id,flags").Where("id=?", $votingID).Row()
9+
if !$voting_map {
10+
warning "Voting is not found"
11+
}
12+
13+
$subject_map = DBFind("votings_subject").Where("voting_id=$ and subject->member_id=$", $votingID, $candidateID).Row()
14+
if !$subject_map {
15+
warning "Subject of voting is not found"
16+
}
17+
18+
$participant_id = DBFind("votings_participants").Where("voting_id=$ and member->member_id=$", $votingID, $key_id).One("id")
19+
if !$participant_id {
20+
warning "You are not a participant in this voting"
21+
}
22+
}
23+
24+
action {
25+
var flags map
26+
flags = JSONToMap($voting_map["flags"])
27+
// if notifications have been sent, then close it
28+
if flags["notifics"] == 1 {
29+
30+
$notific_id = DBFind("notifications").Where("recipient->member_id=$ and page_name=$ and page_params->voting_id=$ and closed=$", $key_id, "voting_view", $votingID, 0).One("id")
31+
32+
if $notific_id {
33+
notifications_Close("notific_id", Int($notific_id))
34+
}
35+
}
36+
37+
// check the decision
38+
if flags["decision"] == 1 {
39+
warning "Decision was taken. Voting is now not possible"
40+
}
41+
42+
// check start-end of voting time
43+
var voting_start, voting_end string
44+
voting_start = DBFind("votings").Where("id=$ and date_started < $", $votingID, BlockTime()).One("id")
45+
voting_end = DBFind("votings").Where("id=$ and date_ended > $", $votingID, BlockTime()).One("id")
46+
if !voting_start {
47+
warning "Voting has not yet begun. Try again later, please"
48+
}
49+
if !voting_end {
50+
warning "Voting has expired. Voting is now not possible"
51+
}
52+
53+
// write the result of the voting
54+
DBUpdate("votings_participants", Int($participant_id), "timestamp decision_date,decision", $block_time, $candidateID)
55+
56+
// increment count of accept
57+
DBUpdate("votings_subject", Int($subject_map["id"]), "+number_accept", 1)
58+
59+
voting_UpdateDataForGraphs("votingID", $votingID)
60+
}
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
contract voting_AcceptDecision {
2+
data {
3+
votingID int
4+
}
5+
6+
conditions {
7+
$voting = DBFind("votings").Columns("id,flags->decision,flags->notifics,voting->type_participants,voting->role_id").Where("id=?", $votingID).Row()
8+
if !$voting {
9+
warning "Voting is not found"
10+
}
11+
if $voting["voting.type_participants"] == 3{
12+
if $voting["voting.role_id"] != $role_id{
13+
warning "Incorrect role for voting"
14+
}
15+
}
16+
17+
$subject = DBFind("votings_subject").Where("voting_id=$", $votingID).Row()
18+
if !$subject {
19+
warning "Subject of voting is not found"
20+
}
21+
22+
$participant_id = DBFind("votings_participants").Where("voting_id=$ and member->member_id=$", $votingID, $key_id).One("id")
23+
if !$participant_id {
24+
warning "You are not a participant in this voting"
25+
}
26+
}
27+
28+
action {
29+
// if notifications have been sent, then close it
30+
if $voting["flags.notifics"] == 1 {
31+
var noteId string
32+
noteId = DBFind("notifications").Where("recipient->member_id=$ and page_name=$ and page_params->voting_id=$ and closed=$", $key_id, "voting_view", $votingID, 0).One("id")
33+
if noteId {
34+
notifications_Close("notific_id", Int(noteId))
35+
}
36+
}
37+
38+
// check the decision
39+
if $voting["flags.decision"] == 1 {
40+
warning "Decision was taken. Voting is now not possible"
41+
}
42+
43+
// check start-end of voting time
44+
var voting_start voting_end string
45+
voting_start = DBFind("votings").Where("id=$ and date_started < $", $votingID, BlockTime()).One("id")
46+
voting_end = DBFind("votings").Where("id=$ and date_ended > $", $votingID, BlockTime()).One("id")
47+
if !voting_start {
48+
warning "Voting has not yet begun. Try again later, please"
49+
}
50+
if !voting_end {
51+
warning "Voting has expired. Voting is now not possible"
52+
}
53+
54+
DBUpdate("votings_participants", Int($participant_id), "timestamp decision_date,decision", $block_time, 1)
55+
56+
// increment count of accept
57+
DBUpdate("votings_subject", Int($subject["id"]), "+number_accept", 1)
58+
59+
voting_UpdateDataForGraphs("votingID", $votingID)
60+
}
61+
}

0 commit comments

Comments
 (0)