Commit e1474c7a authored by Skia's avatar Skia
Browse files

Add is_root property to user

parent 79256399
Pipeline #115 failed with stage
in 2 minutes and 50 seconds
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
{%- endmacro %} {%- endmacro %}
{% block content %} {% block content %}
{% if user.is_superuser or user.is_in_group(settings.SITH_GROUPS['root']['name']) %} {% if user.is_root %}
<p><a href="{{ url('club:club_new') }}">{% trans %}New club{% endtrans %}</a></p> <p><a href="{{ url('club:club_new') }}">{% trans %}New club{% endtrans %}</a></p>
{% endif %} {% endif %}
{% if club_list %} {% if club_list %}
......
...@@ -223,6 +223,7 @@ class User(AbstractBaseUser): ...@@ -223,6 +223,7 @@ class User(AbstractBaseUser):
return True return True
return self.groups.filter(name=group_name).exists() return self.groups.filter(name=group_name).exists()
@property
def is_root(self): def is_root(self):
return self.is_superuser or self.groups.filter(name=settings.SITH_GROUPS['root']['name']).exists() return self.is_superuser or self.groups.filter(name=settings.SITH_GROUPS['root']['name']).exists()
...@@ -348,7 +349,7 @@ class User(AbstractBaseUser): ...@@ -348,7 +349,7 @@ class User(AbstractBaseUser):
return False return False
def can_be_edited_by(self, user): def can_be_edited_by(self, user):
return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_in_group(settings.SITH_GROUPS['root']['name']) return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_root
class AnonymousUser(AuthAnonymousUser): class AnonymousUser(AuthAnonymousUser):
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
{% endif %} {% endif %}
{% if profile.customer and (profile == request.user {% if profile.customer and (profile == request.user
or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name'])
or request.user.is_in_group(settings.SITH_GROUPS['root']['name'])) %} or request.user.is_root) %}
<a href="{{ url('core:user_account', user_id=profile.id) }}">{% trans %}Account{% endtrans %}</a> <a href="{{ url('core:user_account', user_id=profile.id) }}">{% trans %}Account{% endtrans %}</a>
{% endif %} {% endif %}
</div> </div>
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
<hr> <hr>
<h4>{% trans %}Sith management{% endtrans %}</h4> <h4>{% trans %}Sith management{% endtrans %}</h4>
<ul> <ul>
{% if user.is_in_group(settings.SITH_GROUPS['root']['name']) %} {% if user.is_root %}
<li><a href="{{ url('core:group_list') }}">{% trans %}Groups{% endtrans %}</a></li> <li><a href="{{ url('core:group_list') }}">{% trans %}Groups{% endtrans %}</a></li>
{% endif %} {% endif %}
{% if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %} {% if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_root %}
<li><a href="{{ url('subscription:subscription') }}">{% trans %}Subscriptions{% endtrans %}</a></li> <li><a href="{{ url('subscription:subscription') }}">{% trans %}Subscriptions{% endtrans %}</a></li>
{% endif %} {% endif %}
</ul> </ul>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<hr> <hr>
<h4>{% trans %}Counters{% endtrans %}</h4> <h4>{% trans %}Counters{% endtrans %}</h4>
<ul> <ul>
{% if user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %} {% if user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) or user.is_root %}
<h5>{% trans %}General management{% endtrans %}</h5> <h5>{% trans %}General management{% endtrans %}</h5>
<li><a href="{{ url('counter:admin_list') }}">{% trans %}General counters management{% endtrans %}</a></li> <li><a href="{{ url('counter:admin_list') }}">{% trans %}General counters management{% endtrans %}</a></li>
<li><a href="{{ url('counter:product_list') }}">{% trans %}Products management{% endtrans %}</a></li> <li><a href="{{ url('counter:product_list') }}">{% trans %}Products management{% endtrans %}</a></li>
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<hr> <hr>
<h4>{% trans %}Accounting{% endtrans %}</h4> <h4>{% trans %}Accounting{% endtrans %}</h4>
<ul> <ul>
{% if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %} {% if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) or user.is_root %}
<li><a href="{{ url('accounting:bank_list') }}">{% trans %}General accounting{% endtrans %}</a></li> <li><a href="{{ url('accounting:bank_list') }}">{% trans %}General accounting{% endtrans %}</a></li>
{% endif %} {% endif %}
{% for m in user.membership.filter(end_date=None).filter(role__gte=7).all() %} {% for m in user.membership.filter(end_date=None).filter(role__gte=7).all() %}
......
...@@ -46,7 +46,7 @@ def password_root_change(request, user_id): ...@@ -46,7 +46,7 @@ def password_root_change(request, user_id):
""" """
Allows a root user to change someone's password Allows a root user to change someone's password
""" """
if not request.user.is_superuser and not request.user.is_in_group(settings.SITH_GROUPS['root']['name']): if not request.user.is_root:
raise PermissionDenied raise PermissionDenied
user = User.objects.filter(id=user_id).first() user = User.objects.filter(id=user_id).first()
if not user: if not user:
...@@ -196,7 +196,7 @@ class UserAccountView(DetailView): ...@@ -196,7 +196,7 @@ class UserAccountView(DetailView):
res = super(UserAccountView, self).dispatch(request, *arg, **kwargs) res = super(UserAccountView, self).dispatch(request, *arg, **kwargs)
if (self.object == request.user if (self.object == request.user
or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name'])
or request.user.is_in_group(settings.SITH_GROUPS['root']['name'])): or request.user.is_root):
return res return res
raise PermissionDenied raise PermissionDenied
......
...@@ -115,7 +115,7 @@ class Subscription(models.Model): ...@@ -115,7 +115,7 @@ class Subscription(models.Model):
def can_be_edited_by(self, user): def can_be_edited_by(self, user):
return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_in_group(settings.SITH_GROUPS['root']['name']) return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_root
def is_valid_now(self): def is_valid_now(self):
return self.subscription_start <= date.today() and date.today() <= self.subscription_end return self.subscription_start <= date.today() and date.today() <= self.subscription_end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment