Refactor group settings

This commit is contained in:
Skia 2016-12-10 01:29:56 +01:00
parent 1649d14518
commit 0d4b697079
16 changed files with 82 additions and 94 deletions

View File

@ -68,7 +68,7 @@ class BankAccount(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
m = self.club.get_membership_for(user) m = self.club.get_membership_for(user)
if m is not None and m.role >= 7: if m is not None and m.role >= 7:
@ -94,7 +94,7 @@ class ClubAccount(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
return False return False
@ -155,7 +155,7 @@ class GeneralJournal(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
if self.club_account.can_be_edited_by(user): if self.club_account.can_be_edited_by(user):
return True return True
@ -260,7 +260,7 @@ class Operation(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
if self.journal.closed: if self.journal.closed:
return False return False
@ -308,7 +308,7 @@ class AccountingType(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
return False return False

View File

@ -8,7 +8,7 @@
<h4> <h4>
{% trans %}Accounting{% endtrans %} {% trans %}Accounting{% endtrans %}
</h4> </h4>
{% if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) %} {% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
<p><a href="{{ url('accounting:simple_type_list') }}">{% trans %}Manage simplified types{% endtrans %}</a></p> <p><a href="{{ url('accounting:simple_type_list') }}">{% trans %}Manage simplified types{% endtrans %}</a></p>
<p><a href="{{ url('accounting:type_list') }}">{% trans %}Manage accounting types{% endtrans %}</a></p> <p><a href="{{ url('accounting:type_list') }}">{% trans %}Manage accounting types{% endtrans %}</a></p>
<p><a href="{{ url('accounting:bank_new') }}">{% trans %}New bank account{% endtrans %}</a></p> <p><a href="{{ url('accounting:bank_new') }}">{% trans %}New bank account{% endtrans %}</a></p>

View File

@ -367,11 +367,11 @@ class OperationPDFView(CanViewMixin, DetailView):
im = ImageReader("core/static/core/img/logo.jpg") im = ImageReader("core/static/core/img/logo.jpg")
iw, ih = im.getSize() iw, ih = im.getSize()
p.drawImage(im, 40, height - 50, width=iw/2, height=ih/2) p.drawImage(im, 40, height - 50, width=iw/2, height=ih/2)
labelStr = [["%s %s - %s %s" % (_("Journal"), ti, _("Operation"), num)]] labelStr = [["%s %s - %s %s" % (_("Journal"), ti, _("Operation"), num)]]
label = Table(labelStr, colWidths=[150], rowHeights=[20]) label = Table(labelStr, colWidths=[150], rowHeights=[20])
label.setStyle(TableStyle([ label.setStyle(TableStyle([
('ALIGN',(0,0),(-1,-1),'CENTER'), ('ALIGN',(0,0),(-1,-1),'CENTER'),
('BOX', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black),
@ -384,11 +384,11 @@ class OperationPDFView(CanViewMixin, DetailView):
p.drawString(90, height - 160, _("Label: %(op_label)s") % {"op_label": op_label if op_label != None else ""}) p.drawString(90, height - 160, _("Label: %(op_label)s") % {"op_label": op_label if op_label != None else ""})
data = [] data = []
data += [["%s" % (_("Credit").upper() if nature == 'CREDIT' else _("Debit").upper())]] data += [["%s" % (_("Credit").upper() if nature == 'CREDIT' else _("Debit").upper())]]
data += [[_("Amount: %(amount).2f") % {"amount": amount}]] data += [[_("Amount: %(amount).2f") % {"amount": amount}]]
payment_mode = "" payment_mode = ""
for m in settings.SITH_ACCOUNTING_PAYMENT_METHOD: for m in settings.SITH_ACCOUNTING_PAYMENT_METHOD:
if m[0] == mode: if m[0] == mode:
@ -398,11 +398,11 @@ class OperationPDFView(CanViewMixin, DetailView):
payment_mode += " %s\n" %(m[1]) payment_mode += " %s\n" %(m[1])
data += [[payment_mode]] data += [[payment_mode]]
data += [["%s : %s" % (_("Debtor") if nature == 'CREDIT' else _("Creditor"), target), ""]] data += [["%s : %s" % (_("Debtor") if nature == 'CREDIT' else _("Creditor"), target), ""]]
data += [["%s \n%s" % (_("Comment:"), remark)]] data += [["%s \n%s" % (_("Comment:"), remark)]]
t = Table(data, colWidths=[(width-90*2)/2]*2, rowHeights=[20, 20, 70, 20, 80]) t = Table(data, colWidths=[(width-90*2)/2]*2, rowHeights=[20, 20, 70, 20, 80])
t.setStyle(TableStyle([ t.setStyle(TableStyle([
('ALIGN',(0,0),(-1,-1),'CENTER'), ('ALIGN',(0,0),(-1,-1),'CENTER'),
@ -498,7 +498,7 @@ class RefoundAccountView(FormView):
form_class = CloseCustomerAccountForm form_class = CloseCustomerAccountForm
def permission(self, user): def permission(self, user):
if user.is_root or user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_root or user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
else: else:
raise PermissionDenied raise PermissionDenied

View File

@ -33,7 +33,7 @@ class Club(models.Model):
address = models.CharField(_('address'), max_length=254) address = models.CharField(_('address'), max_length=254)
# email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically # email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically
owner_group = models.ForeignKey(Group, related_name="owned_club", owner_group = models.ForeignKey(Group, related_name="owned_club",
default=settings.SITH_GROUPS['root']['id']) default=settings.SITH_GROUP_ROOT_ID)
edit_groups = models.ManyToManyField(Group, related_name="editable_club", blank=True) edit_groups = models.ManyToManyField(Group, related_name="editable_club", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_club", blank=True) view_groups = models.ManyToManyField(Group, related_name="viewable_club", blank=True)
home = models.OneToOneField(SithFile, related_name='home_of_club', verbose_name=_("home"), null=True, blank=True, home = models.OneToOneField(SithFile, related_name='home_of_club', verbose_name=_("home"), null=True, blank=True,

View File

@ -31,8 +31,15 @@ class Command(BaseCommand):
os.environ['DJANGO_COLORS'] = 'nocolor' os.environ['DJANGO_COLORS'] = 'nocolor'
Site(id=4000, domain=settings.SITH_URL, name=settings.SITH_NAME).save() 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__)))) root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
for g in settings.SITH_GROUPS.values(): Group(name="Root").save()
Group(id=g['id'], name=g['name']).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") self.reset_index("core", "auth")
root = User(id=0, username='root', last_name="", first_name="Bibou", root = User(id=0, username='root', last_name="", first_name="Bibou",
email="ae.info@utbm.fr", 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 = SithFile(parent=None, name="clubs", is_folder=True, owner=root)
club_root.save() club_root.save()
SithFile(parent=None, name="SAS", is_folder=True, owner=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'], 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']) address=settings.SITH_MAIN_CLUB['address'])
main_club.save() main_club.save()
@ -77,7 +83,7 @@ class Command(BaseCommand):
p = Page(name='Index') p = Page(name='Index')
p.set_lock(root) p.set_lock(root)
p.save() p.save()
p.view_groups=[settings.SITH_GROUPS['public']['id']] p.view_groups=[settings.SITH_GROUP_PUBLIC_ID]
p.set_lock(root) p.set_lock(root)
p.save() p.save()
PageRev(page=p, title="Wiki index", author=root, content=""" PageRev(page=p, title="Wiki index", author=root, content="""
@ -87,7 +93,7 @@ Welcome to the wiki page!
p = Page(name="services") p = Page(name="services")
p.set_lock(root) p.set_lock(root)
p.save() p.save()
p.view_groups=[settings.SITH_GROUPS['public']['id']] p.view_groups=[settings.SITH_GROUP_PUBLIC_ID]
p.set_lock(root) p.set_lock(root)
PageRev(page=p, title="Services", author=root, content=""" PageRev(page=p, title="Services", author=root, content="""
| | | | | | | |
@ -139,7 +145,7 @@ Welcome to the wiki page!
counter.set_password("plop") counter.set_password("plop")
counter.save() counter.save()
counter.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id] 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() counter.save()
# Adding user Comptable # Adding user Comptable
comptable = User(username='comptable', last_name="Able", first_name="Compte", comptable = User(username='comptable', last_name="Able", first_name="Compte",
@ -149,7 +155,7 @@ Welcome to the wiki page!
comptable.set_password("plop") comptable.set_password("plop")
comptable.save() comptable.save()
comptable.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id] 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() comptable.save()
# Adding user Guy # Adding user Guy
u = User(username='guy', last_name="Carlier", first_name="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() """).save()
p = Page(name='Services') p = Page(name='Services')
p.save(force_lock=True) 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) p.save(force_lock=True)
PageRev(page=p, title="Services", author=skia, content=""" 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 # Adding README
p = Page(name='README') p = Page(name='README')
p.save(force_lock=True) 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) p.save(force_lock=True)
with open(os.path.join(root_path)+'/README.md', 'r') as rm: with open(os.path.join(root_path)+'/README.md', 'r') as rm:
PageRev(page=p, title="README", author=skia, content=rm.read()).save() PageRev(page=p, title="README", author=skia, content=rm.read()).save()

View File

@ -197,13 +197,15 @@ class User(AbstractBaseUser):
def is_in_group(self, group_name): def is_in_group(self, group_name):
"""If the user is in the group passed in argument (as string or by id)""" """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 if isinstance(group_name, int): # Handle the case where group_name is an ID
g = Group.objects.filter(id=group_name).first() g = Group.objects.filter(id=group_name).first()
if g: if g:
group_name = g.name group_name = g.name
group_id = g.id
else: else:
return False return False
if group_name == settings.SITH_GROUPS['public']['name']: if group_id == settings.SITH_GROUP_PUBLIC_ID:
return True return True
if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked
if 'subscription' in settings.INSTALLED_APPS: if 'subscription' in settings.INSTALLED_APPS:
@ -231,13 +233,13 @@ class User(AbstractBaseUser):
if mem: if mem:
return True return True
return False 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 True
return self.groups.filter(name=group_name).exists() return self.groups.filter(name=group_name).exists()
@property @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(id=settings.SITH_GROUP_ROOT_ID).exists()
@property @property
def is_board_member(self): def is_board_member(self):
@ -251,11 +253,11 @@ class User(AbstractBaseUser):
@property @property
def is_banned_alcohol(self): 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 @property
def is_banned_counter(self): 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): def save(self, *args, **kwargs):
create = False create = False
@ -373,7 +375,7 @@ class User(AbstractBaseUser):
return True return True
if hasattr(obj, "owner_group") and self.is_in_group(obj.owner_group.name): if hasattr(obj, "owner_group") and self.is_in_group(obj.owner_group.name):
return True 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 True
return False return False
@ -463,7 +465,15 @@ class AnonymousUser(AuthAnonymousUser):
""" """
The anonymous user is only the public group 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 True
return False return False
@ -474,7 +484,7 @@ class AnonymousUser(AuthAnonymousUser):
return False return False
def can_view(self, obj): 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 return True
if hasattr(obj, 'can_be_viewed_by') and obj.can_be_viewed_by(self): if hasattr(obj, 'can_be_viewed_by') and obj.can_be_viewed_by(self):
return True return True
@ -523,7 +533,7 @@ class SithFile(models.Model):
def is_owned_by(self, user): def is_owned_by(self, user):
if hasattr(self, 'profile_of') and user.is_in_group(settings.SITH_MAIN_BOARD_GROUP): if hasattr(self, 'profile_of') and user.is_in_group(settings.SITH_MAIN_BOARD_GROUP):
return True 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 True
return user.id == self.owner.id return user.id == self.owner.id
@ -667,7 +677,7 @@ class Page(models.Model):
# playing with a Page object, use get_full_name() instead! # playing with a Page object, use get_full_name() instead!
_full_name = models.CharField(_('page name'), max_length=255, blank=True) _full_name = models.CharField(_('page name'), max_length=255, blank=True)
owner_group = models.ForeignKey(Group, related_name="owned_page", verbose_name=_("owner group"), 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) 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) 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) lock_user = models.ForeignKey(User, related_name="locked_pages", verbose_name=_("lock user"), blank=True, null=True, default=None)

View File

@ -42,7 +42,7 @@
{% if not file.home_of and not file.home_of_club and file.parent %} {% 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> <p><a href="{{ url('core:file_delete', file_id=file.id, popup=popup) }}">{% trans %}Delete{% endtrans %}</a></p>
{% endif %} {% 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> <p><a href="{{ url('core:file_moderate', file_id=file.id) }}">{% trans %}Moderate{% endtrans %}</a></p>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -23,7 +23,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_root %} {% if user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID) 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>
@ -42,7 +42,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_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:refound_account') }}">{% trans %}Refound Account{% endtrans %}</a></li>
<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 %}
@ -62,10 +62,10 @@
<hr> <hr>
<h4>{% trans %}Communication{% endtrans %}</h4> <h4>{% trans %}Communication{% endtrans %}</h4>
<ul> <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> <li><a href="{{ url('core:file_moderation') }}">{% trans %}Moderate files{% endtrans %}</a></li>
{% endif %} {% 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> <li><a href="{{ url('sas:moderation') }}">{% trans %}Moderate pictures{% endtrans %}</a></li>
{% endif %} {% endif %}
</ul> </ul>

View File

@ -69,7 +69,7 @@ class AddFilesForm(forms.Form):
except Exception as e: except Exception as e:
self.add_error(None, _("Error uploading file %(file_name)s: %(msg)s") % {'file_name': f, 'msg': repr(e)}) self.add_error(None, _("Error uploading file %(file_name)s: %(msg)s") % {'file_name': f, 'msg': repr(e)})
if notif: 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(): if not u.notifications.filter(type="FILE_MODERATION").exists():
Notification(user=u, url=reverse("core:file_moderation"), type="FILE_MODERATION").save() Notification(user=u, url=reverse("core:file_moderation"), type="FILE_MODERATION").save()

View File

@ -165,7 +165,7 @@ class UserTabsMixin(TabedViewMixin):
}) })
try: try:
if (self.object.customer and (self.object == self.request.user 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_in_group(settings.SITH_BAR_MANAGER['unix_name']+settings.SITH_BOARD_SUFFIX)
or self.request.user.is_root)): or self.request.user.is_root)):
tab_list.append({ tab_list.append({
@ -417,7 +417,7 @@ class UserAccountBase(UserTabsMixin, DetailView):
def dispatch(self, request, *arg, **kwargs): # Manually validates the rights def dispatch(self, request, *arg, **kwargs): # Manually validates the rights
res = super(UserAccountBase, self).dispatch(request, *arg, **kwargs) res = super(UserAccountBase, 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_GROUP_ACCOUNTING_ADMIN_ID)
or request.user.is_in_group(settings.SITH_BAR_MANAGER['unix_name']+settings.SITH_BOARD_SUFFIX) or request.user.is_in_group(settings.SITH_BAR_MANAGER['unix_name']+settings.SITH_BOARD_SUFFIX)
or request.user.is_root): or request.user.is_root):
return res return res

View File

@ -79,7 +79,7 @@ class ProductType(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
return False return False
@ -117,7 +117,7 @@ class Product(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) or user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) or user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID):
return True return True
return False return False
@ -159,7 +159,7 @@ class Counter(models.Model):
mem = self.club.get_membership_for(user) mem = self.club.get_membership_for(user)
if mem and mem.role >= 7: if mem and mem.role >= 7:
return True return True
return user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID)
def can_be_viewed_by(self, user): def can_be_viewed_by(self, user):
if self.type == "BAR" or self.type == "EBOUTIC": if self.type == "BAR" or self.type == "EBOUTIC":
@ -464,7 +464,7 @@ class CashRegisterSummary(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']): if user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID):
return True return True
return False return False
@ -516,7 +516,7 @@ class Eticket(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
return user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID)
def get_hash(self, string): def get_hash(self, string):
import hashlib, hmac import hashlib, hmac

View File

@ -24,7 +24,7 @@ class Picture(SithFile):
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_SAS_ADMIN_GROUP_ID) return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID)
def can_be_viewed_by(self, user): def can_be_viewed_by(self, user):
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
@ -87,7 +87,7 @@ class Album(SithFile):
proxy = True proxy = True
def can_be_edited_by(self, user): def can_be_edited_by(self, user):
return user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID) return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID)
def can_be_viewed_by(self, user): def can_be_viewed_by(self, user):
print(self.is_in_sas) print(self.is_in_sas)

View File

@ -24,7 +24,7 @@
{{ a.name }} {{ a.name }}
</div> </div>
</a> </a>
{% elif user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID) %} {% elif user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) %}
<div style="display: inline-block; border: solid 1px red; text-align: center"> <div style="display: inline-block; border: solid 1px red; text-align: center">
<p><a href="{{ url('core:file_moderate', file_id=a.id) }}?next={{ url('sas:moderation') }}">Moderate</a> or <a href="">Delete</a></p> <p><a href="{{ url('core:file_moderate', file_id=a.id) }}?next={{ url('sas:moderation') }}">Moderate</a> or <a href="">Delete</a></p>
<a href="{{ url("sas:album", album_id=a.id) }}">{{ a.name }}</a> <a href="{{ url("sas:album", album_id=a.id) }}">{{ a.name }}</a>
@ -32,7 +32,7 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
{% if user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID) %} {% if user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) %}
<form action="" method="post" enctype="multipart/form-data"> <form action="" method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{{ form.non_field_errors() }} {{ form.non_field_errors() }}

View File

@ -62,7 +62,7 @@
{% for r in picture.people.all() %} {% for r in picture.people.all() %}
<li> <li>
<a href="{{ r.user.get_absolute_url() }}">{{ r.user.get_short_name() }}</a> <a href="{{ r.user.get_absolute_url() }}">{{ r.user.get_short_name() }}</a>
{% if user == r.user or user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID) %} {% if user == r.user or user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) %}
<a href="?remove_user={{ r.user.id }}">{% trans %}Delete{% endtrans %}</a> <a href="?remove_user={{ r.user.id }}">{% trans %}Delete{% endtrans %}</a>
{% endif %} {% endif %}
</li> </li>

View File

@ -49,7 +49,7 @@ class SASForm(forms.Form):
except Exception as e: except Exception as e:
self.add_error(None, _("Error uploading file %(file_name)s: %(msg)s") % {'file_name': f, 'msg': repr(e)}) self.add_error(None, _("Error uploading file %(file_name)s: %(msg)s") % {'file_name': f, 'msg': repr(e)})
if notif: 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="SAS_MODERATION").exists(): if not u.notifications.filter(type="SAS_MODERATION").exists():
Notification(user=u, url=reverse("sas:moderation"), type="SAS_MODERATION").save() Notification(user=u, url=reverse("sas:moderation"), type="SAS_MODERATION").save()
@ -70,7 +70,7 @@ class SASMainView(FormView):
parent = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first() parent = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first()
files = request.FILES.getlist('images') files = request.FILES.getlist('images')
root = User.objects.filter(username="root").first() root = User.objects.filter(username="root").first()
if request.user.is_authenticated() and request.user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID): if request.user.is_authenticated() and request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID):
if self.form.is_valid(): if self.form.is_valid():
self.form.process(parent=parent, owner=root, files=files, automodere=True) self.form.process(parent=parent, owner=root, files=files, automodere=True)
if self.form.is_valid(): if self.form.is_valid():
@ -103,7 +103,7 @@ class PictureView(CanViewMixin, DetailView, FormMixin):
if 'remove_user' in request.GET.keys(): if 'remove_user' in request.GET.keys():
try: try:
user = User.objects.filter(id=int(request.GET['remove_user'])).first() user = User.objects.filter(id=int(request.GET['remove_user'])).first()
if user.id == request.user.id or request.user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID): if user.id == request.user.id or request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID):
r = PeoplePictureRelation.objects.filter(user=user, picture=self.object).delete() r = PeoplePictureRelation.objects.filter(user=user, picture=self.object).delete()
except: pass except: pass
if 'ask_removal' in request.GET.keys(): if 'ask_removal' in request.GET.keys():
@ -164,7 +164,7 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
if request.user.is_authenticated() and request.user.is_in_group('ae-membres'): if request.user.is_authenticated() and request.user.is_in_group('ae-membres'):
if self.form.is_valid(): if self.form.is_valid():
self.form.process(parent=parent, owner=request.user, files=files, self.form.process(parent=parent, owner=request.user, files=files,
automodere=request.user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID)) automodere=request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID))
if self.form.is_valid(): if self.form.is_valid():
return super(AlbumView, self).form_valid(self.form) return super(AlbumView, self).form_valid(self.form)
else: else:
@ -185,7 +185,7 @@ class ModerationView(TemplateView):
template_name = "sas/moderation.jinja" template_name = "sas/moderation.jinja"
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if request.user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID): if request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID):
for k,v in request.GET.items(): for k,v in request.GET.items():
if k[:2] == "a_": if k[:2] == "a_":
try: try:

