Skip to content

Commit

Permalink
Add confirm dialog when locking a user
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Feb 9, 2018
1 parent bc6df89 commit d5d97b1
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 35 deletions.
62 changes: 54 additions & 8 deletions www/src/app/pages/admin/common/user-list/users-list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class UsersListController {
OrganizationService,
UserService,
NotificationService,
ModalService,
clipboard
) {
'ngInject';
Expand All @@ -19,6 +20,7 @@ export default class UsersListController {
this.OrganizationService = OrganizationService;
this.UserService = UserService;
this.NotificationService = NotificationService;
this.ModalService = ModalService;
this.clipboard = clipboard;

this.userKeyCache = {};
Expand All @@ -30,14 +32,6 @@ export default class UsersListController {
}

reload() {
// if (this.organization) {
// this.OrganizationService.users(this.organization.id).then(users => {
// this.users = users;
// });
// } else {
// this.UserService.
// }

this.$log.log('Users list should be reloaded');

this.onReload();
Expand Down Expand Up @@ -128,4 +122,56 @@ export default class UsersListController {
this.$log.log(rejection);
});
}

lockUser(id) {
let modalInstance = this.ModalService.confirm(
'Lock user',
'Are you sure you want to lock this user. He will no longer be able to have access to Cortex',
{
flavor: 'danger',
okText: 'Yes, lock the user'
}
);

modalInstance.result
.then(() => this.UserService.update(id, { status: 'Locked' }))
.then(
/*response*/
() => {
this.reload();
this.NotificationService.success('User locked successfully');
}
)
.catch(err => {
if (!_.isString(err)) {
this.NotificationService.error('Unable to lock the user.');
}
});
}

unlockUser(id) {
let modalInstance = this.ModalService.confirm(
'Unlock user',
'Are you sure you want to unlock this user. He will be able to have access to Cortex',
{
flavor: 'danger',
okText: 'Yes, unlock the user'
}
);

modalInstance.result
.then(() => this.UserService.update(id, { status: 'Ok' }))
.then(
/*response*/
() => {
this.reload();
this.NotificationService.success('User unlocked successfully');
}
)
.catch(err => {
if (!_.isString(err)) {
this.NotificationService.error('Unable to unlock the user.');
}
});
}
}
10 changes: 7 additions & 3 deletions www/src/app/pages/admin/common/user-list/users-list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<section class="mt-s">
<section>
<p class="lead">
Defined users ({{$ctrl.users.length}})
<a class="btn btn-primary pull-right" href ng-click="$ctrl.openModal('create', {})"><i class="fa fa-plus"></i> Add user</a>
Expand Down Expand Up @@ -76,10 +76,14 @@ <h4 class="media-heading">
<a href class="text-primary" ng-click="$ctrl.openModal('edit', user)">
<i class="fa fa-edit"></i>Edit</a>
</div>
<div class="flex-col flex-icon">
<a href class="text-danger" ng-click="$ctrl.lock(user.id)">
<div class="flex-col flex-icon flex-w-80" ng-if="user.status === 'Ok'">
<a href class="text-danger" ng-click="$ctrl.lockUser(user.id)">
<i class="fa fa-ban"></i>Lock</a>
</div>
<div class="flex-col flex-icon flex-w-80" ng-if="user.status === 'Locked'">
<a href class="text-success" ng-click="$ctrl.unlockUser(user.id)">
<i class="fa fa-refresh"></i>Unlock</a>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export default class AnalyzerEditController {
}

$onInit() {
this.$log.log('onInit of AnalyzerEditController', this.analyzer);

if (_.isEmpty(this.analyzer)) {
let analyzer = {
name: this.definition.id,
Expand All @@ -36,11 +34,9 @@ export default class AnalyzerEditController {
}

save() {
this.$log.log('Save clicked');
this.$uibModalInstance.close(this.analyzer);
}
cancel() {
this.$log.log('Cancel clicked');
this.$uibModalInstance.dismiss('cancel');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ <h3 class="modal-title">{{$modal.mode === 'create' ? 'Enable' : 'Edit'}} analyze
</div>
<div class="modal-body">
<analyzer-config-form definition="$modal.definition" analyzer="$modal.analyzer"></analyzer-config-form>

<div>Analyzer</div>
<pre>{{$modal.analyzer | json}}</pre>
</div>
<div class="modal-footer">
<button class="btn btn-warning pull-left" type="button" ng-click="$modal.cancel()">Cancel</button>
<button class="btn btn-default pull-left" type="button" ng-click="$modal.cancel()">Cancel</button>
<button class="btn btn-primary pull-right" type="submit" ng-disabled="form.$invalid">Save</button>
</div>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import AnalyzerEditController from './analyzer.edit.controller';
import editModalTpl from './analyzer.edit.modal.html';

export default class OrganizationAnalyzersController {
constructor($log, $uibModal, OrganizationService) {
constructor(
$log,
$uibModal,
OrganizationService,
ModalService,
NotificationService
) {
'ngInject';

this.$log = $log;
this.$uibModal = $uibModal;
this.OrganizationService = OrganizationService;
this.ModalService = ModalService;
this.NotificationService = NotificationService;
}

$onInit() {
Expand All @@ -35,9 +43,8 @@ export default class OrganizationAnalyzersController {
}
});

modal.result
return modal.result
.then(response => {
this.$log.log(response);
if (mode === 'create') {
return this.OrganizationService.enableAnalyzer(
this.organization.id,
Expand All @@ -60,26 +67,44 @@ export default class OrganizationAnalyzersController {

if (_.map(definition.configurationItems, 'required').indexOf(true) !== -1) {
// The analyzer requires some configurations
this.openModal('create', definition, {});
this.openModal('create', definition, {}).then(() => {
this.NotificationService.success('Analyzer enabled successfully');
});
} else {
this.OrganizationService.enableAnalyzer(
this.organization.id,
analyzerId,
{
name: analyzerId
}
).then(response => {
this.$log.log(`Analyzer ${analyzerId} enabled`, response);
).then(() => {
this.NotificationService.success('Analyzer enabled successfully');
this.reload();
});
}
}

disable(analyzerId) {
this.OrganizationService.disableAnalyzer(analyzerId).then(response => {
this.$log.log(`Analyzer ${analyzerId} disabled`, response);
this.reload();
});
let modalInstance = this.ModalService.confirm(
'Disable analyzer',
'Are you sure you want to disable this analyzer? The corresponding configuration will be lost.',
{
flavor: 'danger',
okText: 'Yes, disable it'
}
);

modalInstance.result
.then(() => this.OrganizationService.disableAnalyzer(analyzerId))
.then(() => {
this.reload();
this.NotificationService.success('Analyzer disabled successfully');
})
.catch(err => {
if (!_.isString(err)) {
this.NotificationService.error('Unable to delete the Job.');
}
});
}

reload() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<section class="content-header">
<h1>Organization:
<strong>{{$ctrl.organization.id}}</strong>
<a ui-sref="main.organizations" class="pull-right"><small><i class="fa fa-chevron-left"></i> Back to list</small></a>
<a ui-sref="main.organizations" class="pull-right"><small class="text-primary"><i class="fa fa-chevron-left"></i> Back to list</small></a>
</h1>
</section>

Expand Down
10 changes: 5 additions & 5 deletions www/src/app/pages/jobs/job.page.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<section class="content-header">
<h1>Job details
<small class="pull-right">
<a ui-sref="main.jobs">
<i class="fa fa-chevron-left fa-lg"></i> Back to list</a>
</small>
<h1>Job details
<a ui-sref="main.jobs" class="pull-right">
<small class="text-primary">
<i class="fa fa-chevron-left fa-lg"></i> Back to list</small>
</a>
</h1>
</section>
<!-- Main content -->
Expand Down

0 comments on commit d5d97b1

Please sign in to comment.