Do not allow revote in a quiz.

GitOrigin-RevId: c6865a295b154fee3ba09d96691a7bc86ba4214e
This commit is contained in:
levlam 2020-04-29 16:35:53 +03:00
parent 2e2a4b4570
commit 1f58155cf1
1 changed files with 6 additions and 0 deletions

View File

@ -691,6 +691,9 @@ void PollManager::set_poll_answer(PollId poll_id, FullMessageId full_message_id,
if (poll->is_quiz && option_ids.empty()) {
return promise.set_error(Status::Error(400, "Can't retract vote in a quiz"));
}
if (poll->is_quiz && pending_answers_.count(poll_id) != 0) {
return promise.set_error(Status::Error(400, "Can't revote in a quiz"));
}
std::unordered_map<size_t, int> affected_option_ids;
vector<string> options;
@ -705,6 +708,9 @@ void PollManager::set_poll_answer(PollId poll_id, FullMessageId full_message_id,
}
for (size_t option_index = 0; option_index < poll->options.size(); option_index++) {
if (poll->options[option_index].is_chosen) {
if (poll->is_quiz) {
return promise.set_error(Status::Error(400, "Can't revote in a quiz"));
}
affected_option_ids[option_index]++;
}
}