View File

@ -249,41 +249,17 @@ SITH_START_DATE = (8, 15) # 15th August
SITH_SCHOOL_START_YEAR = 1999 SITH_SCHOOL_START_YEAR = 1999
SITH_GROUP_ROOT_ID = 1 SITH_GROUP_ROOT_ID = 1
SITH_GROUP_PUBLIC_ID = 2
SITH_GROUP_ACCOUNTING_ADMIN_ID = 3
SITH_GROUP_COM_ADMIN_ID = 4
SITH_GROUP_COUNTER_ADMIN_ID = 5
SITH_GROUP_BANNED_ALCOHOL_ID = 6
SITH_GROUP_BANNED_COUNTER_ID = 7
SITH_GROUP_BANNED_SUBSCRIPTION_ID = 8
SITH_GROUP_SAS_ADMIN_ID = 9
SITH_GROUPS = { # SAS variables
'root': { SITH_SAS_ROOT_DIR_ID = 4
'id': 1,
'name': "Root",
},
'public': {
'id': 2,
'name': "Not registered users",
},
'accounting-admin': {
'id': 3,
'name': "Accounting admin",
},
'communication-admin': {
'id': 4,
'name': "Communication admin",
},
'counter-admin': {
'id': 5,
'name': "Counter admin",
},
'banned-alcohol': {
'id': 6,
'name': "Banned from buying alcohol",
},
'banned-from-counters': {
'id': 7,
'name': "Banned from counters",
},
'banned-to-subscribe': {
'id': 8,
'name': "Banned to subscribe",
}
}
SITH_BOARD_SUFFIX="-bureau" SITH_BOARD_SUFFIX="-bureau"
SITH_MEMBER_SUFFIX="-membres" SITH_MEMBER_SUFFIX="-membres"
@ -448,10 +424,6 @@ SITH_LAUNDERETTE_PRICES = {
'DRYING': 0.75, 'DRYING': 0.75,
} }
# SAS variables
SITH_SAS_ROOT_DIR_ID = 4
SITH_SAS_ADMIN_GROUP_ID = 9
SITH_NOTIFICATIONS = [ SITH_NOTIFICATIONS = [
('FILE_MODERATION', _("New files to be moderated")), ('FILE_MODERATION', _("New files to be moderated")),
('SAS_MODERATION', _("New pictures/album to be moderated in the SAS")), ('SAS_MODERATION', _("New pictures/album to be moderated in the SAS")),