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

RBAC: decoupled rules from assignments and items, implemented php manager #2974

Merged
merged 7 commits into from
Apr 4, 2014

Conversation

samdark
Copy link
Member

@samdark samdark commented Apr 4, 2014

See #499

@samdark
Copy link
Member Author

samdark commented Apr 4, 2014

Ready for review/merge.

@samdark samdark added this to the 2.0 Beta milestone Apr 4, 2014
*
* @param Rule $rule the rule that has been changed.
*/
public function saveRule(Rule $rule)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps createRule and updateRule would be better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently Rule can be pretty freeform class so it's hard to wrap its creation into method signature. Also it doesn't look well when implemented. I've dropped it during first draft.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think perhaps createRule() should be separated from saveRule(), similar to that for item and assignment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea about the signature?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the following? Note that I'm using the name insert and update so that they are similar to the corresponding methods in AR (this means the methods for saving items and assignments should be changed accordingly for consistency):

insertRule(Rule $rule)
updateRule($name, Rule $rule)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is a good idea to rename createRole and others to insertRole since it's actually creating new object instance from parameters passed to method.

As for Rule, we already have the instance so there's no need to create anything.

try {
$this->db->createCommand()->insert($this->ruleTable, ['name' => $rule->name, 'data' => $data])->execute();
} catch (\yii\db\Exception $e) {
$this->db->createCommand()->update($this->ruleTable, ['data' => $data], ['name' => $rule->name])->execute();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the name of the rule is changed, this implementation will create a new rule and leave the old one there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is why i was mentioning createRule and updateRule as well.
updateRule takes first param $ruleName and second param Rule $newRule. If names are different, the means also a name swap, we remove the previous rule, and call createRule($newRule)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous rule should not be removed. It should be updated (to trigger on update cascade).

@qiangxue
Copy link
Member

qiangxue commented Apr 4, 2014

I have finished reviewing. It looks great to me overall!

@pmoust
Copy link
Contributor

pmoust commented Apr 4, 2014

👍

@qiangxue
Copy link
Member

qiangxue commented Apr 4, 2014

Looks fine to me. You may merge it if no more changes will be done. good job!

samdark added a commit that referenced this pull request Apr 4, 2014
RBAC: decoupled rules from assignments and items, implemented php manager
@samdark samdark merged commit 69786b0 into master Apr 4, 2014
@samdark samdark deleted the decouple-bizrules-from-auth-items branch April 4, 2014 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants