admin could remove user

This commit is contained in:
lesion 2019-06-18 15:13:13 +02:00
parent 85694906f1
commit 4c3c7ee324
4 changed files with 54 additions and 6 deletions

View file

@ -42,7 +42,9 @@ const it = {
copy: 'Copia', copy: 'Copia',
recover_password: 'Recupera password', recover_password: 'Recupera password',
new_password: 'Nuova password', new_password: 'Nuova password',
new_user: 'Nuovo utente' new_user: 'Nuovo utente',
ok: 'Ok',
cancel: 'Annulla'
}, },
login: { login: {
@ -114,7 +116,11 @@ const it = {
mastodon_instance: 'Istanza', mastodon_instance: 'Istanza',
mastodon_description: 'Puoi associare un account mastodon a questa istanza di gancio, ogni evento verrà pubblicato lì.', mastodon_description: 'Puoi associare un account mastodon a questa istanza di gancio, ogni evento verrà pubblicato lì.',
place_description: `Nel caso in cui un luogo sia errato o cambi indirizzo, puoi modificarlo. <br/>Considera che tutti gli eventi associati a questo luogo cambieranno indirizzo (anche quelli passati!)`, place_description: `Nel caso in cui un luogo sia errato o cambi indirizzo, puoi modificarlo. <br/>Considera che tutti gli eventi associati a questo luogo cambieranno indirizzo (anche quelli passati!)`,
event_confirm_description: 'Puoi confermare qui gli eventi inseriti da utenti anonimi' event_confirm_description: 'Puoi confermare qui gli eventi inseriti da utenti anonimi',
delete_user: 'Elimina',
remove_admin: 'Rimuovi admin',
delete_user_confirm: 'Sicura di rimuovere questo utente?',
user_remove_ok: 'Utente eliminato'
}, },
auth: { auth: {

View file

@ -36,7 +36,11 @@
@click='toggle(data.row)') {{data.row.is_active?$t('common.deactivate'):$t('common.activate')}} @click='toggle(data.row)') {{data.row.is_active?$t('common.deactivate'):$t('common.activate')}}
el-button(size='mini' el-button(size='mini'
:type='data.row.is_admin?"danger":"warning"' :type='data.row.is_admin?"danger":"warning"'
@click='toggleAdmin(data.row)') {{data.row.is_admin?$t('common.remove_admin'):$t('common.admin')}} @click='toggleAdmin(data.row)') {{data.row.is_admin?$t('admin.remove_admin'):$t('common.admin')}}
el-button(size='mini'
type='danger'
@click='delete_user(data.row)') {{$t('admin.delete_user')}}
el-pagination(:page-size='perPage' :currentPage.sync='userPage' :total='users.length') el-pagination(:page-size='perPage' :currentPage.sync='userPage' :total='users.length')
//- PLACES //- PLACES
@ -110,13 +114,18 @@
el-form(inline @submit.native.prevent='associate_mastondon_instance' label-width='140px') el-form(inline @submit.native.prevent='associate_mastondon_instance' label-width='140px')
p {{$t('admin.mastodon_description')}} p {{$t('admin.mastodon_description')}}
el-form-item {{$t('admin.mastodon_instance')}} el-form-item {{$t('admin.mastodon_instance')}}
el-input(v-model="mastodon_instance") el-input(v-model="settings.mastodon_instance")
el-button(slot='append' native-type='submit' type='success' :disabled='!mastodon_instance.length') {{$t('common.associate')}} el-button(slot='append' native-type='submit' type='success' :disabled='!settings.mastodon_instance') {{$t('common.associate')}}
p {{$t('admin.allow_registration_description')}}
el-form-item {{$t('admin.allow_registration')}}
el-switch(v-model='settings.allow_registration')
</template> </template>
<script> <script>
import { mapState } from 'vuex' import { mapState } from 'vuex'
import { Message } from 'element-ui' import { Message, MessageBox } from 'element-ui'
export default { export default {
name: 'Admin', name: 'Admin',
@ -224,6 +233,23 @@ export default {
const url = await this.$axios.$post('/settings/getauthurl', {instance: this.settings.mastodon_instance}) const url = await this.$axios.$post('/settings/getauthurl', {instance: this.settings.mastodon_instance})
setTimeout( () => window.location.href=url, 100); setTimeout( () => window.location.href=url, 100);
}, },
async delete_user (user) {
console.error('dentro delete user', user)
MessageBox.confirm(this.$t('admin.delete_user_confirm'),
this.$t('common.confirm'), {
confirmButtonText: this.$t('common.ok'),
cancelButtonText: this.$t('common.cancel'),
type: 'error'
})
.then( () => this.$axios.delete(`/user/${user.id}`) )
.then( () => {
Message({
type: 'success',
message: this.$t('admin.user_remove_ok')
})
this.users = this.users.filter(u => u.id!==user.id)
})
},
async create_user () { async create_user () {
try { try {
this.loading = true this.loading = true

View file

@ -254,6 +254,16 @@ const userController = {
} catch (e) { } catch (e) {
res.status(404).json(e) res.status(404).json(e)
} }
},
async remove(req, res) {
try {
const user = await User.findByPk(req.params.id)
user.destroy()
res.sendStatus(200)
} catch (e) {
res.status(404).json(e)
}
} }
} }

View file

@ -40,6 +40,12 @@ api.post('/user', jwt, isAuth, isAdmin, userController.create)
// update user (disable/) // update user (disable/)
api.put('/user', jwt, isAuth, isAdmin, userController.update) api.put('/user', jwt, isAuth, isAdmin, userController.update)
//delete user
api.delete('/user/:id', jwt, isAuth, isAdmin, userController.remove)
//
// api.delete('/user', userController.remove)
// get all users // get all users
api.get('/users', jwt, isAuth, isAdmin, userController.getAll) api.get('/users', jwt, isAuth, isAdmin, userController.getAll)