-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelection_status.rs
More file actions
58 lines (55 loc) · 1.75 KB
/
election_status.rs
File metadata and controls
58 lines (55 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// State Transition Diagram:
//
// [Draft] -> [Registration] -> [Voting] ----------> [Finished]
// V V ^ V ^
// <Delete> \-> [InitFailed] -/ \->[CollectionFailed] -/
//
// Note: Elections can ONLY be edited or deleted in the [Draft] state.
// Once registration has begun, the election must be carried to the end.
//
// Note: Public elections are not visible until the [Registration] state.
sql_enum!(
pub ElectionStatus {
Draft = 0,
Registration,
InitFailed,
Voting,
CollectionFailed,
Finished
}
);
impl ElectionStatus {
pub fn get_name(&self) -> &'static str {
match self {
ElectionStatus::Draft => "Draft",
ElectionStatus::Registration => "Registration",
ElectionStatus::InitFailed => "Initialization Failed",
ElectionStatus::Voting => "Voting",
ElectionStatus::CollectionFailed => "Collection Failed",
ElectionStatus::Finished => "Finished",
}
}
/// Test if the election parameters have been initialized
pub fn is_initialized(&self) -> bool {
match self {
ElectionStatus::Draft => false,
ElectionStatus::Registration => false,
ElectionStatus::InitFailed => false,
ElectionStatus::Voting => true,
ElectionStatus::CollectionFailed => true,
ElectionStatus::Finished => true,
}
}
/// Test if we are allowed to view the results
/// (Even if the election isn't 100% finished yet)
pub fn can_view_results(&self) -> bool {
match self {
ElectionStatus::Draft => false,
ElectionStatus::Registration => false,
ElectionStatus::InitFailed => false,
ElectionStatus::Voting => true,
ElectionStatus::CollectionFailed => true,
ElectionStatus::Finished => true,
}
}
}