Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom actions and filtering in the template #87

Open
coaperator opened this issue Jun 14, 2020 · 3 comments
Open

Custom actions and filtering in the template #87

coaperator opened this issue Jun 14, 2020 · 3 comments
Labels
feature request Considered to be implemented. question A question rather than an issue.

Comments

@coaperator
Copy link

coaperator commented Jun 14, 2020

Hello!
I use express, passport and ejs template engine in my application

  1. The documentation describes CRUD actions, but I need to create my own operations, such as shuffling a post, splitting a post, showing a download button, allowing downloading, etc.
    How can i do this?

  2. How can I check access to several (for example 10) functions in a template?
    For example, I need to display a list of links for administering publications, such as creating, editing, moving, deleting, etc.
    My template:

<ul>
	<li>Create</li>
	<li>Edit</li>
	<li>Move</li>
	<li>Delete</li>
</ul>

I understand correctly that if I need to check when and why to display this or that link, will I have to write such a check?

<% if(ac.can('admin').updateAny('postView')) { %>
<ul>
	<% if(ac.can('admin').updateAny('postCreate')) { %>
	<li>Create</li>
	<% } %>

	<% if(ac.can('admin').updateAny('postEdit')) { %>
	<li>Edit</li>
	<% } %>

	<% if(ac.can('admin').updateAny('postMove')) { %>
	<li>Move</li>
	<% } %>

	<% if(ac.can('admin').updateAny('postDelete')) { %>
	<li>Delete</li>
	<% } %>
</ul>
<% } %>

and if I have 10 conditions(I have 10 roles - User, Editor, Admin, Moderator etc..), then will I have to write all of them into the IF condition?

@nitishmakhija
Copy link

Did you figure it out?

@coaperator
Copy link
Author

Did you figure it out?

no

@onury
Copy link
Owner

onury commented Jan 16, 2021

You should never hard-code the role like that. This will never restrict the data.
"admin" can always do those actions to those resources (in your context).
But is the current user an admin?

You should ask: "can the current user's role(s) do that?"

<% if (ac.can(currentUser.roles).update('postView')) { %>
<ul>
    <!-- Allowed content  -->
</ul>
<% } %>

About your other question; AC currently supports CRUD actions only which virtually covers any action that could be applied to a resource (similar to the REST methodology). You just need to decide what the resource is, in your application's context.

You can read the F.A.Q. for more insight to what I mean. But in future, I plan for enabling custom actions.

@onury onury added question A question rather than an issue. feature request Considered to be implemented. labels Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Considered to be implemented. question A question rather than an issue.
Projects
None yet
Development

No branches or pull requests

3 participants