adminEditUserCtrl.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. define([
  2. 'angular',
  3. ],
  4. function (angular) {
  5. 'use strict';
  6. var module = angular.module('grafana.controllers');
  7. module.controller('AdminEditUserCtrl', function($scope, $routeParams, backendSrv, $location) {
  8. $scope.user = {};
  9. $scope.permissions = {};
  10. $scope.init = function() {
  11. if ($routeParams.id) {
  12. $scope.getUser($routeParams.id);
  13. }
  14. };
  15. $scope.getUser = function(id) {
  16. backendSrv.get('/api/admin/users/' + id).then(function(user) {
  17. $scope.user = user;
  18. $scope.user_id = id;
  19. $scope.permissions.isGrafanaAdmin = user.isGrafanaAdmin;
  20. });
  21. };
  22. $scope.setPassword = function () {
  23. if (!$scope.passwordForm.$valid) { return; }
  24. var payload = { password: $scope.password };
  25. backendSrv.put('/api/admin/users/' + $scope.user_id + '/password', payload).then(function() {
  26. $location.path('/admin/users');
  27. });
  28. };
  29. $scope.updatePermissions = function() {
  30. var payload = $scope.permissions;
  31. backendSrv.put('/api/admin/users/' + $scope.user_id + '/permissions', payload).then(function() {
  32. $location.path('/admin/users');
  33. });
  34. };
  35. $scope.create = function() {
  36. if (!$scope.userForm.$valid) { return; }
  37. backendSrv.post('/api/admin/users', $scope.user).then(function() {
  38. $location.path('/admin/users');
  39. });
  40. };
  41. $scope.update = function() {
  42. if (!$scope.userForm.$valid) { return; }
  43. backendSrv.put('/api/admin/users/' + $scope.user_id + '/details', $scope.user).then(function() {
  44. $location.path('/admin/users');
  45. });
  46. };
  47. $scope.init();
  48. });
  49. });