Problem/Motivation
Currently you can only set a poll as active or inactive. However, inactive is not the same as unpublished since in many cases, you still want to be able to view the poll results.
Steps to reproduce
Create a poll and watch how the active flag behaves.
Proposed resolution
- Add an extra state and update the schema/entity. This should be the one from core entity functionality
- Update all access handler logic.
- Add & update tests
Remaining tasks
MR with the points above.
User interface changes
An extra checkbox will be added.
API changes
N/A?
Data model changes
Extra definition in the schema
Original issue summary
It appears that when a poll is closed (i.e. 'active' is unchecked), it is still visible to a plebeian (one that doesn't have an administer poll permission).
I have modified the access handler for Polls to check if the Poll is open and only grant access based on that or the fallback - if they have the administer polls permission.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | Screenshot 2024-10-10 at 08.28.14.png | 166.86 KB | bramdriesen |
Issue fork poll-3045110
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
johnsiciliComment #3
rasikap commentedThis functionality works for me in my project with Drupal version 8.6.16 without applying this patch.
Thanks,
Rasika P
Comment #4
naheemsays commentedThere will be many times where you want the results of a closed poll to be visible. This probably needs to be an option on a per poll basis and not based on permissions.
Comment #5
nevergoneClosed poll: visible, but not voteable.
Comment #6
naheemsays commentedThe issue of some drupal sites wanting to show the final result is a tricky one that isnt considered in the patch.
Where are you seeing the poll that you dont like?
If it is in a listing, maybe there should be (or is?) a iews option to not list closed polls?
If it is for the poll itself etc, then the options need to consider a lot more - you will often want the result of a closed poll to be visible.
Comment #7
ivnish@Berdir, @BramDriesen, what do you think about it?
Comment #8
bramdriesenI think it makes more sense to allow a poll to be unpublished similar to a regular entity/node. A closed poll should still be accessible to show the results in many/most cases.
Comment #9
bramdriesenComment #10
bramdriesenComment #11
samitk commentedHi @BramDriesen,
The
"published" = "status"(entity_keys) is already exists as Active(A flag indicating whether the poll is active.) Field,this Active filed is used to open or close any poll, I guess we have to introduce new filed for open or close any poll, and will use this field to publish or unpublished any poll.
Please confirm.
Thanks
Samit K.
Comment #12
bramdriesenComment #14
bramdriesenSome extra things that came to mind:
- Needs update hook to update all existing polls to copy over the value from what is now published to the new Active field. Probably best to also set "published" to TRUE as default for now. (needs to be a batch!)
- Update view
- Update list builder
Comment #15
bramdriesenCan already be tested. Only needs to add some tests for this.
Comment #16
ivnishI tested it manually:
1) I created a new poll with anonymous votes. Poll is active and published.
2) Anonymous user can view poll and can vote
3) I set active=false, Anonymous user can view poll and can't vote
4) I set active=true and published=false
5) Anonymous user can't view poll
It works as expected.
But, after I set poll published=false, poll hide from Poll List Builder.
Proposed solution:
1) Allow to view unpublished polls into List Builder
2) We can also add new column "status" as Node List Builder with publishing status
Comment #17
bramdriesenThe list builder I must admit I did not test yet! Thanks for the manual review :-) really helps
Comment #18
ivnish@Bram, do you have time to continue this issue? It looks like 90% ready :)
Comment #19
bramdriesenPoll list viewer seems to work fine.
Did notice in the listbuilder class that the votes section is not implemented. Will create a follow up issue for that.
Comment #20
ivnishLooks like MR needs reroll 🤔
Comment #21
bramdriesenAll green now :-)
Comment #22
ivnishI will test it now :)
Comment #23
bramdriesenRe #19: #3479810: PollListBuilder is missing vote information
Comment #24
ivnishExisting sites don't have new "status" field in /admin/content/poll, because they have "old" poll admin view. Should we add in hook_update re-import views.view.poll_admin.yml config form poll config/install directory?
Comment #25
bramdriesenThat has crossed my mind as well. Not sure how to deal with that, as sites might have overwritten the view.
Comment #26
ivnishOr we can write about it in release notes
Comment #27
bramdriesenI think a change records makes sense. Will draft it here: https://www.drupal.org/node/3479831
Comment #28
bramdriesenDone 👆
Comment #29
ivnishComment #31
bramdriesenAlso added the view related info in the CR.
Thanks for your reviews! @ivnish. Thanks to the rest that participated!