Browse Source

Fix #2555 - Informar erro ao tentar criar usuário sem selecionar roles (#2564)

* Fix #2555

* Corrige lugar da mensagem de erro
pull/2573/head
Vinícius Cantuária 6 years ago
committed by Edward
parent
commit
025dbfbae3
  1. 4
      sapl/base/forms.py
  2. 10
      sapl/base/views.py

4
sapl/base/forms.py

@ -84,7 +84,7 @@ class UsuarioCreateForm(ModelForm):
'password1', 'password2', 'user_active', 'roles'] 'password1', 'password2', 'user_active', 'roles']
def clean(self): def clean(self):
super(UsuarioCreateForm, self).clean() super().clean()
if not self.is_valid(): if not self.is_valid():
return self.cleaned_data return self.cleaned_data
@ -99,7 +99,7 @@ class UsuarioCreateForm(ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(UsuarioCreateForm, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
row0 = to_row([('username', 12)]) row0 = to_row([('username', 12)])

10
sapl/base/views.py

@ -1329,17 +1329,19 @@ class CreateUsuarioView(PermissionRequiredMixin, CreateView):
model = get_user_model() model = get_user_model()
form_class = UsuarioCreateForm form_class = UsuarioCreateForm
success_message = 'Usuário criado com sucesso!' success_message = 'Usuário criado com sucesso!'
fail_message = 'Usuário não criado!'
permission_required = ('base.add_appconfig',) permission_required = ('base.add_appconfig',)
def get_success_url(self): def get_success_url(self):
return reverse('sapl.base:usuario') return reverse('sapl.base:usuario')
def form_valid(self, form): def form_valid(self, form):
data = form.cleaned_data data = form.cleaned_data
new_user = get_user_model().objects.create( new_user = get_user_model().objects.create(
username=data['username'], email=data['email']) username=data['username'],
email=data['email']
)
new_user.first_name = data['firstname'] new_user.first_name = data['firstname']
new_user.last_name = data['lastname'] new_user.last_name = data['lastname']
new_user.set_password(data['password1']) new_user.set_password(data['password1'])
@ -1354,6 +1356,10 @@ class CreateUsuarioView(PermissionRequiredMixin, CreateView):
messages.success(self.request, self.success_message) messages.success(self.request, self.success_message)
return HttpResponseRedirect(self.get_success_url()) return HttpResponseRedirect(self.get_success_url())
def form_invalid(self, form):
messages.error(self.request, self.fail_message)
return super().form_invalid(form)
class DeleteUsuarioView(PermissionRequiredMixin, DeleteView): class DeleteUsuarioView(PermissionRequiredMixin, DeleteView):
model = get_user_model() model = get_user_model()

Loading…
Cancel
Save