-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Giving the administrator the option to hide polls #4819
Giving the administrator the option to hide polls #4819
Conversation
Hi, @arthur1041 😄. Thanks for your contribution! 🙏 If I understand it correctly, the original issue was about adding a "preview" feature to polls, similar to what we've got in budgets, so administrators could access non-published polls in the public page. Is that correct? As far as I can see, with the changes in this pull request, administrators still can't access non-published polls in the public page 🤔. They can of course access them in the admin area, but that's something they can already do without this pull request by setting the publication date of the poll in the future. Is there something I'm missing? Please let me know if that's the case! Another thing to consider is that I think it shouldn't be possible to "unpublish" a poll once it's received votes, just like it isn't possible to delete a poll once it's received votes. Do you think this makes sense? |
Yes. I read the issue again and I saw the admistrator needs to see the poll in the public page even if it's not published. I'll work on a solution for it. Yeah, it also makes sense not to be able to unpublish a poll once it received votes, I'll add this restriction. |
@javierm Just pushed two new commits containing the modifications that you mentioned in your last comment. |
@arthur1041 Thanks once again! 🙏 We're currently preparing version 1.5; we'll review this pull request after that. Sorry for the delay! 🙏 And thank you for your patience 😌. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arthur1041 Sorry for the late review!
I'm also very sorry because apparently there was another team working on a similar issue and due to miscommunication we didn't know about it.
So I've left a few comments regarding this pull request but, at the same time, I don't know whether this pull request could be merged if you apply the changes 🤦.
I apologize for this whole situation 🙏.
@polls = Kaminari.paginate_array( | ||
@polls.created_by_admin.not_budget.send(@current_filter).includes(:geozones).sort_for_list(current_user) | ||
administrator ? @polls.created_by_admin.not_budget.send(@current_filter).includes(:geozones).sort_for_list(current_user) : | ||
@polls.created_by_admin.not_budget.published.send(@current_filter).includes(:geozones).sort_for_list(current_user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be tricky because the default vaule of the published
column in the polls
table is false
. That means existing polls would no longer appear if we add this filter 🤔.
For now, feel free to ignore this scenario 👌, since there's another pull request dealing with poll restrictions (#4859) which has been developed independently, and we need to check it before deciding how to handle with this case.
administrator = current_user ? current_user.administrator? : false | ||
|
||
@polls = Kaminari.paginate_array( | ||
@polls.created_by_admin.not_budget.send(@current_filter).includes(:geozones).sort_for_list(current_user) | ||
administrator ? @polls.created_by_admin.not_budget.send(@current_filter).includes(:geozones).sort_for_list(current_user) : | ||
@polls.created_by_admin.not_budget.published.send(@current_filter).includes(:geozones).sort_for_list(current_user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could keep this line the way it was and use abilities instead 🤔. So we keep the same code here:
@polls.created_by_admin.not_budget.send(@current_filter).includes(:geozones).sort_for_list(current_user)
And in the app/models/abilities/everyone.rb
file, we change:
- can :read, Poll
+ can :read, Poll, published: true
That way this authorization check will also be applied to the show
action.
What do you think?
@@ -17,6 +17,10 @@ | |||
<div class="icon-poll-answer already-answer" title="<%= t("polls.index.already_answer") %>"> | |||
<span class="show-for-sr"><%= t("polls.index.already_answer") %></span> | |||
</div> | |||
<% elsif current_user.administrator? && !poll.published %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need the first condition since unpublished polls will only be loaded for administrators 🤔.
<% elsif current_user.administrator? && !poll.published %> | |
<% elsif !poll.published %> |
@@ -3,7 +3,7 @@ | |||
describe "Polls" do | |||
context "Public index" do | |||
scenario "Budget polls should not be listed" do | |||
poll = create(:poll) | |||
poll = create(:poll, :published) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to simplify the tests, how about changing the polls
factory so published
is set to true
by default, like we do for budgets, proposals and legislation processes? Then we can remove many of these changes and change only the tests where we're dealing with draft polls.
<div class="row"> | ||
<div class="clear"> | ||
<div class="margin-top small-6 medium-6 column"> | ||
<%= f.check_box :published, :disabled => polls_has_votes(@poll) %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<%= f.check_box :published, :disabled => polls_has_votes(@poll) %> | |
<%= f.check_box :published, disabled: @poll.voters.any? %> |
This way we can remove the polls_has_votes
helper method.
@@ -143,6 +144,12 @@ def date_range | |||
end | |||
end | |||
|
|||
def published_checkbox | |||
if !published && polls_has_votes?(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !published && polls_has_votes?(self) | |
if !published && voters.any? |
This way we can remove the polls_has_votes?
method.
@@ -22,7 +22,7 @@ | |||
</div> | |||
|
|||
<div class="small-12 column"> | |||
<%= translations_form.text_area :summary, rows: 4 %> | |||
<%= translations_form.text_field :summary, rows: 4 %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change related to this pull request? 🤔
Closing as incompatible because the changes in #4904 aren't compatible with this approach. @arthur1041 Sorry about that! |
References
Objectives
Visual Changes
Notes