minutebase / ember-can

Simple authorisation addon for Ember apps
http://ember-can.com
MIT License
269 stars 50 forks source link

Use via RouterDSL #56

Open denzo opened 7 years ago

denzo commented 7 years ago

Hi there, we found ourselves writing the following code in routes, which is great. However, as the app grew we felt like we could all benefit from a birds eye view of all the routes that require abilities.

beforeModel: function() {
    if (!this.can('write post')) {
      this.transitionTo('index');
    }
  }

We thought the best place for overlooking those would be in the Router.map.

Router.map(function() {
  this.route('posts', { abilities: ['manage team', 'view post'] }, function() {
    this.route('create', { abilities: ['create post'] });
    this.route('show', { path: ':id', resourceAbilities: ['update post'] });
  });
});

We've implemented an extension of the RouterDSL in a similar manner to the way ember-torii does with authenticatedRoute.

I was wondering if you would be interested in including this type of functionality into this addon.

blimmer commented 7 years ago

Hey @denzo and thanks for the information! I totally understand your use case for this and it's certainly an interesting solution.

My only concern is that this is modifying default Ember routing behavior. I wonder if there's a way to provide this behavior as an opt-in with another addon? I would happily link to this add-on in the README if people were interested in this kind of behavior.

What do you think?

denzo commented 7 years ago

That sounds perfectly reasonable. In fact that is how we designed our addon. ember-can is simply a dependency of ember-can-router-dsl.

Ok great, I'll ping you for some feedback when it's published.

blimmer commented 7 years ago

That's awesome - please do ping me for some feedback once you've got something public. I'd be happy to have a look.

rlivsey commented 7 years ago

👍 awesome, definitely would work well as an addon.

Would be great to take a leaf from the ember-power-* addons and have a page listing extensions like this. Eg ember-power-select addons page.