ember-can icon indicating copy to clipboard operation
ember-can copied to clipboard

Use via RouterDSL

Open denzo opened this issue 7 years ago • 4 comments

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.

denzo avatar Apr 07 '17 01:04 denzo

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?

blimmer avatar Apr 15 '17 19:04 blimmer

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.

denzo avatar Apr 15 '17 23:04 denzo

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

blimmer avatar Apr 15 '17 23:04 blimmer

👍 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.

rlivsey avatar Apr 16 '17 14:04 rlivsey