dfunckt / django-rules

Awesome Django authorization, without the database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Updating permissions does not work

RonilRufo opened this issue · comments

I couldn't find any solution online to this issue so I'm hoping you could help me out. So here's the scenario. I first created the permission below weeks ago. Back then, I wanted to display the list of companies only to admin users:
add_perm('mining.list_company', is_admin_level)

The above code worked perfectly. However, couple of days ago, we have made some changes and we want the list of companies to be available to all users. So I have this now:
add_perm('mining.list_company', is_authenticated)

However, when I go to the company list page using a regular user, I still get a permission denied error even though I have already changed the permission. I went into a little bit of digging and it looks like the add_perm method gets executed only ONCE, that's why the is_authenticated does not get recognized. I was able to confirm this because when I tried adding pdb debugging inside the predicate itself, it does not get executed and just proceeds to permission denied error.

Am I missing anything here? It seems I'm the only one having this issue. Below are the necessary codes:

predicates.py

from __future__ import unicode_literals, absolute_import

from rules import predicate


@predicate()
def is_authenticated(user):
    return user.is_authenticated()

@predicate()
def is_admin_level(user):
    return user.is_admin_level

rules.py

from __future__ import unicode_literals, absolute_import
from rules import add_perm
from .predicates import is_authenticated

add_perm('mining.list_company', is_authenticated)

views.py

class CompanyList(LoginRequiredMixin, PermissionMixin, ListView):
    logger = logging.getLogger(__name__)
    context_object_name = 'companies'
    permission_required = 'mining.list_company'
    template_name = 'mining/company/list.html'
    paginate_by = 10

Again, everything is working perfectly fine before. The error appeared when I changed is_admin_level to is_authenticated. I would really appreciate it if you could point me to the right direction here. Thanks in advance!

@RonilRufo: I'm just trying to understand your issue.

Do you want to update the permissions without restarting the server or the process providing your application?

Closing as it seems resolved given no answer. Please reopen if needed.