-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from fleetbase/dev-v0.2.15
v0.2.15
- Loading branch information
Showing
13 changed files
with
392 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Ability } from 'ember-can'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { inject as service } from '@ember/service'; | ||
import { singularize } from 'ember-inflector'; | ||
|
||
export default class extends Ability { | ||
@service currentUser; | ||
@tracked service; | ||
@tracked resource; | ||
@tracked ability; | ||
@tracked permissions = new Set(); | ||
|
||
constructor() { | ||
super(...arguments); | ||
this.permissions = new Set(this.currentUser.permissions.map((permission) => permission.name)); | ||
} | ||
|
||
parseProperty(str) { | ||
let [service, ability, resource] = str.split(' '); | ||
|
||
this.service = service; | ||
this.ability = ability; | ||
this.resource = singularize(resource); | ||
|
||
return 'can'; | ||
} | ||
|
||
get can() { | ||
if (this.currentUser.isAdmin) { | ||
return true; | ||
} | ||
|
||
const permission = [this.service, this.ability, this.resource].join(' '); | ||
const wilcardPermission = [this.service, '*', this.resource].join(' '); | ||
const wildcardServicePermission = [this.service, '*'].join(' '); | ||
|
||
return this.permissions.has(permission) || this.permissions.has(wilcardPermission) || this.permissions.has(wildcardServicePermission); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ const hostServices = [ | |
'fileQueue', | ||
'universe', | ||
'intl', | ||
'abilities', | ||
{ hostRouter: 'router' }, | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ const services = [ | |
'fileQueue', | ||
'universe', | ||
'intl', | ||
'abilities', | ||
]; | ||
|
||
export default services; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Service from 'ember-can/services/abilities'; | ||
|
||
export default class AbilitiesService extends Service { | ||
parse(propertyName) { | ||
return { propertyName, abilityName: 'dynamic' }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '@fleetbase/ember-core/abilities/dynamic'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '@fleetbase/ember-core/services/abilities'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.