mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Refactor group settings
This commit is contained in:
@ -31,8 +31,15 @@ class Command(BaseCommand):
|
||||
os.environ['DJANGO_COLORS'] = 'nocolor'
|
||||
Site(id=4000, domain=settings.SITH_URL, name=settings.SITH_NAME).save()
|
||||
root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||
for g in settings.SITH_GROUPS.values():
|
||||
Group(id=g['id'], name=g['name']).save()
|
||||
Group(name="Root").save()
|
||||
Group(name="Not registered users").save()
|
||||
Group(name="Accounting admin").save()
|
||||
Group(name="Communication admin").save()
|
||||
Group(name="Counter admin").save()
|
||||
Group(name="Banned from buying alcohol").save()
|
||||
Group(name="Banned from counters").save()
|
||||
Group(name="Banned to subscribe").save()
|
||||
Group(name="SAS admin").save()
|
||||
self.reset_index("core", "auth")
|
||||
root = User(id=0, username='root', last_name="", first_name="Bibou",
|
||||
email="ae.info@utbm.fr",
|
||||
@ -46,7 +53,6 @@ class Command(BaseCommand):
|
||||
club_root = SithFile(parent=None, name="clubs", is_folder=True, owner=root)
|
||||
club_root.save()
|
||||
SithFile(parent=None, name="SAS", is_folder=True, owner=root).save()
|
||||
Group(name="SAS admin").save()
|
||||
main_club = Club(id=1, name=settings.SITH_MAIN_CLUB['name'], unix_name=settings.SITH_MAIN_CLUB['unix_name'],
|
||||
address=settings.SITH_MAIN_CLUB['address'])
|
||||
main_club.save()
|
||||
@ -77,7 +83,7 @@ class Command(BaseCommand):
|
||||
p = Page(name='Index')
|
||||
p.set_lock(root)
|
||||
p.save()
|
||||
p.view_groups=[settings.SITH_GROUPS['public']['id']]
|
||||
p.view_groups=[settings.SITH_GROUP_PUBLIC_ID]
|
||||
p.set_lock(root)
|
||||
p.save()
|
||||
PageRev(page=p, title="Wiki index", author=root, content="""
|
||||
@ -87,7 +93,7 @@ Welcome to the wiki page!
|
||||
p = Page(name="services")
|
||||
p.set_lock(root)
|
||||
p.save()
|
||||
p.view_groups=[settings.SITH_GROUPS['public']['id']]
|
||||
p.view_groups=[settings.SITH_GROUP_PUBLIC_ID]
|
||||
p.set_lock(root)
|
||||
PageRev(page=p, title="Services", author=root, content="""
|
||||
| | | |
|
||||
@ -139,7 +145,7 @@ Welcome to the wiki page!
|
||||
counter.set_password("plop")
|
||||
counter.save()
|
||||
counter.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id]
|
||||
counter.groups=[Group.objects.filter(name=settings.SITH_GROUPS['counter-admin']['name']).first().id]
|
||||
counter.groups=[Group.objects.filter(id=settings.SITH_GROUP_COUNTER_ADMIN_ID).first().id]
|
||||
counter.save()
|
||||
# Adding user Comptable
|
||||
comptable = User(username='comptable', last_name="Able", first_name="Compte",
|
||||
@ -149,7 +155,7 @@ Welcome to the wiki page!
|
||||
comptable.set_password("plop")
|
||||
comptable.save()
|
||||
comptable.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id]
|
||||
comptable.groups=[Group.objects.filter(name=settings.SITH_GROUPS['accounting-admin']['name']).first().id]
|
||||
comptable.groups=[Group.objects.filter(id=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID).first().id]
|
||||
comptable.save()
|
||||
# Adding user Guy
|
||||
u = User(username='guy', last_name="Carlier", first_name="Guy",
|
||||
@ -176,7 +182,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
|
||||
""").save()
|
||||
p = Page(name='Services')
|
||||
p.save(force_lock=True)
|
||||
p.view_groups=[settings.SITH_GROUPS['public']['id']]
|
||||
p.view_groups=[settings.SITH_GROUP_PUBLIC_ID]
|
||||
p.save(force_lock=True)
|
||||
PageRev(page=p, title="Services", author=skia, content="""
|
||||
| | | |
|
||||
@ -188,7 +194,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
|
||||
# Adding README
|
||||
p = Page(name='README')
|
||||
p.save(force_lock=True)
|
||||
p.view_groups=[settings.SITH_GROUPS['public']['id']]
|
||||
p.view_groups=[settings.SITH_GROUP_PUBLIC_ID]
|
||||
p.save(force_lock=True)
|
||||
with open(os.path.join(root_path)+'/README.md', 'r') as rm:
|
||||
PageRev(page=p, title="README", author=skia, content=rm.read()).save()
|
||||
|
@ -197,13 +197,15 @@ class User(AbstractBaseUser):
|
||||
|
||||
def is_in_group(self, group_name):
|
||||
"""If the user is in the group passed in argument (as string or by id)"""
|
||||
group_id = 0
|
||||
if isinstance(group_name, int): # Handle the case where group_name is an ID
|
||||
g = Group.objects.filter(id=group_name).first()
|
||||
if g:
|
||||
group_name = g.name
|
||||
group_id = g.id
|
||||
else:
|
||||
return False
|
||||
if group_name == settings.SITH_GROUPS['public']['name']:
|
||||
if group_id == settings.SITH_GROUP_PUBLIC_ID:
|
||||
return True
|
||||
if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked
|
||||
if 'subscription' in settings.INSTALLED_APPS:
|
||||
@ -231,13 +233,13 @@ class User(AbstractBaseUser):
|
||||
if mem:
|
||||
return True
|
||||
return False
|
||||
if group_name == settings.SITH_GROUPS['root']['name'] and self.is_superuser:
|
||||
if group_id == settings.SITH_GROUP_ROOT_ID and self.is_superuser:
|
||||
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()
|
||||
return self.is_superuser or self.groups.filter(id=settings.SITH_GROUP_ROOT_ID).exists()
|
||||
|
||||
@property
|
||||
def is_board_member(self):
|
||||
@ -251,11 +253,11 @@ class User(AbstractBaseUser):
|
||||
|
||||
@property
|
||||
def is_banned_alcohol(self):
|
||||
return self.is_in_group(settings.SITH_GROUPS['banned-alcohol']['name'])
|
||||
return self.is_in_group(settings.SITH_GROUP_BANNED_ALCOHOL_ID)
|
||||
|
||||
@property
|
||||
def is_banned_counter(self):
|
||||
return self.is_in_group(settings.SITH_GROUPS['banned-from-counters']['name'])
|
||||
return self.is_in_group(settings.SITH_GROUP_BANNED_COUNTER_ID)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
create = False
|
||||
@ -373,7 +375,7 @@ class User(AbstractBaseUser):
|
||||
return True
|
||||
if hasattr(obj, "owner_group") and self.is_in_group(obj.owner_group.name):
|
||||
return True
|
||||
if self.is_superuser or self.is_in_group(settings.SITH_GROUPS['root']['name']):
|
||||
if self.is_superuser or self.is_in_group(settings.SITH_GROUP_ROOT_ID):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -463,7 +465,15 @@ class AnonymousUser(AuthAnonymousUser):
|
||||
"""
|
||||
The anonymous user is only the public group
|
||||
"""
|
||||
if group_name == settings.SITH_GROUPS['public']['name']:
|
||||
group_id = 0
|
||||
if isinstance(group_name, int): # Handle the case where group_name is an ID
|
||||
g = Group.objects.filter(id=group_name).first()
|
||||
if g:
|
||||
group_name = g.name
|
||||
group_id = g.id
|
||||
else:
|
||||
return False
|
||||
if group_id == settings.SITH_GROUP_PUBLIC_ID:
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -474,7 +484,7 @@ class AnonymousUser(AuthAnonymousUser):
|
||||
return False
|
||||
|
||||
def can_view(self, obj):
|
||||
if hasattr(obj, 'view_groups') and obj.view_groups.filter(pk=settings.SITH_GROUPS['public']['id']).exists():
|
||||
if hasattr(obj, 'view_groups') and obj.view_groups.filter(id=settings.SITH_GROUP_PUBLIC_ID).exists():
|
||||
return True
|
||||
if hasattr(obj, 'can_be_viewed_by') and obj.can_be_viewed_by(self):
|
||||
return True
|
||||
@ -523,7 +533,7 @@ class SithFile(models.Model):
|
||||
def is_owned_by(self, user):
|
||||
if hasattr(self, 'profile_of') and user.is_in_group(settings.SITH_MAIN_BOARD_GROUP):
|
||||
return True
|
||||
if user.is_in_group(settings.SITH_GROUPS['communication-admin']['id']):
|
||||
if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID):
|
||||
return True
|
||||
return user.id == self.owner.id
|
||||
|
||||
@ -667,7 +677,7 @@ class Page(models.Model):
|
||||
# playing with a Page object, use get_full_name() instead!
|
||||
_full_name = models.CharField(_('page name'), max_length=255, blank=True)
|
||||
owner_group = models.ForeignKey(Group, related_name="owned_page", verbose_name=_("owner group"),
|
||||
default=settings.SITH_GROUPS['root']['id'])
|
||||
default=settings.SITH_GROUP_ROOT_ID)
|
||||
edit_groups = models.ManyToManyField(Group, related_name="editable_page", verbose_name=_("edit group"), blank=True)
|
||||
view_groups = models.ManyToManyField(Group, related_name="viewable_page", verbose_name=_("view group"), blank=True)
|
||||
lock_user = models.ForeignKey(User, related_name="locked_pages", verbose_name=_("lock user"), blank=True, null=True, default=None)
|
||||
|
@ -42,7 +42,7 @@
|
||||
{% if not file.home_of and not file.home_of_club and file.parent %}
|
||||
<p><a href="{{ url('core:file_delete', file_id=file.id, popup=popup) }}">{% trans %}Delete{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
{% if user.is_in_group(settings.SITH_GROUPS['communication-admin']['id']) %}
|
||||
{% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) %}
|
||||
<p><a href="{{ url('core:file_moderate', file_id=file.id) }}">{% trans %}Moderate{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
@ -23,7 +23,7 @@
|
||||
<hr>
|
||||
<h4>{% trans %}Counters{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% if user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) or user.is_root %}
|
||||
{% if user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID) 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>
|
||||
@ -42,7 +42,7 @@
|
||||
<hr>
|
||||
<h4>{% trans %}Accounting{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) or user.is_root %}
|
||||
{% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) or user.is_root %}
|
||||
<li><a href="{{ url('accounting:refound_account') }}">{% trans %}Refound Account{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('accounting:bank_list') }}">{% trans %}General accounting{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
@ -62,10 +62,10 @@
|
||||
<hr>
|
||||
<h4>{% trans %}Communication{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% if user.is_in_group(settings.SITH_GROUPS['communication-admin']['id']) %}
|
||||
{% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) %}
|
||||
<li><a href="{{ url('core:file_moderation') }}">{% trans %}Moderate files{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
{% if user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID) %}
|
||||
{% if user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) %}
|
||||
<li><a href="{{ url('sas:moderation') }}">{% trans %}Moderate pictures{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
@ -69,7 +69,7 @@ class AddFilesForm(forms.Form):
|
||||
except Exception as e:
|
||||
self.add_error(None, _("Error uploading file %(file_name)s: %(msg)s") % {'file_name': f, 'msg': repr(e)})
|
||||
if notif:
|
||||
for u in RealGroup.objects.filter(id=settings.SITH_SAS_ADMIN_GROUP_ID).first().users.all():
|
||||
for u in RealGroup.objects.filter(id=settings.SITH_GROUP_SAS_ADMIN_ID).first().users.all():
|
||||
if not u.notifications.filter(type="FILE_MODERATION").exists():
|
||||
Notification(user=u, url=reverse("core:file_moderation"), type="FILE_MODERATION").save()
|
||||
|
||||
|
@ -165,7 +165,7 @@ class UserTabsMixin(TabedViewMixin):
|
||||
})
|
||||
try:
|
||||
if (self.object.customer and (self.object == self.request.user
|
||||
or self.request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name'])
|
||||
or self.request.user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID)
|
||||
or self.request.user.is_in_group(settings.SITH_BAR_MANAGER['unix_name']+settings.SITH_BOARD_SUFFIX)
|
||||
or self.request.user.is_root)):
|
||||
tab_list.append({
|
||||
@ -417,7 +417,7 @@ class UserAccountBase(UserTabsMixin, DetailView):
|
||||
def dispatch(self, request, *arg, **kwargs): # Manually validates the rights
|
||||
res = super(UserAccountBase, 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_GROUP_ACCOUNTING_ADMIN_ID)
|
||||
or request.user.is_in_group(settings.SITH_BAR_MANAGER['unix_name']+settings.SITH_BOARD_SUFFIX)
|
||||
or request.user.is_root):
|
||||
return res
|
||||
|
Reference in New Issue
Block a user