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

Rules for index actions not working as expected. #5

Closed
computeus opened this issue Mar 7, 2014 · 10 comments
Closed

Rules for index actions not working as expected. #5

computeus opened this issue Mar 7, 2014 · 10 comments
Labels

Comments

@computeus
Copy link

Hi,

I have written a rule like this,

if($user->hasRole('admin')) {
  $authority->allow('read', 'Actor', function($self, $actor){
    return $actor->id >= 3;
  });
}

On index action of ActorController, I get an error 'Trying to get property of non-object' as the error is displayed for the

return $actor->id >=3;

line as there is no $actor object on the index action. But why is the function defined in rule definition executed when I visited the index action as the README says the opposite?

@tortuetorche
Copy link
Contributor

Hi Fatih,

I'll like to ask you one question before investigate a bit more, do you want this rule to be executed on 'index' and 'show' actions or only on 'show' action ?

Cheers,
Tortue Torche

@computeus
Copy link
Author

Hi Tortue,

I think you are going to say to have different rules for show and index actions. Am I right?

I always use cancan when I develop with Rails. Cancan automatically omits the code part of the rule. So I expect that authority-controller has this feature too.

@tortuetorche
Copy link
Contributor

I think you are going to say to have different rules for show and index actions. Am I right?

Yes, you are.

@tortuetorche
Copy link
Contributor

I always use cancan when I develop with Rails. Cancan automatically omits the code part of the rule. So I expect that authority-controller will have this feature too.

I can confirm you this is an issue, thank you for reporting it 😉
The reference of this behavior is here.

And this test should not pass, but it does.

The CanCan doc for this behavior is here. So I need to port this doc.
The CanCan test for this behavior is here. So I need to port this test.

Before I fix this issue, you can use this workaround in your Authority-Controller config.php file:

if($user->hasRole('admin')) {
  $authority->allow('show', 'Actor', function($self, $actor){
    return $actor->id >= 3;
  });
}

@tortuetorche
Copy link
Contributor

@computeus To confirm that this issue is gone, can you update this package in your application ?
With the master version, add this in your composer.json file:

{
  // ...
  "require": {
     //...
     "efficiently/authority-controller": "dev-master",
  //...
}

Then update it, like this:
composer update efficiently/authority-controller

If you have still the error, reopen this issue please.

Otherwise, if it's OK, I'll tag a new version.

Have a good day,
Tortue Torche

@computeus
Copy link
Author

@tortuetorche Index action works as expected but now show action is broken.

The conditional callback of the rule is not executed with show action.

Thanks for your effords.

@tortuetorche
Copy link
Contributor

My bad, I need to check this.

@tortuetorche
Copy link
Contributor

Thanks for your effords.

@computeus You're welcome

Can you update this package and try again, please ?

@computeus
Copy link
Author

It works as expected. Thank you very much.

@tortuetorche
Copy link
Contributor

🆒

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants