diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 85ff02ad..c29748f5 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -17,17 +17,26 @@ class Command(BaseCommand): def handle(self, *args, **options): root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) - u = User(username='root', last_name="", first_name="Bibou", + root = User(username='root', last_name="", first_name="Bibou", email="ae.info@utbm.fr", date_of_birth="1942-06-12", is_superuser=True, is_staff=True) - u.set_password("plop") - u.save() + root.set_password("plop") + root.save() for g in settings.AE_GROUPS.values(): Group(id=g['id'], name=g['name']).save() ae = Club(name=settings.AE_MAIN_CLUB['name'], unix_name=settings.AE_MAIN_CLUB['unix_name'], address=settings.AE_MAIN_CLUB['address']) ae.save() + p = Page(name='Index') + p.set_lock(root) + p.save() + p.view_groups=[settings.AE_GROUPS['public']['id']] + p.set_lock(root) + p.save() + PageRev(page=p, title="Wiki index", author=root, content=""" +Welcome to the wiki page! +""").save() # Here we add a lot of test datas, that are not necessary for the Sith, but that provide a basic development environment if not options['prod']: @@ -53,14 +62,12 @@ class Command(BaseCommand): r.save() # Adding syntax help page p = Page(name='Aide_sur_la_syntaxe') - p.set_lock(s) p.save() PageRev(page=p, title="Aide sur la syntaxe", author=s, content=""" Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. """).save() # Adding README p = Page(name='README') - p.set_lock(s) p.save() p.view_groups=[settings.AE_GROUPS['public']['id']] p.set_lock(s) diff --git a/core/models.py b/core/models.py index 611d8732..31eacd3e 100644 --- a/core/models.py +++ b/core/models.py @@ -98,6 +98,18 @@ class User(AbstractBaseUser, PermissionsMixin): def is_in_group(self, group_name): """If the user is in the group passed in argument (as string)""" + if group_name == settings.AE_GROUPS['public']['name']: + return True + if group_name == settings.AE_GROUPS['members']['name']: # We check the subscription if asked + try: + from subscription import Subscriber + s = Subscriber.objects.filter(pk=self.pk).first() + if s is not None and s.is_subscribed(): + return True + else: + return False + except Exception as e: + print(e) return self.groups.filter(name=group_name).exists() def get_profile(self): @@ -159,7 +171,7 @@ class User(AbstractBaseUser, PermissionsMixin): """ if not hasattr(obj, "owner_group"): return False - if (self.is_superuser or self.groups.filter(name=obj.owner_group.name).exists() or + if (self.is_superuser or self.is_in_group(obj.owner_group.name) or self.has_perm(obj.__class__.__module__.split('.')[0]+".change_prop_"+obj.__class__.__name__.lower()) or self.groups.filter(id=settings.AE_GROUPS['root']['id']).exists()): return True @@ -175,7 +187,7 @@ class User(AbstractBaseUser, PermissionsMixin): return True if hasattr(obj, "edit_groups"): for g in obj.edit_groups.all(): - if self.groups.filter(name=g.name).exists(): + if self.is_in_group(g.name): return True if isinstance(obj, User) and obj == self: return True @@ -193,7 +205,7 @@ class User(AbstractBaseUser, PermissionsMixin): return True if hasattr(obj, "view_groups"): for g in obj.view_groups.all(): - if self.groups.filter(name=g.name).exists(): + if self.is_in_group(g.name): return True if hasattr(obj, "can_be_viewed_by") and obj.can_be_viewed_by(self): return True diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index 65ad7173..d4dc4711 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -25,7 +25,7 @@
{% endif %} diff --git a/core/templates/core/user_detail.jinja b/core/templates/core/user_detail.jinja index 8f16ba75..0bd63a55 100644 --- a/core/templates/core/user_detail.jinja +++ b/core/templates/core/user_detail.jinja @@ -12,10 +12,10 @@ {% if request.user.id == profile.id %}