In Dashboards categ...
 
Notifications
Clear all

In Dashboards categories.html , i tried to change that users with editor role can only edit or delete the category, but not normal user.i tried modifying the code it is working for normal users, but for editors also it is donot have permission

1 Posts
2 Users
0 Reactions
143 Views
0
Topic starter
categories.html:
{% extends 'base.html' %}


{% block content %}
<div class="row">
    <!-- Left  sidebar -->
    <!-- load the side bar -->
    {% include 'dashboard/sidebar.html' %}
    <!-- Right Side Content-->
     <div class="col-md-9">
        <h3 class="text-center">All Categories</h3>
        <a href="{% url 'add_category' %}" class="btn btn-dark text-light float-right mb-2">Add New</a>
        <table class="table table-hover">
            <thead>
              <tr>
                <th>#</th>
                <th>Category Name</th>
                <th>Created At</th>
                <th>Updated At</th>
                <th>Action</th>
              </tr>
            </thead>
            <tbody>
            {% for category in categories %}
              <tr>
                <td>{{ forloop.counter }}</td>
                <td>{{ category }}</td>
                <td>{{ category.created_at }}</td>
                <td>{{ category.updated_at }}</td>
                <td>
                  {% if perms.auth.change_category %}
                    <a href="{% url 'edit_category' category.id %}"><i class="fa fa-edit text-success"></i></a>
                    &nbsp;
                    <a href="{% url 'delete_category' category.id %}"><i class="fa fa-trash text-danger"></i></a>
                    {% else %}
                    <h5>You do not have permission to change or delete.</h5>
                  {% endif%}
                </td>
              </tr>
            {% endfor %}


            </tbody>
          </table>
     </div>
</div>


{% endblock %}
This topic was modified 2 months ago by Rathan Kumar
1 Answer
0

Hi VIGNESH SR 

I think the your goal is to allow users with the editor role to edit or delete categories, but not regular users. The issue is likely related to how the permissions are checked in your template. The condition you’re using checks for the change_category permission, but it doesn’t differentiate between users with different roles.

To fix this, you should modify the logic in your template to check if the user is an editor before allowing them to edit or delete a category. Here’s how you can do it:

  1. Define the editor role in your user model: Ensure that your user model or the associated groups are set up correctly so that you can check for the editor role.

  2. Modify the template to check for the editor role: Update the template to check if the user is an editor or has the necessary permissions.

Alternatively, you can use a custom role to define specific users who can edit or delete.

If you encounter any issues while making these changes, please share your GitHub repository, and feel free to ask for any help.

Share: