From 847a28721a7b1b86f49c590e3f7d21e44b54db62 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Mon, 11 Sep 2017 16:46:28 -0300 Subject: [PATCH] =?UTF-8?q?Criar=20usu=C3=A1rios=20padr=C3=A3o=20somente?= =?UTF-8?q?=20de=20forma=20expl=C3=ADcita?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/rules/apps.py | 50 +++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/sapl/rules/apps.py b/sapl/rules/apps.py index ab8c6322c..ad4ec1864 100644 --- a/sapl/rules/apps.py +++ b/sapl/rules/apps.py @@ -3,7 +3,6 @@ from builtins import LookupError import django import reversion from django.apps import apps -from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.management import _get_all_permissions from django.core import exceptions @@ -116,7 +115,8 @@ def create_proxy_permissions( def update_groups(app_config, verbosity=2, interactive=True, - using=DEFAULT_DB_ALIAS, **kwargs): + using=DEFAULT_DB_ALIAS, cria_usuarios_padrao=False, + **kwargs): if app_config != AppConfig and not isinstance(app_config, AppConfig): return @@ -149,41 +149,16 @@ def update_groups(app_config, verbosity=2, interactive=True, if not group_name: return - g = Group.objects.get_or_create(name=group_name) - if not isinstance(g, Group): - g = g[0] - g.permissions.clear() + group, created = Group.objects.get_or_create(name=group_name) + group.permissions.clear() try: - print(' ', group_name) for model, perms in rules_list: - self.associar(g, model, perms) + self.associar(group, model, perms) except Exception as e: print(group_name, e) - if settings.DEBUG: - user = '' - if group_name == SAPL_GROUP_ADMINISTRATIVO: - user = 'operador_administrativo' - elif group_name == SAPL_GROUP_PROTOCOLO: - user = 'operador_protocoloadm' - elif group_name == SAPL_GROUP_COMISSOES: - user = 'operador_comissoes' - elif group_name == SAPL_GROUP_MATERIA: - user = 'operador_materia' - elif group_name == SAPL_GROUP_NORMA: - user = 'operador_norma' - elif group_name == SAPL_GROUP_SESSAO: - user = 'operador_sessao' - elif group_name == SAPL_GROUP_PAINEL: - user = 'operador_painel' - elif group_name == SAPL_GROUP_GERAL: - user = 'operador_geral' - - if user: - self.cria_usuario(user, g) - def groups_add_user(self, user, groups_name): if not isinstance(groups_name, list): groups_name = [groups_name, ] @@ -213,6 +188,19 @@ def update_groups(app_config, verbosity=2, interactive=True, usuario.save() grupo.user_set.add(usuario) + def cria_usuarios_padrao(self): + for group, user in ( + (SAPL_GROUP_ADMINISTRATIVO, 'operador_administrativo'), + (SAPL_GROUP_PROTOCOLO, 'operador_protocoloadm'), + (SAPL_GROUP_COMISSOES, 'operador_comissoes'), + (SAPL_GROUP_MATERIA, 'operador_materia'), + (SAPL_GROUP_NORMA, 'operador_norma'), + (SAPL_GROUP_SESSAO, 'operador_sessao'), + (SAPL_GROUP_PAINEL, 'operador_painel'), + (SAPL_GROUP_GERAL, 'operador_geral'), + ): + self.cria_usuario(user, group) + def update_groups(self): print('') print(string_concat('\033[93m\033[1m', @@ -225,6 +213,8 @@ def update_groups(app_config, verbosity=2, interactive=True, rules = Rules(rules_patterns) rules.update_groups() + if cria_usuarios_padrao: + rules.cria_usuarios_padrao() def revision_pre_delete_signal(sender, **kwargs):