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

Merge alias actions when merging abilities #538

Merged
merged 3 commits into from
Jan 26, 2019
Merged

Merge alias actions when merging abilities #538

merged 3 commits into from
Jan 26, 2019

Conversation

Jcambass
Copy link
Contributor

Closes #468
Closes #280

This changes the behaviour of Ability#merge to also include defined
alias_actions.

If a collision between the defined aliases occurs the actions on self
will be overwritten with those on the passed object. For an example see this added spec.

The inline documentation has been updated in order to reflect those
changes.

Closes #468
Closes #280

This changes the behaviour of `Ability#merge` to also include defined
`alias_actions`.

If a collision between the defined aliases occurs the actions on +self+
will be overwritten with those on the passed object.

The inline documentation has been updated in order to reflect those
changes.
Copy link
Member

@coorasse coorasse left a comment

Choose a reason for hiding this comment

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

I personally would have expected the alias to "sum up" and be merged. see my comment. I nevertheless approve the PR, since it's well written, tested, and it does exactly what is meant for. I wait for a feedback to hear your thoughts about this.

#
# read_ability = ReadAbility.new
# read_ability.merge(ShowAbility)
# read_ability.aliased_actions #=> [:see => [:show]]
Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I'd have expected them to be see: [:show, :index] since they are merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@coorasse You're right merge would kinda indicate that, but would that make sense?

If we merge two abilities we expect to gain the rules from the ability which was passed. But it wouldn't really make sense to combine the actions defined for an alias since it could change the "meaning" of that alias.

Even tho it seems like the more intuitive approach, I think it would lead to some surprises. I choose this approach because it's "safer" and doesn't change the rules defined for an alias.

@coorasse coorasse merged commit 4eecb08 into CanCanCommunity:develop Jan 26, 2019
@Jcambass Jcambass deleted the merge_alias_actions_when_merging_abilities branch April 8, 2019 09:20
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