mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
Refactor group settings
This commit is contained in:
parent
1649d14518
commit
0d4b697079
@ -68,7 +68,7 @@ class BankAccount(models.Model):
|
||||
"""
|
||||
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
|
||||
m = self.club.get_membership_for(user)
|
||||
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
|
||||
"""
|
||||
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 False
|
||||
|
||||
@ -155,7 +155,7 @@ class GeneralJournal(models.Model):
|
||||
"""
|
||||
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
|
||||
if self.club_account.can_be_edited_by(user):
|
||||
return True
|
||||
@ -260,7 +260,7 @@ class Operation(models.Model):
|
||||
"""
|
||||
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
|
||||
if self.journal.closed:
|
||||
return False
|
||||
@ -308,7 +308,7 @@ class AccountingType(models.Model):
|
||||
"""
|
||||
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 False
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
<h4>
|
||||
{% trans %}Accounting{% endtrans %}
|
||||
</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:type_list') }}">{% trans %}Manage accounting types{% endtrans %}</a></p>
|
||||
<p><a href="{{ url('accounting:bank_new') }}">{% trans %}New bank account{% endtrans %}</a></p>
|
||||
|
@ -367,11 +367,11 @@ class OperationPDFView(CanViewMixin, DetailView):
|
||||
im = ImageReader("core/static/core/img/logo.jpg")
|
||||
iw, ih = im.getSize()
|
||||
p.drawImage(im, 40, height - 50, width=iw/2, height=ih/2)
|
||||
|
||||
|
||||
labelStr = [["%s %s - %s %s" % (_("Journal"), ti, _("Operation"), num)]]
|
||||
|
||||
label = Table(labelStr, colWidths=[150], rowHeights=[20])
|
||||
|
||||
|
||||
label.setStyle(TableStyle([
|
||||
('ALIGN',(0,0),(-1,-1),'CENTER'),
|
||||
('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 ""})
|
||||
|
||||
data = []
|
||||
|
||||
|
||||
data += [["%s" % (_("Credit").upper() if nature == 'CREDIT' else _("Debit").upper())]]
|
||||
|
||||
data += [[_("Amount: %(amount).2f €") % {"amount": amount}]]
|
||||
|
||||
|
||||
payment_mode = ""
|
||||
for m in settings.SITH_ACCOUNTING_PAYMENT_METHOD:
|
||||
if m[0] == mode:
|
||||
@ -398,11 +398,11 @@ class OperationPDFView(CanViewMixin, DetailView):
|
||||
payment_mode += " %s\n" %(m[1])
|
||||
|
||||
data += [[payment_mode]]
|
||||
|
||||
|
||||
data += [["%s : %s" % (_("Debtor") if nature == 'CREDIT' else _("Creditor"), target), ""]]
|
||||
|
||||
data += [["%s \n%s" % (_("Comment:"), remark)]]
|
||||
|
||||
|
||||
t = Table(data, colWidths=[(width-90*2)/2]*2, rowHeights=[20, 20, 70, 20, 80])
|
||||
t.setStyle(TableStyle([
|
||||
('ALIGN',(0,0),(-1,-1),'CENTER'),
|
||||
@ -498,7 +498,7 @@ class RefoundAccountView(FormView):
|
||||
form_class = CloseCustomerAccountForm
|
||||
|
||||
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
|
||||
else:
|
||||
raise PermissionDenied
|
||||
|
@ -33,7 +33,7 @@ class Club(models.Model):
|
||||
address = models.CharField(_('address'), max_length=254)
|
||||
# email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically
|
||||
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)
|
||||
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,
|
||||
|
@ -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
|
||||
|
@ -79,7 +79,7 @@ class ProductType(models.Model):
|
||||
"""
|
||||
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 False
|
||||
|
||||
@ -117,7 +117,7 @@ class Product(models.Model):
|
||||
"""
|
||||
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 False
|
||||
|
||||
@ -159,7 +159,7 @@ class Counter(models.Model):
|
||||
mem = self.club.get_membership_for(user)
|
||||
if mem and mem.role >= 7:
|
||||
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):
|
||||
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
|
||||
"""
|
||||
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 False
|
||||
|
||||
@ -516,7 +516,7 @@ class Eticket(models.Model):
|
||||
"""
|
||||
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):
|
||||
import hashlib, hmac
|
||||
|
@ -24,7 +24,7 @@ class Picture(SithFile):
|
||||
return False
|
||||
|
||||
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):
|
||||
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
|
||||
|
||||
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):
|
||||
print(self.is_in_sas)
|
||||
|
@ -24,7 +24,7 @@
|
||||
{{ a.name }}
|
||||
</div>
|
||||
</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">
|
||||
<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>
|
||||
@ -32,7 +32,7 @@
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</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">
|
||||
{% csrf_token %}
|
||||
{{ form.non_field_errors() }}
|
||||
|
@ -62,7 +62,7 @@
|
||||
{% for r in picture.people.all() %}
|
||||
<li>
|
||||
<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>
|
||||
{% endif %}
|
||||
</li>
|
||||
|
10
sas/views.py
10
sas/views.py
@ -49,7 +49,7 @@ class SASForm(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="SAS_MODERATION").exists():
|
||||
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()
|
||||
files = request.FILES.getlist('images')
|
||||
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():
|
||||
self.form.process(parent=parent, owner=root, files=files, automodere=True)
|
||||
if self.form.is_valid():
|
||||
@ -103,7 +103,7 @@ class PictureView(CanViewMixin, DetailView, FormMixin):
|
||||
if 'remove_user' in request.GET.keys():
|
||||
try:
|
||||
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()
|
||||
except: pass
|
||||
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 self.form.is_valid():
|
||||
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():
|
||||
return super(AlbumView, self).form_valid(self.form)
|
||||
else:
|
||||
@ -185,7 +185,7 @@ class ModerationView(TemplateView):
|
||||
template_name = "sas/moderation.jinja"
|
||||
|
||||
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():
|
||||
if k[:2] == "a_":
|
||||
try:
|
||||
|
@ -249,41 +249,17 @@ SITH_START_DATE = (8, 15) # 15th August
|
||||
SITH_SCHOOL_START_YEAR = 1999
|
||||
|
||||
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 = {
|
||||
'root': {
|
||||
'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",
|
||||
}
|
||||
}
|
||||
# SAS variables
|
||||
SITH_SAS_ROOT_DIR_ID = 4
|
||||
|
||||
SITH_BOARD_SUFFIX="-bureau"
|
||||
SITH_MEMBER_SUFFIX="-membres"
|
||||
@ -448,10 +424,6 @@ SITH_LAUNDERETTE_PRICES = {
|
||||
'DRYING': 0.75,
|
||||
}
|
||||
|
||||
# SAS variables
|
||||
SITH_SAS_ROOT_DIR_ID = 4
|
||||
SITH_SAS_ADMIN_GROUP_ID = 9
|
||||
|
||||
SITH_NOTIFICATIONS = [
|
||||
('FILE_MODERATION', _("New files to be moderated")),
|
||||
('SAS_MODERATION', _("New pictures/album to be moderated in the SAS")),
|
||||
|
Loading…
Reference in New Issue
Block a user