32 lines
1.2 KiB
CoffeeScript
32 lines
1.2 KiB
CoffeeScript
import Ember from 'ember'
|
|
# Example usage
|
|
# <ember-app>/app/helpers/can.coffee
|
|
#
|
|
# import DunlopCan from 'ember-cli-dunlop/helpers/dunlop-can'
|
|
#
|
|
# export default DunlopCan.extend
|
|
# # allow all epots scoped model on read adpter permission
|
|
# custom_compute: (permission, type, target, roles) ->
|
|
# return true if 'manage-adapter-epots' in roles
|
|
#
|
|
# if permission is 'read' and type is 'model' and target.match(/^epots/)
|
|
# return 'read-adapter-epots' in roles
|
|
# false
|
|
#
|
|
|
|
export default Ember.Helper.extend
|
|
globals: Ember.inject.service('globals')
|
|
|
|
# This method is meant to be overloaded for custom authorization hehaviour
|
|
custom_compute: (authorization, type, target, roles) -> false
|
|
|
|
# compute implements the standard dunlop checks. Application specific logic should be implemented
|
|
# in the custom_compute method
|
|
compute: ([authorization, type, target], options) ->
|
|
return false unless @get('globals.current_user')
|
|
return true if @get('globals.current_user.admin')
|
|
roles = @get('globals.current_user.role_names') || []
|
|
return true if "manage-#{type}-#{target}" in roles
|
|
return true if "#{authorization}-#{type}-#{target}" in roles
|
|
@custom_compute.call(@, authorization, type, target, roles)
|