This commit is contained in:
zmagod 2018-01-12 11:38:52 +01:00
parent 0d7c116de1
commit 371491c259
2 changed files with 13 additions and 15 deletions

View file

@ -20,16 +20,16 @@ module ClientApi
.public_send(:find_by_id, @resource.fetch(:id) {
raise ArgumentError, 'ID must be present'
}) if @resource
@required_permissions.collect do |permission|
parsed_permision = permission.gsub('can_', '')
@required_permissions.each do |permission|
trim_permission = permission.gsub('can_', '')
if @resource
# return false if object does not exist
result = obj ? @holder.eval('read_team', current_user, obj) : false
result = obj ? @holder.eval(trim_permission, current_user, obj) : false
@permissions.merge!(permission => result)
else
@permissions.merge!(
permission => @holder.eval_generic(
parsed_permision, current_user
trim_permission, current_user
)
)
end

View file

@ -8,20 +8,20 @@
pass this "permissions helper methods" in your component params:
If you need to specific model you have to specify it in the connect method
like the example below
like the example below:
>
> Permissions.connect(MyComponent, ["can_update_team", "can_read_team"], "Team");
>
In case your component is connected to Redux or some other HOC you can simply
chain the HOC's
chain the HOC's:
>
> const mapStateToProps = ({ current_team }) => ({ current_team });
> const MyComponentWithPermissions = Permissions.connect(MyComponent, ["can_read_team"], "Team");
> export default connect(mapStateToProps)(MyComponentWithPermissions);
>
beside the permissions object you get the setPermissionResourceId/1 function
in your component props. Than you can pass the id of the resource when you have it.
Beside the permissions object there's also the setPermissionResourceId/1 function in your component props.
This function should be used to pass the ID of the resource when you have it.
Example: you need the current team for whatever reason you can call it in the
shouldComponentUpdate function...
@ -31,11 +31,10 @@
> return true; // remember to return true!
> }
JUST REMEMBER THAT YOU HAVE PASS A VALID ID and you have to check if is present
at the moment of execution. THE REQUEST WILL BE TRIGGERED WHEN YOU INVOKE
setPermissionResourceId/1 FUNCTION!!!!
JUST REMEMBER THAT YOU HAVE TO PASS A VALID ID and you have to check if it's present at the moment of the execution.
THE REQUEST WILL BE TRIGGERED WHEN YOU INVOKE setPermissionResourceId/1 FUNCTION!!!
else you can pass just the perrmissions on the user
Otherwise (generic permissions without the accessed object) you can just pass the permissions on the user
>
> Permissions.connect(MyComponent, ["can_update"])
>
@ -44,9 +43,8 @@
Now you can access your permissions through component params. The permissions
you required have 3 states [true, false, null]. Null is when you are waiting for server response.
Finally you can access to your permissions in the component using
props.permissions.can_.... whatever you specify. The props.permissions is
basically an object that holds all required permissions.
Finally you can access your permissions in the component using props.permissions.can_... whatever you specify.
The props.permissions is basically an object that holds all required permissions.
*/
import * as React from "react";