From b51ef9df65f6b935da2f14f94dd679d1cd24e6ba Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Tue, 21 Jan 2020 20:33:33 +0500 Subject: [PATCH] feature: suspend/unsuspend users --- .../static/userManagment/userManagment.js | 55 +++++++++++++++++- .../templates/userManagment/listUsers.html | 4 +- userManagment/urls.py | 1 + userManagment/userManager.py | 47 +++++++++++++++ userManagment/views.py | 57 ++++++++++++++++++- 5 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 userManagment/userManager.py diff --git a/userManagment/static/userManagment/userManagment.js b/userManagment/static/userManagment/userManagment.js index b25c5a400..39cbf5d6d 100755 --- a/userManagment/static/userManagment/userManagment.js +++ b/userManagment/static/userManagment/userManagment.js @@ -1686,8 +1686,59 @@ app.controller('listTableUsers', function ($scope, $http) { }; - $scope.controlUserState = function (state) { - alert(state); + $scope.controlUserState = function (userName, state) { + $scope.cyberpanelLoading = false; + + var url = "/users/controlUserState"; + + var data = { + accountUsername: userName, + state : state + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + $scope.populateCurrentRecords(); + new PNotify({ + title: 'Success!', + text: 'Action successfully started.', + type: 'success' + }); + + } else { + + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.cyberpanelLoading = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + + } } }); diff --git a/userManagment/templates/userManagment/listUsers.html b/userManagment/templates/userManagment/listUsers.html index 470d78207..05271bf79 100755 --- a/userManagment/templates/userManagment/listUsers.html +++ b/userManagment/templates/userManagment/listUsers.html @@ -49,10 +49,10 @@ {% trans 'Suspend' %} + ng-click="controlUserState(record.name, 'SUSPEND')" title="">{% trans 'Suspend' %} {% trans 'Activate' %} + ng-click="controlUserState(record.name, 'ACTIVATE')" title="">{% trans 'Activate' %}