Commit e1474c7a authored by Skia's avatar Skia

Add is_root property to user

parent 79256399
Pipeline #115 failed with stage
in 2 minutes and 50 seconds
......@@ -17,7 +17,7 @@
{%- endmacro %}
{% 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>
{% endif %}
{% if club_list %}
......
......@@ -223,6 +223,7 @@ class User(AbstractBaseUser):
return True
return self.groups.filter(name=group_name).exists()
@property
def is_root(self):
return self.is_superuser or self.groups.filter(name=settings.SITH_GROUPS['root']['name']).exists()
......@@ -348,7 +349,7 @@ class User(AbstractBaseUser):
return False
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):
......
......@@ -13,7 +13,7 @@
{% endif %}
{% 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['root']['name'])) %}
or request.user.is_root) %}
<a href="{{ url('core:user_account', user_id=profile.id) }}">{% trans %}Account{% endtrans %}</a>
{% endif %}
</div>
......
......@@ -10,10 +10,10 @@
<hr>
<h4>{% trans %}Sith management{% endtrans %}</h4>
<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>
{% 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>
{% endif %}
</ul>
......@@ -21,7 +21,7 @@
<hr>
<h4>{% trans %}Counters{% endtrans %}</h4>
<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>
<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>
......@@ -38,7 +38,7 @@
<hr>
<h4>{% trans %}Accounting{% endtrans %}</h4>
<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>
{% endif %}
{% 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):
"""
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
user = User.objects.filter(id=user_id).first()
if not user:
......@@ -196,7 +196,7 @@ class UserAccountView(DetailView):
res = super(UserAccountView, self).dispatch(request, *arg, **kwargs)
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['root']['name'])):
or request.user.is_root):
return res
raise PermissionDenied
......
......@@ -115,7 +115,7 @@ class Subscription(models.Model):
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):
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