forked from softlayer/sl-ember-behavior
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.js
executable file
·65 lines (51 loc) · 1.68 KB
/
route.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Ember from 'ember';
/**
* @module
* @augments ember/Mixin
*/
export default Ember.Mixin.create({
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
// Attributes
/**
* Route to direct user to when they have been denied access to a route
*
* @type {?String}
*/
unableRoute: null,
// -------------------------------------------------------------------------
// Actions
// -------------------------------------------------------------------------
// Events
// -------------------------------------------------------------------------
// Properties
/**
* The behavior service used to check if behavior is allowed
*
* @type {ember/Service}
*/
behaviorService: Ember.inject.service( 'sl-behavior' ),
// -------------------------------------------------------------------------
// Observers
// -------------------------------------------------------------------------
// Methods
/**
* Enforce permission-based access restrictions
*
* @function
* @param {ember/RSVP/Promise} transition
* @returns {undefined}
*/
beforeModel( transition ) {
Ember.get( this, '_super' )( ...arguments );
if ( this.get( 'behaviorService' ).isUnable( transition.targetName, 'route' ) ) {
const unableRoute = this.get( 'unableRoute' );
if ( Ember.isEmpty( unableRoute ) ) {
transition.abort();
} else {
this.transitionTo( unableRoute );
}
}
}
});