1 |
commit: 2bc0f6162e76a0a2a6c6753b5c5808ddba85ccd0 |
2 |
Author: Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com> |
3 |
AuthorDate: Tue Aug 2 15:24:28 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Aug 3 08:44:33 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=2bc0f616 |
7 |
|
8 |
Make some more actions available only to council members |
9 |
|
10 |
Namely #nextitem, #previtem, #changeitem, #startvote, #endvote |
11 |
|
12 |
--- |
13 |
bot/ircmeeting/agenda.py | 22 ++++++++++++++++------ |
14 |
bot/ircmeeting/meeting.py | 10 +++++----- |
15 |
bot/tests/run_test.py | 2 +- |
16 |
bot/tests/test_scripts/council_only_actions.json | 7 +++++++ |
17 |
4 files changed, 29 insertions(+), 12 deletions(-) |
18 |
|
19 |
diff --git a/bot/ircmeeting/agenda.py b/bot/ircmeeting/agenda.py |
20 |
index 05e4a57..ffd028c 100644 |
21 |
--- a/bot/ircmeeting/agenda.py |
22 |
+++ b/bot/ircmeeting/agenda.py |
23 |
@@ -62,9 +62,11 @@ class Agenda(object): |
24 |
match.group(3), irc) |
25 |
self._agenda[self._current_item][2] = '' |
26 |
|
27 |
- def next_agenda_item(self, irc): |
28 |
+ def next_agenda_item(self, nick, irc): |
29 |
if not self.conf.manage_agenda: |
30 |
return('') |
31 |
+ if not nick in self._voters: |
32 |
+ return str.format(self.can_not_vote_msg, ", ".join(self._voters)) |
33 |
if self._vote_open: |
34 |
return self.voting_open_so_item_not_changed_msg |
35 |
else: |
36 |
@@ -72,9 +74,11 @@ class Agenda(object): |
37 |
self._swich_agenda_item_to(self._current_item + 1, irc) |
38 |
return(self.get_agenda_item()) |
39 |
|
40 |
- def prev_agenda_item(self, irc): |
41 |
+ def prev_agenda_item(self, nick, irc): |
42 |
if not self.conf.manage_agenda: |
43 |
return('') |
44 |
+ if not nick in self._voters: |
45 |
+ return str.format(self.can_not_vote_msg, ", ".join(self._voters)) |
46 |
if self._vote_open: |
47 |
return self.voting_open_so_item_not_changed_msg |
48 |
else: |
49 |
@@ -82,17 +86,21 @@ class Agenda(object): |
50 |
self._swich_agenda_item_to(self._current_item - 1, irc) |
51 |
return(self.get_agenda_item()) |
52 |
|
53 |
- def start_vote(self): |
54 |
+ def start_vote(self, nick): |
55 |
if not self.conf.manage_agenda: |
56 |
return('') |
57 |
+ if not nick in self._voters: |
58 |
+ return str.format(self.can_not_vote_msg, ", ".join(self._voters)) |
59 |
if self._vote_open: |
60 |
return self.voting_already_open_msg |
61 |
self._vote_open = True |
62 |
return str.format(self.voting_open_msg, self.options()) |
63 |
|
64 |
- def end_vote(self): |
65 |
+ def end_vote(self, nick): |
66 |
if not self.conf.manage_agenda: |
67 |
return('') |
68 |
+ if not nick in self._voters: |
69 |
+ return str.format(self.can_not_vote_msg, ", ".join(self._voters)) |
70 |
if self._vote_open: |
71 |
self._vote_open = False |
72 |
return self.voting_close_msg |
73 |
@@ -125,7 +133,7 @@ class Agenda(object): |
74 |
|
75 |
reply = str.format(self.vote_confirm_msg, opt, self._agenda[self._current_item][1][opt]) |
76 |
if users_who_voted == self._voters: |
77 |
- reply += '. ' + self.end_vote() |
78 |
+ reply += '. ' + self.end_vote(nick) |
79 |
return(reply) |
80 |
|
81 |
def _get_json(self, url): |
82 |
@@ -169,9 +177,11 @@ class Agenda(object): |
83 |
options_list.append(option_text) |
84 |
return str.format(self.added_option_msg, option_text) |
85 |
|
86 |
- def change_agenda_item(self, line): |
87 |
+ def change_agenda_item(self, nick, line): |
88 |
if not self.conf.manage_agenda: |
89 |
return('') |
90 |
+ if not nick in self._voters: |
91 |
+ return str.format(self.can_not_vote_msg, ", ".join(self._voters)) |
92 |
if self._vote_open: |
93 |
return self.voting_open_so_item_not_changed_msg |
94 |
opt = self._to_agenda_item_number(line) |
95 |
|
96 |
diff --git a/bot/ircmeeting/meeting.py b/bot/ircmeeting/meeting.py |
97 |
index c20fd6d..6440ca2 100644 |
98 |
--- a/bot/ircmeeting/meeting.py |
99 |
+++ b/bot/ircmeeting/meeting.py |
100 |
@@ -324,11 +324,11 @@ class MeetingCommands(object): |
101 |
|
102 |
def do_nextitem(self, nick, time_, line, **kwargs): |
103 |
"""Go to next agenda item""" |
104 |
- self.reply(self.config.agenda.next_agenda_item(self)) |
105 |
+ self.reply(self.config.agenda.next_agenda_item(nick, self)) |
106 |
|
107 |
def do_previtem(self, nick, time_, line, **kwargs): |
108 |
"""Go to previous agenda item""" |
109 |
- self.reply(self.config.agenda.prev_agenda_item(self)) |
110 |
+ self.reply(self.config.agenda.prev_agenda_item(nick, self)) |
111 |
|
112 |
def do_timelimit(self, nick, time_, line, **kwargs): |
113 |
""" Manage reminders: |
114 |
@@ -352,16 +352,16 @@ class MeetingCommands(object): |
115 |
|
116 |
def do_changeitem(self, nick, time_, line, **kwargs): |
117 |
"""Change agenda item. Usage: #chengeitem <item number>""" |
118 |
- self.reply(self.config.agenda.change_agenda_item(line)) |
119 |
+ self.reply(self.config.agenda.change_agenda_item(nick, line)) |
120 |
|
121 |
def do_startvote(self, nick, time_, line, **kwargs): |
122 |
"""Start vote on current item""" |
123 |
- for messageline in self.config.agenda.start_vote().split('\n'): |
124 |
+ for messageline in self.config.agenda.start_vote(nick).split('\n'): |
125 |
self.reply(messageline) |
126 |
|
127 |
def do_endvote(self, nick, time_, line, **kwargs): |
128 |
"""Close voting for current agenda item. You can resume voting later with #startvote""" |
129 |
- for messageline in self.config.agenda.end_vote().split('\n'): |
130 |
+ for messageline in self.config.agenda.end_vote(nick).split('\n'): |
131 |
self.reply(messageline) |
132 |
|
133 |
def do_vote(self, nick, time_, line, **kwargs): |
134 |
|
135 |
diff --git a/bot/tests/run_test.py b/bot/tests/run_test.py |
136 |
index a6077cb..dafcda3 100644 |
137 |
--- a/bot/tests/run_test.py |
138 |
+++ b/bot/tests/run_test.py |
139 |
@@ -326,7 +326,7 @@ class MeetBotTest(unittest.TestCase): |
140 |
def test_message_answer_tests(self): |
141 |
files = ['agenda_item_changing', 'agenda_option_listing', |
142 |
'agenda_option_adding', 'agenda_option_removing', |
143 |
- 'close_voting_after_last_vote'] |
144 |
+ 'close_voting_after_last_vote', 'council_only_actions'] |
145 |
for file in files: |
146 |
test = self.get_simple_agenda_test() |
147 |
test.check_responses_from_json_file(file) |
148 |
|
149 |
diff --git a/bot/tests/test_scripts/council_only_actions.json b/bot/tests/test_scripts/council_only_actions.json |
150 |
new file mode 100644 |
151 |
index 0000000..ce843a9 |
152 |
--- /dev/null |
153 |
+++ b/bot/tests/test_scripts/council_only_actions.json |
154 |
@@ -0,0 +1,7 @@ |
155 |
+[ |
156 |
+["20:13:50 <y> #nextitem", "You can not vote or change agenda. Only x, z can."], |
157 |
+["20:13:50 <y> #previtem", "You can not vote or change agenda. Only x, z can."], |
158 |
+["20:13:50 <y> #changeitem 1", "You can not vote or change agenda. Only x, z can."], |
159 |
+["20:13:50 <y> #startvote", "You can not vote or change agenda. Only x, z can."], |
160 |
+["20:13:50 <y> #endvote", "You can not vote or change agenda. Only x, z can."] |
161 |
+] |