diff --git a/sapl/base/forms.py b/sapl/base/forms.py index cca62d89b..8033c37f6 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -368,6 +368,9 @@ class AutorForm(ModelForm): if self.cleaned_data['action_user'] == 'A': u = get_user_model().objects.get( username=self.cleaned_data['username']) + if not u.is_active: + u.is_active = settings.DEBUG + u.save() elif self.cleaned_data['action_user'] == 'C': u = get_user_model().objects.create( username=self.cleaned_data['username'], diff --git a/sapl/base/views.py b/sapl/base/views.py index 650c2d055..89aaec991 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -77,6 +77,11 @@ class AutorCrud(CrudAux): try: kwargs = {} user = self.object.user + + if user.is_active: + return reverse('sapl.base:autor_detail', + kwargs={'pk': pk_autor}) + kwargs['token'] = default_token_generator.make_token(user) kwargs['uidb64'] = urlsafe_base64_encode(force_bytes(user.pk)) assunto = "SAPL - Confirmação de Conta" diff --git a/sapl/templates/base/autor_form.html b/sapl/templates/base/autor_form.html index 48e379037..12eaf104b 100644 --- a/sapl/templates/base/autor_form.html +++ b/sapl/templates/base/autor_form.html @@ -10,15 +10,16 @@ $(document).ready(function(){ $('.radiogroup-status').remove(); flag_create = true } - var active = function(str) { + var active = function(str, atualizar=true) { if (str == 'nome') { - $('#id_nome, #id_q').val(''); + if (atualizar) + $('#id_nome, #id_q, #id_cargo').val(''); $('.div_nome_cargo').removeClass('hidden'); $("#div_id_autor_related .controls").html(''); $("[data-application='AutorSearch'], .radiogroup-autor-related").addClass('hidden'); } else { - $('#id_nome').val(''); + $('#id_nome, #id_cargo').val(''); $('.div_nome_cargo').addClass('hidden'); $("#div_id_autor_related .alert").remove(); $("[data-application='AutorSearch'], .radiogroup-autor-related").removeClass('hidden'); @@ -64,7 +65,7 @@ $(document).ready(function(){ $('#id_nome, #id_q').val(''); } }).fail(function(data) { - active('nome'); + active('nome', atualizar); }); } diff --git a/scripts/inicializa_grupos_autorizacoes.py b/scripts/inicializa_grupos_autorizacoes.py index b1ad775b7..fe69914b1 100644 --- a/scripts/inicializa_grupos_autorizacoes.py +++ b/scripts/inicializa_grupos_autorizacoes.py @@ -10,6 +10,7 @@ if True: from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission from django.contrib.contenttypes.models import ContentType + from sapl.base.models import Autor class InicializaGruposAutorizacoes(): @@ -108,17 +109,12 @@ class InicializaGruposAutorizacoes(): self.cria_usuario(nome_usuario, grupo_geral) # Autor - perms_autor = [] - perms_autor.append(Permission.objects.get(name='Can add Proposição')) - perms_autor.append( - Permission.objects.get(name='Can change Proposição')) - perms_autor.append( - Permission.objects.get(name='Can delete Proposição')) - - # Configura Permissoes Autor grupo = self.cria_ou_reseta_grupo('Autor') - for p in perms_autor: - grupo.permissions.add(p) + + list(map(lambda permissao: grupo.permissions.add(permissao), + list(Permission.objects.filter( + content_type=ContentType.objects.get_by_natural_key( + app_label='materia', model='proposicao'))))) """ Mesmo para teste, um usuário com perfil Autor criado via /admin