Skip to content

Commit

Permalink
Allow non admin users to delete themselves (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxvd authored Sep 25, 2024
1 parent 2238cba commit b6ea637
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions client/scripts/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* Created by groupsky on 13.01.16.
*/

var angular = require('angular')
var forms = require('../configs/forms')
const angular = require('angular')
const forms = require('../configs/forms')

require('../app').controller('UserController', /* @ngInject */function ($scope, $state, $stateParams, $q, $timeout, $translate, api, ngToast, user, User, Raven) {
var controller = this
const controller = this

var id = $stateParams.id || $stateParams.fromId
const id = $stateParams.id || $stateParams.fromId

controller.data = id ? User.get({ id: id }) : new User()
controller.data = id ? User.get({ id }) : new User()
controller.data.id = id

controller.moderatorForms = []
Expand Down Expand Up @@ -98,8 +98,11 @@ require('../app').controller('UserController', /* @ngInject */function ($scope,

controller.delete = function () {
$q.resolve(controller.data)
.then(function (user) {
return User.delete({ id: user.id }).$promise
.then(function (userToDelete) {
return $q.all([
userToDelete,
User.delete({ id: userToDelete.id }).$promise
])
})
.then(function (res) {
ngToast.create({
Expand All @@ -117,7 +120,10 @@ require('../app').controller('UserController', /* @ngInject */function ($scope,
})
.then(function (res) {
controller.form.$setPristine()
$state.go('^')
if (res[0].id === user.getIdentity().id) {
user.logout()
}
$state.go('home')
})
}

Expand All @@ -126,7 +132,7 @@ require('../app').controller('UserController', /* @ngInject */function ($scope,
}

function hackAutocompletion () {
var timeout = false
let timeout = false
var deregister = $scope.$watch(function () {
if (timeout) $timeout.cancel(timeout)
timeout = $timeout(function () {
Expand Down
2 changes: 1 addition & 1 deletion client/views/users/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h1 ng-if="user.data.id" class="page-header">
<button type="button"
class="btn btn-danger"
ng-disabled="!user.data.getName()"
ng-if="::$user.isAdmin() && user.data.id"
ng-if="user.data.id"
confirm="{{::user.deleteConfirmMessage}}"
confirm-text="{{::user.data.getName()}}"
confirm-size="md"
Expand Down

0 comments on commit b6ea637

Please sign in to comment.