mirror of
https://github.com/getredash/redash.git
synced 2025-12-23 20:01:59 -05:00
123 lines
2.8 KiB
JavaScript
123 lines
2.8 KiB
JavaScript
import { each } from 'underscore';
|
|
import template from './show.html';
|
|
|
|
function UserCtrl($scope, $routeParams, $http, $location, toastr,
|
|
clientConfig, currentUser, Events, User) {
|
|
// $scope.$parent.pageTitle = 'Users';
|
|
|
|
$scope.userId = $routeParams.userId;
|
|
$scope.currentUser = currentUser;
|
|
$scope.clientConfig = clientConfig;
|
|
|
|
if ($scope.userId === 'me') {
|
|
$scope.userId = currentUser.id;
|
|
}
|
|
|
|
Events.record(currentUser, 'view', 'user', $scope.userId);
|
|
$scope.canEdit = currentUser.hasPermission('admin') || currentUser.id === parseInt($scope.userId, 10);
|
|
$scope.showSettings = false;
|
|
$scope.showPasswordSettings = false;
|
|
|
|
$scope.selectTab = (tab) => {
|
|
$scope.selectedTab = tab;
|
|
each($scope.tabs, (v, k) => {
|
|
$scope.tabs[k] = (k === tab);
|
|
});
|
|
};
|
|
|
|
$scope.setTab = (tab) => {
|
|
$scope.selectedTab = tab;
|
|
$location.hash(tab);
|
|
};
|
|
|
|
$scope.tabs = {
|
|
profile: false,
|
|
apiKey: false,
|
|
settings: false,
|
|
password: false,
|
|
};
|
|
|
|
$scope.selectTab($location.hash() || 'profile');
|
|
|
|
$scope.user = User.get({ id: $scope.userId }, (user) => {
|
|
if (user.auth_type === 'password') {
|
|
$scope.showSettings = $scope.canEdit;
|
|
$scope.showPasswordSettings = $scope.canEdit;
|
|
}
|
|
});
|
|
|
|
$scope.password = {
|
|
current: '',
|
|
new: '',
|
|
newRepeat: '',
|
|
};
|
|
|
|
$scope.savePassword = (form) => {
|
|
$scope.$broadcast('show-errors-check-validity');
|
|
|
|
if (!form.$valid) {
|
|
return;
|
|
}
|
|
|
|
const data = {
|
|
id: $scope.user.id,
|
|
password: $scope.password.new,
|
|
old_password: $scope.password.current,
|
|
};
|
|
|
|
User.save(data, () => {
|
|
toastr.success('Password Saved.');
|
|
$scope.password = {
|
|
current: '',
|
|
new: '',
|
|
newRepeat: '',
|
|
};
|
|
}, (error) => {
|
|
const message = error.data.message || 'Failed saving password.';
|
|
toastr.error(message);
|
|
});
|
|
};
|
|
|
|
$scope.updateUser = (form) => {
|
|
$scope.$broadcast('show-errors-check-validity');
|
|
|
|
if (!form.$valid) {
|
|
return;
|
|
}
|
|
|
|
const data = {
|
|
id: $scope.user.id,
|
|
name: $scope.user.name,
|
|
email: $scope.user.email,
|
|
};
|
|
|
|
User.save(data, (user) => {
|
|
toastr.success('Saved.');
|
|
$scope.user = user;
|
|
}, (error) => {
|
|
const message = error.data.message || 'Failed saving.';
|
|
toastr.error(message);
|
|
});
|
|
};
|
|
|
|
$scope.sendPasswordReset = () => {
|
|
$scope.disablePasswordResetButton = true;
|
|
$http.post(`api/users/${$scope.user.id}/reset_password`).success((data) => {
|
|
$scope.disablePasswordResetButton = false;
|
|
$scope.passwordResetLink = data.reset_link;
|
|
});
|
|
};
|
|
}
|
|
|
|
export default function (ngModule) {
|
|
ngModule.controller('UserCtrl', UserCtrl);
|
|
|
|
return {
|
|
'/users/:userId': {
|
|
template,
|
|
reloadOnSearch: false,
|
|
controller: 'UserCtrl',
|
|
},
|
|
};
|
|
}
|