forked from DGNum/gestioCOF
Merge branch 'aureplop/clean_perms' into 'master'
Clean K-Fêt permissions See merge request !235
This commit is contained in:
commit
92c946a286
2 changed files with 113 additions and 21 deletions
81
kfet/migrations/0055_move_permissions.py
Normal file
81
kfet/migrations/0055_move_permissions.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def forwards_perms(apps, schema_editor):
|
||||
"""Safely delete content type for old kfet.GlobalPermissions model.
|
||||
|
||||
Any permissions (except defaults) linked to this content type are updated
|
||||
to link at its new content type.
|
||||
Then, delete the content type. This will delete the three defaults
|
||||
permissions which are assumed unused.
|
||||
|
||||
"""
|
||||
ContentType = apps.get_model('contenttypes', 'contenttype')
|
||||
try:
|
||||
ctype_global = ContentType.objects.get(
|
||||
app_label="kfet", model="globalpermissions",
|
||||
)
|
||||
except ContentType.DoesNotExist:
|
||||
# We are not migrating from existing data, nothing to do.
|
||||
return
|
||||
|
||||
perms = {
|
||||
'account': (
|
||||
'is_team', 'manage_perms', 'manage_addcosts',
|
||||
'edit_balance_account', 'change_account_password',
|
||||
'special_add_account',
|
||||
),
|
||||
'accountnegative': ('view_negs',),
|
||||
'inventory': ('order_to_inventory',),
|
||||
'operation': (
|
||||
'perform_deposit', 'perform_negative_operations',
|
||||
'override_frozen_protection', 'cancel_old_operations',
|
||||
'perform_commented_operations',
|
||||
),
|
||||
}
|
||||
|
||||
Permission = apps.get_model('auth', 'permission')
|
||||
global_perms = Permission.objects.filter(content_type=ctype_global)
|
||||
|
||||
for modelname, codenames in perms.items():
|
||||
model = apps.get_model('kfet', modelname)
|
||||
ctype = ContentType.objects.get_for_model(model)
|
||||
(
|
||||
global_perms
|
||||
.filter(codename__in=codenames)
|
||||
.update(content_type=ctype)
|
||||
)
|
||||
|
||||
ctype_global.delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('kfet', '0054_delete_settings'),
|
||||
('contenttypes', '__latest__'),
|
||||
('auth', '__latest__'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='account',
|
||||
options={'permissions': (('is_team', 'Is part of the team'), ('manage_perms', 'Gérer les permissions K-Fêt'), ('manage_addcosts', 'Gérer les majorations'), ('edit_balance_account', "Modifier la balance d'un compte"), ('change_account_password', "Modifier le mot de passe d'une personne de l'équipe"), ('special_add_account', 'Créer un compte avec une balance initiale'))},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='accountnegative',
|
||||
options={'permissions': (('view_negs', 'Voir la liste des négatifs'),)},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='inventory',
|
||||
options={'ordering': ['-at'], 'permissions': (('order_to_inventory', "Générer un inventaire à partir d'une commande"),)},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='operation',
|
||||
options={'permissions': (('perform_deposit', 'Effectuer une charge'), ('perform_negative_operations', 'Enregistrer des commandes en négatif'), ('override_frozen_protection', "Forcer le gel d'un compte"), ('cancel_old_operations', 'Annuler des commandes non récentes'), ('perform_commented_operations', 'Enregistrer des commandes avec commentaires'))},
|
||||
),
|
||||
migrations.RunPython(forwards_perms),
|
||||
]
|
|
@ -63,6 +63,18 @@ class Account(models.Model):
|
|||
unique = True,
|
||||
blank = True, null = True, default = None)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
('is_team', 'Is part of the team'),
|
||||
('manage_perms', 'Gérer les permissions K-Fêt'),
|
||||
('manage_addcosts', 'Gérer les majorations'),
|
||||
('edit_balance_account', "Modifier la balance d'un compte"),
|
||||
('change_account_password',
|
||||
"Modifier le mot de passe d'une personne de l'équipe"),
|
||||
('special_add_account',
|
||||
"Créer un compte avec une balance initiale")
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return '%s (%s)' % (self.trigramme, self.name)
|
||||
|
||||
|
@ -284,6 +296,11 @@ class AccountNegative(models.Model):
|
|||
)
|
||||
comment = models.CharField("commentaire", max_length=255, blank=True)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
('view_negs', 'Voir la liste des négatifs'),
|
||||
)
|
||||
|
||||
|
||||
class Checkout(models.Model):
|
||||
created_by = models.ForeignKey(
|
||||
|
@ -462,6 +479,10 @@ class Inventory(models.Model):
|
|||
|
||||
class Meta:
|
||||
ordering = ['-at']
|
||||
permissions = (
|
||||
('order_to_inventory', "Générer un inventaire à partir d'une commande"),
|
||||
)
|
||||
|
||||
|
||||
class InventoryArticle(models.Model):
|
||||
inventory = models.ForeignKey(
|
||||
|
@ -638,6 +659,17 @@ class Operation(models.Model):
|
|||
max_digits=6, decimal_places=2,
|
||||
blank=True, null=True, default=None)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
('perform_deposit', 'Effectuer une charge'),
|
||||
('perform_negative_operations',
|
||||
'Enregistrer des commandes en négatif'),
|
||||
('override_frozen_protection', "Forcer le gel d'un compte"),
|
||||
('cancel_old_operations', 'Annuler des commandes non récentes'),
|
||||
('perform_commented_operations',
|
||||
'Enregistrer des commandes avec commentaires'),
|
||||
)
|
||||
|
||||
@property
|
||||
def is_checkout(self):
|
||||
return (self.type == Operation.DEPOSIT or
|
||||
|
@ -658,26 +690,5 @@ class Operation(models.Model):
|
|||
amount=self.amount)
|
||||
|
||||
|
||||
class GlobalPermissions(models.Model):
|
||||
class Meta:
|
||||
managed = False
|
||||
permissions = (
|
||||
('is_team', 'Is part of the team'),
|
||||
('perform_deposit', 'Effectuer une charge'),
|
||||
('perform_negative_operations',
|
||||
'Enregistrer des commandes en négatif'),
|
||||
('override_frozen_protection', "Forcer le gel d'un compte"),
|
||||
('cancel_old_operations', 'Annuler des commandes non récentes'),
|
||||
('manage_perms', 'Gérer les permissions K-Fêt'),
|
||||
('manage_addcosts', 'Gérer les majorations'),
|
||||
('perform_commented_operations', 'Enregistrer des commandes avec commentaires'),
|
||||
('view_negs', 'Voir la liste des négatifs'),
|
||||
('order_to_inventory', "Générer un inventaire à partir d'une commande"),
|
||||
('edit_balance_account', "Modifier la balance d'un compte"),
|
||||
('change_account_password', "Modifier le mot de passe d'une personne de l'équipe"),
|
||||
('special_add_account', "Créer un compte avec une balance initiale")
|
||||
)
|
||||
|
||||
|
||||
class GenericTeamToken(models.Model):
|
||||
token = models.CharField(max_length = 50, unique = True)
|
||||
|
|
Loading…
Reference in a new issue