1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-12-24 17:42:23 +00:00

Sporz permissions

This commit is contained in:
Alexandre Iooss 2019-08-16 15:05:10 +02:00
parent b41fe3525b
commit fa94ac7689
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
3 changed files with 71 additions and 39 deletions

View File

@ -39,44 +39,53 @@ FLUSH PRIVILEGES;
```
bureau
Can view borrowed item
Can add borrowed item
Can change borrowed item
Can delete borrowed item
Can view adhesion
Can add adhesion
Can change adhesion
Can delete adhesion
Can view clef
Can add clef
Can change clef
Can delete clef
Can view user
Can add user
Can change user
media | Can view borrowed item
media | Can add borrowed item
media | Can change borrowed item
media | Can delete borrowed item
users | Can view adhesion
users | Can add adhesion
users | Can change adhesion
users | Can delete adhesion
users | Can view clef
users | Can add clef
users | Can change clef
users | Can delete clef
users | Can view user
users | Can add user
users | Can change user
sporz | Can view gamesave
+ permissions keyholder
keyholder
Can view auteur
Can add auteur
Can change auteur
Can delete auteur
Can view media
Can add media
Can change media
Can delete media
Can view jeu
Can add jeu
Can change jeu
Can delete jeu
Can view emprunt
Can add emprunt
Can change emprunt
Can delete emprunt
Can view user
Can view clef
media | Can view auteur
media | Can add auteur
media | Can change auteur
media | Can delete auteur
media | Can view media
media | Can add media
media | Can change media
media | Can delete media
media | Can view jeu
media | Can add jeu
media | Can change jeu
media | Can delete jeu
media | Can view emprunt
media | Can add emprunt
media | Can change emprunt
media | Can delete emprunt
users | Can view user
users | Can view clef
users
Can view auteur
Can view media
Can view jeu
users (default group for everyone)
media | Can view auteur
media | Can view media
media | Can view jeu
sporz | Can add gamesave
sporz | Can change gamesave
sporz | Can delete gamesave
sporz | Can view player
sporz | Can add player
sporz | Can change player
sporz | Can delete player
```

2
TODO
View File

@ -1,2 +0,0 @@
régler pq de permission sur app sporz : permettre d'afficher seulement nos gamesave à tout le monde

View File

@ -3,6 +3,8 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.db.models import Q
from med.admin import admin_site
from .models import GameSave, Player
@ -16,6 +18,7 @@ class GameSaveAdmin(admin.ModelAdmin):
inlines = [PlayerInline, ]
list_display = ('__str__', 'game_master', 'game_has_ended')
date_hierarchy = 'created_at'
autocomplete_fields = ('game_master',)
def has_change_permission(self, request, obj=None):
"""
@ -43,5 +46,27 @@ class GameSaveAdmin(admin.ModelAdmin):
request.GET = data
return super().add_view(request, form_url, extra_context)
def formfield_for_foreignkey(self, db_field, request, **kwargs):
"""
Authorize game master change only if user can see all users
"""
if db_field.name == 'game_master':
if not request.user.has_perm('users.view_user'):
kwargs['queryset'] = get_user_model().objects.filter(
username=request.user.username)
return super().formfield_for_foreignkey(db_field, request, **kwargs)
def get_queryset(self, request):
"""
List all game save only if user has view permission
else, list only own games and ended games
"""
queryset = super().get_queryset(request)
if request.user.has_perm('sporz.view_gamesave'):
return queryset
return queryset.filter(
Q(game_master=request.user) | Q(game_has_ended=True)
)
admin_site.register(GameSave, GameSaveAdmin)