Closed (fixed)
Project:
Scheduler
Version:
8.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
16 Jan 2016 at 15:50 UTC
Updated:
18 Mar 2016 at 09:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
joekersWe seemed to have removed the permission check when we moved the code from scheduler.edit.inc to scheduler.module.
I added the permission check back in which prevents access to the scheduler fields if the user doesn't not have permission. Because the fields are always defined on the node, I also had to bypass the field validation if the scheduler fields are required, not sure if there is a better way to do this?
Comment #3
pfrenssenI agree, digging so deep in the widget array doesn't feel right.
Could you check if it works to deny access on the publish/unpublish fields instead of disabling the #required state?
My guess is that the validators are also disabled when the entire field is disabled, but I'm not sure.
Since this is security related, it would be great to have a test for this. Raising priority to major too.
Comment #4
joekersDenying access to the fields was the first thing I tried but it didn't work so the only other thing I could think of was to set #required to FALSE.
I'll have a look to see how other modules achieve this.
I don't have any experience writing tests but I'm happy to give it a go :)
Comment #5
jonathan1055 commentedI have added tests to cover this bug
http://cgit.drupalcode.org/scheduler/commit/?id=00d1135
[edit] ooops, sorry Joe, I did not see your comment about writing tests. I put this together and commited as I knew we needed tests. before I read the above thread in detail.
Comment #7
joekersCool, I didn't start writing tests for it but I'll take a look at your code to see how it's done.
Comment #10
jonathan1055 commentedOddly the commit in #9 to fix my mistake of leaving _ in the test names has not shown up in the actual 8.x code repository. Maybe I did something wrong with the merge, which show no differences, yet the two branches do have differences, the testing branch has the correct test names. Make the change again, to get back to alignment.
http://cgit.drupalcode.org/scheduler/commit/?id=e2bc5ef
Comment #11
joekersRe-rolled the patch because of #2538002: Cannot save Scheduler permission with ( ) in machine name key
Comment #12
jonathan1055 commentedThanks. Setting the status to 'needs review' to trigger the tests to be run.
Comment #14
jonathan1055 commentedAs before, we get an extra test pass.
Did you have any luck in answering pfrennsen's query about how to disable the validators? It does seem wrong to have to set #required to FALSE and in doing so have to hardcode the deep set of array key names.
It also surprises me that with all the customisable/configurable flexibility we now have in Drupal8 that when we don't want a user to have access to a field we have to leave it in the form but just hide it and make sure it does not throw a validation error. There must be some way to say "do not let the user anywhere near this field, just as if it was not there in the first place"
Comment #15
joekersI did take a brief look but I couldn't see anything in core. I know that if you hide a required field from the form display that it will not cause any validation errors, but I think that's only because the field is never added to the form in the first place - so that doesn't help.
I agree there must be a cleaner way to achieve this. Maybe there's a preprocess form or something so we can decide what fields we want to appear on the form? Hopefully Pieter knows a way, or I'll try asking in IRC.
Comment #16
jonathan1055 commentedI think we should commit this fix, as it does solve a major problem. Joe, if you can add a @todo referencing this issue, and stating that the solution is not ideal but better than nothing, I will commit it. If we find a better solution later we can change it again.
Comment #17
joekersCool - updated patch.
Comment #20
jonathan1055 commentedThat's another test now passing.
I just made a minor alteration in the comment. Using the text @see is apparently better as this string is parsed by the automated documentation process.
Thanks Joe, good to get this committed.