From 3f2b21f7f43ea88c50be5d1aeb605c6f6b6ac209 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 20 Mar 2020 02:14:43 +0100 Subject: [PATCH] Fix CI --- apps/activity/api/views.py | 2 +- apps/api/urls.py | 1 - apps/api/viewsets.py | 1 - apps/logs/api/views.py | 2 +- apps/logs/signals.py | 4 +--- apps/member/api/views.py | 2 +- apps/member/backends.py | 7 ++----- apps/member/forms.py | 2 +- apps/member/models.py | 12 +----------- apps/member/views.py | 2 +- apps/note/api/serializers.py | 5 ----- apps/note/api/views.py | 2 +- apps/note/views.py | 14 +++++++------- 13 files changed, 17 insertions(+), 39 deletions(-) diff --git a/apps/activity/api/views.py b/apps/activity/api/views.py index 651560fd..76b2b333 100644 --- a/apps/activity/api/views.py +++ b/apps/activity/api/views.py @@ -3,8 +3,8 @@ from django_filters.rest_framework import DjangoFilterBackend from rest_framework.filters import SearchFilter - from api.viewsets import ReadProtectedModelViewSet + from .serializers import ActivityTypeSerializer, ActivitySerializer, GuestSerializer from ..models import ActivityType, Activity, Guest diff --git a/apps/api/urls.py b/apps/api/urls.py index 40e6c572..b275a0b8 100644 --- a/apps/api/urls.py +++ b/apps/api/urls.py @@ -8,7 +8,6 @@ from django_filters.rest_framework import DjangoFilterBackend from rest_framework import routers, serializers from rest_framework.filters import SearchFilter from rest_framework.viewsets import ReadOnlyModelViewSet - from activity.api.urls import register_activity_urls from api.viewsets import ReadProtectedModelViewSet from member.api.urls import register_members_urls diff --git a/apps/api/viewsets.py b/apps/api/viewsets.py index c700339f..5380489d 100644 --- a/apps/api/viewsets.py +++ b/apps/api/viewsets.py @@ -4,7 +4,6 @@ from django.contrib.contenttypes.models import ContentType from member.backends import PermissionBackend from rest_framework import viewsets - from note_kfet.middlewares import get_current_authenticated_user diff --git a/apps/logs/api/views.py b/apps/logs/api/views.py index 6bd4f721..b3b9b166 100644 --- a/apps/logs/api/views.py +++ b/apps/logs/api/views.py @@ -3,8 +3,8 @@ from django_filters.rest_framework import DjangoFilterBackend from rest_framework.filters import OrderingFilter - from api.viewsets import ReadOnlyProtectedModelViewSet + from .serializers import ChangelogSerializer from ..models import Changelog diff --git a/apps/logs/signals.py b/apps/logs/signals.py index 0c80a4cd..a7cf9a47 100644 --- a/apps/logs/signals.py +++ b/apps/logs/signals.py @@ -4,12 +4,10 @@ from django.contrib.contenttypes.models import ContentType from rest_framework.renderers import JSONRenderer from rest_framework.serializers import ModelSerializer - import getpass - from note.models import NoteUser, Alias - from note_kfet.middlewares import get_current_authenticated_user, get_current_ip + from .models import Changelog diff --git a/apps/member/api/views.py b/apps/member/api/views.py index b4715cae..57c216a1 100644 --- a/apps/member/api/views.py +++ b/apps/member/api/views.py @@ -2,8 +2,8 @@ # SPDX-License-Identifier: GPL-3.0-or-later from rest_framework.filters import SearchFilter - from api.viewsets import ReadProtectedModelViewSet + from .serializers import ProfileSerializer, ClubSerializer, RoleSerializer, MembershipSerializer from ..models import Profile, Club, Role, Membership diff --git a/apps/member/backends.py b/apps/member/backends.py index 90dc70f8..b0e026f8 100644 --- a/apps/member/backends.py +++ b/apps/member/backends.py @@ -1,15 +1,15 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later +from django.contrib.auth.backends import ModelBackend from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.db.models import Q, F - from note.models import Note, NoteUser, NoteClub, NoteSpecial from note_kfet.middlewares import get_current_session from permission.models import Permission + from .models import Membership, Club -from django.contrib.auth.backends import ModelBackend class PermissionBackend(ModelBackend): @@ -53,9 +53,6 @@ class PermissionBackend(ModelBackend): :return: A query that corresponds to the filter to give to a queryset """ - from time import time - ti = time() - if user.is_superuser and get_current_session().get("permission_mask", 0) >= 42: # Superusers have all rights return Q() diff --git a/apps/member/forms.py b/apps/member/forms.py index 0f1ff189..5f2d5838 100644 --- a/apps/member/forms.py +++ b/apps/member/forms.py @@ -8,8 +8,8 @@ from dal import autocomplete from django import forms from django.contrib.auth.forms import UserCreationForm, AuthenticationForm from django.contrib.auth.models import User - from permission.models import PermissionMask + from .models import Profile, Club, Membership diff --git a/apps/member/models.py b/apps/member/models.py index 1a9bcee2..c22d37d4 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -54,7 +54,6 @@ class Profile(models.Model): return reverse('user_detail', args=(self.pk,)) - class Club(models.Model): """ A club is a group of people, whose membership is handle by their @@ -164,6 +163,7 @@ class Membership(models.Model): verbose_name_plural = _('memberships') indexes = [models.Index(fields=['user'])] + class RolePermissions(models.Model): """ Permissions associated with a Role @@ -180,13 +180,3 @@ class RolePermissions(models.Model): def __str__(self): return str(self.role) - - -# @receiver(post_save, sender=settings.AUTH_USER_MODEL) -# def save_user_profile(instance, created, **_kwargs): -# """ -# Hook to save an user profile when an user is updated -# """ -# if created: -# Profile.objects.create(user=instance) -# instance.profile.save() diff --git a/apps/member/views.py b/apps/member/views.py index 3b19503b..8e4fff08 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -24,8 +24,8 @@ from note.forms import AliasForm, ImageForm from note.models import Alias, NoteUser from note.models.transactions import Transaction from note.tables import HistoryTable, AliasTable -from .backends import PermissionBackend +from .backends import PermissionBackend from .filters import UserFilter, UserFilterFormHelper from .forms import SignUpForm, ProfileForm, ClubForm, MembershipForm, MemberFormSet, FormSetHelper, \ CustomAuthenticationForm diff --git a/apps/note/api/serializers.py b/apps/note/api/serializers.py index 5e82c89e..528f8810 100644 --- a/apps/note/api/serializers.py +++ b/apps/note/api/serializers.py @@ -4,8 +4,6 @@ from rest_framework import serializers from rest_polymorphic.serializers import PolymorphicSerializer -from member.backends import PermissionBackend -from note_kfet.middlewares import get_current_authenticated_user from ..models.notes import Note, NoteClub, NoteSpecial, NoteUser, Alias from ..models.transactions import TransactionTemplate, Transaction, MembershipTransaction, TemplateCategory, \ RecurrentTransaction, SpecialTransaction @@ -83,9 +81,6 @@ class AliasSerializer(serializers.ModelSerializer): fields = '__all__' read_only_fields = ('note', ) - def get_note(self, alias): - return alias.note.id - class NotePolymorphicSerializer(PolymorphicSerializer): model_serializer_mapping = { diff --git a/apps/note/api/views.py b/apps/note/api/views.py index f4bf5668..eaf6cd37 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -4,8 +4,8 @@ from django.db.models import Q from django_filters.rest_framework import DjangoFilterBackend from rest_framework.filters import OrderingFilter, SearchFilter - from api.viewsets import ReadProtectedModelViewSet, ReadOnlyProtectedModelViewSet + from .serializers import NotePolymorphicSerializer, AliasSerializer, TemplateCategorySerializer, \ TransactionTemplateSerializer, TransactionPolymorphicSerializer from ..models.notes import Note, Alias diff --git a/apps/note/views.py b/apps/note/views.py index c9905dd2..0b940666 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -8,8 +8,8 @@ from django.db.models import Q from django.utils.translation import gettext_lazy as _ from django.views.generic import CreateView, ListView, UpdateView from django_tables2 import SingleTableView - from member.backends import PermissionBackend + from .forms import TransactionTemplateForm from .models import Transaction, TransactionTemplate, Alias, RecurrentTransaction, NoteSpecial from .models.transactions import SpecialTransaction @@ -27,9 +27,9 @@ class TransactionCreate(LoginRequiredMixin, SingleTableView): table_pagination = {"per_page": 50} def get_queryset(self): - return Transaction.objects.filter(PermissionBackend - .filter_queryset(self.request.user, Transaction, "view")) \ - .order_by("-id").all()[:50] + return Transaction.objects.filter(PermissionBackend.filter_queryset( + self.request.user, Transaction, "view") + ).order_by("-id").all()[:50] def get_context_data(self, **kwargs): """ @@ -137,9 +137,9 @@ class ConsoView(LoginRequiredMixin, SingleTableView): """ context = super().get_context_data(**kwargs) from django.db.models import Count - buttons = TransactionTemplate.objects.filter(PermissionBackend() - .filter_queryset(self.request.user, TransactionTemplate, "view")) \ - .filter(display=True).annotate(clicks=Count('recurrenttransaction')).order_by('category__name', 'name') + buttons = TransactionTemplate.objects.filter( + PermissionBackend().filter_queryset(self.request.user, TransactionTemplate, "view") + ).filter(display=True).annotate(clicks=Count('recurrenttransaction')).order_by('category__name', 'name') context['transaction_templates'] = buttons context['most_used'] = buttons.order_by('-clicks', 'name')[:10] context['title'] = _("Consumptions")