Browse Source

Criar usuários padrão somente de forma explícita

pull/1477/head
Marcio Mazza 7 years ago
parent
commit
847a28721a
  1. 50
      sapl/rules/apps.py

50
sapl/rules/apps.py

@ -3,7 +3,6 @@ from builtins import LookupError
import django import django
import reversion import reversion
from django.apps import apps from django.apps import apps
from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.management import _get_all_permissions from django.contrib.auth.management import _get_all_permissions
from django.core import exceptions from django.core import exceptions
@ -116,7 +115,8 @@ def create_proxy_permissions(
def update_groups(app_config, verbosity=2, interactive=True, 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): if app_config != AppConfig and not isinstance(app_config, AppConfig):
return return
@ -149,41 +149,16 @@ def update_groups(app_config, verbosity=2, interactive=True,
if not group_name: if not group_name:
return return
g = Group.objects.get_or_create(name=group_name) group, created = Group.objects.get_or_create(name=group_name)
if not isinstance(g, Group): group.permissions.clear()
g = g[0]
g.permissions.clear()
try: try:
print(' ', group_name) print(' ', group_name)
for model, perms in rules_list: for model, perms in rules_list:
self.associar(g, model, perms) self.associar(group, model, perms)
except Exception as e: except Exception as e:
print(group_name, 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): def groups_add_user(self, user, groups_name):
if not isinstance(groups_name, list): if not isinstance(groups_name, list):
groups_name = [groups_name, ] groups_name = [groups_name, ]
@ -213,6 +188,19 @@ def update_groups(app_config, verbosity=2, interactive=True,
usuario.save() usuario.save()
grupo.user_set.add(usuario) 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): def update_groups(self):
print('') print('')
print(string_concat('\033[93m\033[1m', 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 = Rules(rules_patterns)
rules.update_groups() rules.update_groups()
if cria_usuarios_padrao:
rules.cria_usuarios_padrao()
def revision_pre_delete_signal(sender, **kwargs): def revision_pre_delete_signal(sender, **kwargs):

Loading…
Cancel
Save