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

Improved authorize Twig extension #948

Merged

Conversation

Sommerregen
Copy link
Contributor

This PR addresses https://getgrav.org/forum#!/general:hiding-certain-tabs-from-no and enhances the authorize Twig extension method with full backward-compatibility. Thus, it can be used as usual with

authorize(['admin.super', 'admin.pages']);
authorize('admin.super');

or with the new changes with

authorize([
  'admin' => [
    'super' => true
  ],
  'site' => [
    'user' => false
  ]
]);

which makes it possible to set access rights for tabs via blueprints as

assets:
  type: tab
  title: Assets
  security:
    admin:
      super: true
    site:
      user: false
  fields:
     ...

@flaviocopes flaviocopes merged commit 496be79 into getgrav:develop Jul 20, 2016
@flaviocopes
Copy link
Contributor

👍 thanks!

@flaviocopes
Copy link
Contributor

Just to clear things,

    admin:
      super: true
    site:
      user: false

means a tab is visible to users with admin.super who do not have site.user set to true? Or what is the logic there?

@Sommerregen
Copy link
Contributor Author

@flaviocopes Good point! I tried to adapt the logic of the Login plugin. Atm it means what you said. Only users with admin.super are allowed to access the tab. Users with site.user not. I see this is redundant, because all other roles do not have access either... and it is not the same as the login plugin provides :-/ ...

Maybe it is better to replace L749-756 with

foreach ($action as $key => $rules) {
  $prefix = is_int($key) ? '' : $key . '.';
  $rules = $prefix ? (array) $rules : [$rules => true];
  foreach ($rules as $rule => $value) {
    if ($this->grav['user']->authorize($prefix . $rule) === $value) {
      return true;
    }
}

like the logic from the login plugin.

@flaviocopes
Copy link
Contributor

My question is, in what case setting a value as false is a good use case? I don't see one at hand, but maybe you do, as you wrote the PR :)

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.

3 participants