Commit 031be094 authored by Lo-J's avatar Lo-J

merging

parents c7d17b52 7b6d858b
Pipeline #658 failed with stage
in 2 minutes and 18 seconds
......@@ -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
......
......@@ -8,7 +8,6 @@ from django.core.urlresolvers import reverse
from django.utils import timezone
from core.models import User, MetaGroup, Group, SithFile
from subscription.models import Subscriber
# Create your models here.
......@@ -33,7 +32,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,
......@@ -120,7 +119,7 @@ class Club(models.Model):
"""
Method to see if that object can be seen by the given user
"""
sub = Subscriber.objects.filter(pk=user.pk).first()
sub = User.objects.filter(pk=user.pk).first()
if sub is None:
return False
return sub.is_subscribed()
......@@ -151,7 +150,7 @@ class Membership(models.Model):
description = models.CharField(_('description'), max_length=128, null=False, blank=True)
def clean(self):
sub = Subscriber.objects.filter(pk=self.user.pk).first()
sub = User.objects.filter(pk=self.user.pk).first()
if sub is None or not sub.is_subscribed():
raise ValidationError(_('User must be subscriber to take part to a club'))
if Membership.objects.filter(user=self.user).filter(club=self.club).filter(end_date=None).exists():
......
......@@ -12,7 +12,7 @@ from django.contrib.sites.models import Site
from core.models import Group, User, Page, PageRev, SithFile
from accounting.models import GeneralJournal, BankAccount, ClubAccount, Operation, AccountingType, Company
from club.models import Club, Membership
from subscription.models import Subscription, Subscriber
from subscription.models import Subscription
from counter.models import Customer, ProductType, Product, Counter
class Command(BaseCommand):
......@@ -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,14 +194,14 @@ 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()
# Subscription
## Root
s = Subscription(member=Subscriber.objects.filter(pk=root.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
s = Subscription(member=User.objects.filter(pk=root.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end(
......@@ -203,7 +209,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
start=s.subscription_start)
s.save()
## Skia
s = Subscription(member=Subscriber.objects.filter(pk=skia.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
s = Subscription(member=User.objects.filter(pk=skia.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end(
......@@ -211,7 +217,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
start=s.subscription_start)
s.save()
## Comptable
s = Subscription(member=Subscriber.objects.filter(pk=comptable.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
s = Subscription(member=User.objects.filter(pk=comptable.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end(
......@@ -219,15 +225,15 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
start=s.subscription_start)
s.save()
## Richard
s = Subscription(member=Subscriber.objects.filter(pk=r.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
s = Subscription(member=User.objects.filter(pk=r.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end(
duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'],
start=s.subscription_start)
s.save()
## Subscriber
s = Subscription(member=Subscriber.objects.filter(pk=subscriber.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
## User
s = Subscription(member=User.objects.filter(pk=subscriber.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end(
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('core', '0011_auto_20161124_0848'),
]
operations = [
migrations.CreateModel(
name='Notification',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('url', models.CharField(max_length=255, verbose_name='url')),
('text', models.CharField(max_length=512, verbose_name='text')),
('type', models.CharField(max_length=16, choices=[('FILE_MODERATION', 'File moderation'), ('SAS_MODERATION', 'SAS moderation'), ('NEW_PICTURES', 'New pictures')], verbose_name='text', null=True, blank=True)),
('date', models.DateTimeField(verbose_name='date', default=django.utils.timezone.now)),
('user', models.ForeignKey(related_name='notifications', to=settings.AUTH_USER_MODEL)),
],
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0012_notification'),
]
operations = [
migrations.RemoveField(
model_name='notification',
name='text',
),
migrations.AddField(
model_name='notification',
name='param',
field=models.CharField(verbose_name='param', default='', max_length=128),
),
migrations.AddField(
model_name='notification',
name='viewed',
field=models.BooleanField(verbose_name='viewed', default=False),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0013_auto_20161209_2338'),
]
operations = [
migrations.AlterField(
model_name='notification',
name='type',
field=models.CharField(verbose_name='type', max_length=32, default='GENERIC', choices=[('FILE_MODERATION', 'New files to be moderated'), ('SAS_MODERATION', 'New pictures/album to be moderated in the SAS'), ('NEW_PICTURES', "You've been identified on some pictures"), ('REFILLING', 'You just refilled of %s €'), ('SELLING', 'You just bought %s'), ('GENERIC', 'You have a notification')]),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('core', '0014_auto_20161210_0009'),
]
operations = [
migrations.AddField(
model_name='sithfile',
name='moderator',
field=models.ForeignKey(related_name='moderated_files', verbose_name='owner', default=0, to=settings.AUTH_USER_MODEL),
preserve_default=False,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('core', '0015_sithfile_moderator'),
]
operations = [
migrations.AlterField(
model_name='sithfile',
name='moderator',
field=models.ForeignKey(related_name='moderated_files', blank=True, null=True, to=settings.AUTH_USER_MODEL, verbose_name='owner'),
),
]
......@@ -182,26 +182,30 @@ class User(AbstractBaseUser):
def to_dict(self):
return self.__dict__
def was_subscribed(self):
return self.subscriptions.exists()
def is_subscribed(self):
s = self.subscriptions.last()
return s.is_valid_now() if s is not None else False
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
g = None
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
else:
return False
if group_name == settings.SITH_GROUPS['public']['name']:
else:
g = Group.objects.filter(name=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
if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked
if 'subscription' in settings.INSTALLED_APPS:
from subscription.models import Subscriber
s = Subscriber.objects.filter(pk=self.pk).first()
if s is not None and s.is_subscribed():
return True
else:
return False
else:
return False
return self.is_subscribed()
if group_name[-len(settings.SITH_BOARD_SUFFIX):] == settings.SITH_BOARD_SUFFIX:
from club.models import Club
name = group_name[:-len(settings.SITH_BOARD_SUFFIX)]
......@@ -218,13 +222,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):
......@@ -238,11 +242,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
......@@ -360,7 +364,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
......@@ -422,6 +426,9 @@ class AnonymousUser(AuthAnonymousUser):
def __init__(self, request):
super(AnonymousUser, self).__init__()
def was_subscribed(self):
return False
@property
def subscribed(self):
return False
......@@ -450,7 +457,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
......@@ -461,7 +476,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
......@@ -501,8 +516,9 @@ class SithFile(models.Model):
size = models.IntegerField(_("size"), default=0)
date = models.DateTimeField(_('date'), default=timezone.now)
is_moderated = models.BooleanField(_("is moderated"), default=False)
moderator = models.ForeignKey(User, related_name="moderated_files", verbose_name=_("owner"), null=True, blank=True)
asked_for_removal = models.BooleanField(_("asked for removal"), default=False)
is_in_sas = models.BooleanField(_("is in the SAS"), default=False)
is_in_sas = models.BooleanField(_("is in the SAS"), default=False) # Allows to query this flag, updated at each call to save()
class Meta:
verbose_name = _("file")
......@@ -510,7 +526,9 @@ 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
if self.is_in_sas and user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID):
return True
return user.id == self.owner.id
......@@ -588,6 +606,27 @@ class SithFile(models.Model):
self.view_groups = self.parent.view_groups.all()
self.save()
def move_to(self, parent):
"""Move a file to somewhere else"""
if not parent.is_folder:
return
import shutil
import os
with transaction.atomic():
if self.is_folder:
old_file_name = self.get_full_path()
else:
old_file_name = self.file.name
self.parent = parent
self.save()
if self.is_folder:
for c in self.children.all():
c.move_to(self)
shutil.rmtree(settings.MEDIA_ROOT + old_file_name)
else:
self.file.save(name=self.name, content=self.file)
os.remove(settings.MEDIA_ROOT + old_file_name)
def __getattribute__(self, attr):
if attr == "is_file":
return not self.is_folder
......@@ -599,6 +638,11 @@ class SithFile(models.Model):
from sas.models import Picture
return Picture.objects.filter(id=self.id).first()
@property
def as_album(self):
from sas.models import Album
return Album.objects.filter(id=self.id).first()
def __str__(self):
if self.is_folder:
return _("Folder: ") + self.name
......@@ -616,6 +660,9 @@ class SithFile(models.Model):
def get_parent_path(self):
return '/' + '/'.join([p.name for p in self.get_parent_list()[::-1]])
def get_full_path(self):
return self.get_parent_path() + '/' + self.name
def get_display_name(self):
return self.name
......@@ -654,7 +701,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'])