From 67fef8e184d655a17f5138a68eadcdc0d46da0b2 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Wed, 17 Jan 2018 15:05:48 -0300 Subject: [PATCH] can authorization helper mixing better explanation --- addon/helpers/dunlop-can.coffee | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/addon/helpers/dunlop-can.coffee b/addon/helpers/dunlop-can.coffee index 0eda797..2ed9446 100644 --- a/addon/helpers/dunlop-can.coffee +++ b/addon/helpers/dunlop-can.coffee @@ -1,9 +1,25 @@ import Ember from 'ember' +# Example usage +# /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) -> +# 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') - custom_compute: (authorization, type, target, roles) -> - false + + # 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')