Browse Source

Checkbox com isStaff

Adicionada a opçao de apenas staff
pull/2418/head
VasileKarpa 6 months ago
parent
commit
2cc9166204
3 changed files with 41 additions and 27 deletions
  1. 5
      backend/users/views.py
  2. 60
      frontend/components/settings/FormCreate.vue
  3. 3
      frontend/repositories/user/apiUserRepository.ts

5
backend/users/views.py

@ -40,6 +40,11 @@ class UserCreation(generics.CreateAPIView):
user.is_staff = True
user.save()
headers = self.get_success_headers(serializer.data)
if request.data.get('is_staff') in [True, 'true', 'True', 1]:
user.is_superuser = False
user.is_staff = True
user.save()
headers = self.get_success_headers(serializer.data)
return Response(UserSerializer(user).data, status=status.HTTP_201_CREATED, headers=headers)
def perform_create(self, serializer):

60
frontend/components/settings/FormCreate.vue

@ -30,11 +30,16 @@
type="password"
required
/>
<!-- Adiciona o checkbox para superusuário -->
<!-- Checkbox para Superuser -->
<v-checkbox
v-model="isSuperuser"
:label="$t('Superuser - If selected, this option grants the user full privileges automatically')"
/>
<!-- Checkbox para Staff -->
<v-checkbox
v-model="isStaff"
:label="$t('Staff - If selected, the user will have staff status without full privileges')"
/>
</v-form>
<v-alert v-if="errorMessage" type="error" dense>{{ errorMessage }}</v-alert>
</v-card-text>
@ -65,8 +70,9 @@
email: '',
password1: '',
password2: '',
// Nova propriedade para o checkbox
// Propriedades dos checkboxes
isSuperuser: false,
isStaff: false,
errorMessage: '',
usernameRules: [
(v: string) => !!v || this.$t('user.usernameRequired'),
@ -83,30 +89,32 @@
}
},
methods: {
async create() {
if (!(this.$refs.form as Vue & { validate: () => boolean }).validate()) {
return
}
this.loading = true
this.errorMessage = ''
try {
await this.$repositories.user.create({
username: this.username,
email: this.email,
password1: this.password1,
password2: this.password2,
// Adiciona a propriedade is_superuser ao objeto de dados
is_superuser: this.isSuperuser
})
this.$emit('save')
} catch (e: any) {
this.errorMessage = e.response?.data?.detail || this.$t('generic.error')
} finally {
this.loading = false
}
}
async create() {
console.log('Método create chamado')
if (!(this.$refs.form as Vue & { validate: () => boolean }).validate()) {
return
}
this.loading = true
this.errorMessage = ''
try {
await this.$repositories.user.create({
username: this.username,
email: this.email,
password1: this.password1,
password2: this.password2,
// Se isSuperuser estiver selecionado, is_superuser será true e is_staff true;
// caso contrário, se isStaff estiver marcado, apenas is_staff será true.
is_superuser: this.isSuperuser,
is_staff: this.isSuperuser ? true : this.isStaff
})
this.$emit('save')
} catch (e: any) {
console.error("Erro ao criar usuário:", e)
this.errorMessage = e.response?.data?.detail || this.$t('generic.error')
} finally {
this.loading = false
}
}
}
})
</script>

3
frontend/repositories/user/apiUserRepository.ts

@ -12,7 +12,8 @@ function toPayload(item: { [key: string]: any }): { [key: string]: any } {
email: item.email,
password1: item.password1,
password2: item.password2,
is_superuser: item.is_superuser
is_superuser: item.is_superuser,
is_staff: item.is_staff
}
}

Loading…
Cancel
Save