Commit 1eb4dc18 authored by okhin's avatar okhin 🚴

Merge branch '30-lorsque-l-on-cree-les-groupes-ajouter-les-superusers-au-groupe-jedi' into 'rp2'

Resolve "Lorsque l'on créé les groupes, ajouter les superusers au groupe jedi"

Closes #30

See merge request !15
parents a85b9a07 6a5817ad
Pipeline #2503 passed with stages
in 3 minutes
......@@ -5,14 +5,18 @@ groups = ["droid", "jedi", "padawan"]
permissions = {
"droid": [],
"jedi": [
"can_change_status", "can_change_priority", "can_vote", "can_edit", "can_edit_users", "can_delete_users", "can_create_user",
"can_change_status", "can_change_priority", "can_vote", "can_edit",
"can_edit_users", "can_delete_users", "can_create_users",
],
"padawan": ["can_vote", "add_article"]
}
class Command(BaseCommand):
help = "Adds initial groups for the application (jedis and padawans). Existing user are promoted as padawans."
help = """
Adds initial groups for the application (jedis, droids and padawans).
Existing user are promoted as padawans and Superuser are promoted to jedi.
"""
def handle(self, *args, **options):
......@@ -24,4 +28,7 @@ class Command(BaseCommand):
users = User.objects.all()
for user in users:
user.groups.add(Group.objects.get(name="padawan"))
if user.is_superuser:
user.groups.add(Group.objects.get(name='jedi'))
else:
user.groups.add(Group.objects.get(name="padawan"))
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core import files
from django.core.files.base import ContentFile
from taggit.managers import TaggableManager
from newspaper import Article as ArticleParser
......@@ -10,9 +9,7 @@ from django_fsm import FSMField, transition, RETURN_VALUE
from io import BytesIO
from datetime import datetime
from tempfile import NamedTemporaryFile
from project.settings import env
from rp.utils import cleanup_url
......@@ -158,14 +155,15 @@ class Article(VoteMixin):
else:
return self.status
@transition(field=status, source='NEW', target='NEW', permission="rp.can_vote")
@transition(field=status, source='NEW', target='NEW',
permission="rp.can_vote")
@transition(field=status, source='DRAFT', target='DRAFT',
permission="rp.can_vote")
def downvote(self, by=None):
"""
Downvote the article score for the given user and remove previous votes.
Draft articles can be downvoted but will not be moved back in the
_NEW_ queue.
Downvote the article score for the given user and remove previous
votes. Draft articles can be downvoted but will not be moved back in
the _NEW_ queue.
"""
super(Article, self).downvote(by)
......
......@@ -23,7 +23,8 @@ class UserProfileInline(admin.StackedInline):
class UserProfileAdmin(UserAdmin):
inlines = [UserProfileInline]
list_display = ("username", "email", "first_name", "last_name", "is_staff", "get_groups")
list_display = ("username", "email", "first_name", "last_name",
"is_staff", "get_groups")
fieldsets = (
(None, {"fields": ("username", "password")}),
......@@ -36,5 +37,6 @@ class UserProfileAdmin(UserAdmin):
return ", ".join(sorted([g.name for g in obj.groups.all()]))
get_groups.short_description = _("Groups")
admin.site.unregister(User)
admin.site.register(User, UserProfileAdmin)
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2019-03-13 16:28
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('userprofile', '0003_auto_20180109_1642'),
]
operations = [
migrations.AlterModelOptions(
name='profile',
options={'permissions': (('can_edit_users', 'Can edit users'), ('can_delete_users', 'Can delete users'), ('can_create_users', 'Can create users')), 'verbose_name': 'User'},
),
]
......@@ -42,6 +42,7 @@ class Profile(models.Model):
permissions = (
("can_edit_users", "Can edit users",),
("can_delete_users", "Can delete users",),
("can_create_users", "Can create users",),
)
def __str__(self):
......
......@@ -6,6 +6,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMix
from django.views.generic.list import ListView
from django.views.generic.edit import DeleteView, UpdateView
class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
model = User
paginate_by = 20
......@@ -22,6 +23,7 @@ class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
return context
class UserEditView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
model = User
permission_required = 'userprofile.can_edit_users'
......@@ -31,6 +33,7 @@ class UserEditView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
fields = ['groups']
success_url = reverse_lazy("users:list")
class UserDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteView):
model = User
permission_required = 'userprofile.can_delete_users'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment