Skip to content
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

FIX allow extensions to modify canXYZ methods #30

Merged

Conversation

robbieaverill
Copy link
Contributor

@wilr
Copy link
Member

wilr commented May 12, 2016

This fix will call the extensions but it won't actually modify the response to it right? Think the pattern for this should be something like

function canX(...) {
$extended = $this->extendedCan(FUNCTION, $member);
if($extended !== null) return $extended;

.. $existing code

@robbieaverill
Copy link
Contributor Author

@wilr yeah, it will call the parent method but won't use its results. It's DataObject::canDelete() for example that provides the extension hook.

@robbieaverill
Copy link
Contributor Author

@wilr no worries, let's go that way!

@robbieaverill robbieaverill force-pushed the bugfix/29-permission-extensions branch from 10f6974 to 9323d3b Compare May 12, 2016 23:20
@robbieaverill
Copy link
Contributor Author

FYI I've gone with PSR-2 since it's coming - if you want me to use standard SS style I'm happy to change it

@wilr
Copy link
Member

wilr commented May 12, 2016

Nah PSR1/2 FTW

@robbieaverill
Copy link
Contributor Author

Cool. Hold this PR - I'm not sure it's working correctly with canView().

@robbieaverill
Copy link
Contributor Author

robbieaverill commented May 13, 2016

Looks like versioned-data-objects is returning 0 somewhere in the canView permissions check and preventing them from being visible. Looking into it.

Even with "Access to all CMS sections" enabled, Versioned::canView is still returning 0 for a non-admin role.

@robbieaverill
Copy link
Contributor Author

robbieaverill commented May 13, 2016

@wilr - having had a quick read of the Versioned docs about permissions it sounds sensible to me that this module should implement its own permission check for canView which it does already, so perhaps we shouldn't try to allow the extension hook for it?

I'm confused about two things here:

  1. Is silverstripe-versioned-dataobjects required over the framework's included Versioned functionality which can apply to DataObjects as well?
  2. Is there a way to still provide the extension hooks from BaseElement, while not letting the permission errors from Versioned prevent the actions? I'm by no means a master in this, but would moving the canXYZ methods into a BaseElementExtension which would extend VersionedDataObject be a better option? This way the result you return from the canXYZ method would be isolated to that extension, and the base permission check would treat it as an extension's two cents rather than the base DataObjects two cents...? It appears to be working for me. I'm gonna push that change up and let you decide if you like it :)

@robbieaverill
Copy link
Contributor Author

Hey @wilr - what do you think about this change?

@robbieaverill robbieaverill force-pushed the bugfix/29-permission-extensions branch from 3354d17 to 1098ad8 Compare June 8, 2016 04:26
@robbieaverill
Copy link
Contributor Author

@wilr - rebased onto latest master changes

@wilr wilr merged commit 3f0348c into silverstripe:master Jun 8, 2016
@wilr
Copy link
Member

wilr commented Jun 8, 2016

Yeah I think that is possibly a better way to go and allows users to sub in anything else for permissions.

@robbieaverill robbieaverill deleted the bugfix/29-permission-extensions branch July 13, 2017 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants