diff --git a/sapl/materia/views.py b/sapl/materia/views.py index d4de74e36..beef845c5 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -10,10 +10,11 @@ from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.tokens import default_token_generator from django.contrib.auth.models import User from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode -from django.core.exceptions import ObjectDoesNotExist +from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned from django.core.mail import send_mail from django.core.urlresolvers import reverse from django.http.response import HttpResponseRedirect +from django.shortcuts import redirect from django.template import Context, loader from django.utils.encoding import force_bytes from django.utils.translation import ugettext_lazy as _ @@ -220,8 +221,15 @@ class ProposicaoCrud(Crud): return 'ProposicaoCreate' def get_initial(self): - autor_id = Autor.objects.get(user=self.request.user.id) - return {'autor': autor_id} + try: + autor_id = Autor.objects.get(user=self.request.user.id) + except MultipleObjectsReturned: + msg = _('Este usuário está relacionado a mais de um autor. ' + + 'Operação cancelada') + messages.add_message(self.request, messages.ERROR, msg) + return redirect(self.get_success_url()) + else: + return {'autor': autor_id} class UpdateView(PermissionRequiredMixin, CrudUpdateView): form_class = ProposicaoForm diff --git a/sapl/utils.py b/sapl/utils.py index 957a4d3d6..808cca94d 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -299,7 +299,7 @@ def permissoes_painel(): def permissao_tb_aux(self): u = self.request.user - if u.groups.filter(name='Operador Geral').exists(): + if u.groups.filter(name='Operador Geral').exists() or u.is_superuser: return True else: return False