Skip to content

Commit

Permalink
#1316 Add UI to switch organisation for users belongs to more than on…
Browse files Browse the repository at this point in the history
…e org
  • Loading branch information
nadouani committed May 15, 2020
1 parent be09479 commit f03fb3f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 3 deletions.
1 change: 1 addition & 0 deletions frontend/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<script src="scripts/components/header.component.js"></script>
<script src="scripts/components/main-sidebar.component.js"></script>
<script src="scripts/components/organisation/OrgCaseTemplateListCmp.js"></script>
<script src="scripts/components/organisation/OrgSwitchCtrl.js"></script>
<script src="scripts/components/organisation/OrgUserListCmp.js"></script>
<script src="scripts/components/search/filters-preview.component.js"></script>
<script src="scripts/components/sharing/SharingListCmp.js"></script>
Expand Down
18 changes: 18 additions & 0 deletions frontend/app/scripts/components/organisation/OrgSwitchCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function() {
'use strict';

angular.module('theHiveControllers').controller('OrgSwitchCtrl',
function($uibModalInstance, currentUser) {
//var self = this;

this.currentUser = currentUser;

this.selectOrg = function(selected) {
$uibModalInstance.close(selected);
};

this.cancel = function() {
$uibModalInstance.dismiss();
};
});
})();
34 changes: 34 additions & 0 deletions frontend/app/scripts/controllers/RootCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,40 @@ angular.module('theHiveControllers').controller('RootCtrl',
});
};

$scope.switchOrg = function() {
var modal = $uibModal.open({
templateUrl: 'views/components/org/orgSwitch.modal.html',
controller: 'OrgSwitchCtrl',
controllerAs: '$dialog',
resolve: {
currentUser: $scope.currentUser
}
});

modal.result
.then(function(organisation) {
console.log(organisation);

$rootScope.isLoading = true;

AuthenticationSrv.current(organisation)
.then(function(/*userData*/) {
$rootScope.isLoading = false;
$state.go('app.index');
})
.catch( function(err) {
NotificationSrv.error('App', err.data, err.status);
$rootScope.isLoading = false;
});
})
.catch(function(err) {
if(err && !_.isString(err)) {
NotificationSrv.error('Switch organisation', err.data, err.status);
}
});

};

$scope.createNewCase = function(template) {
var modal = $uibModal.open({
templateUrl: 'views/partials/case/case.creation.html',
Expand Down
12 changes: 10 additions & 2 deletions frontend/app/scripts/services/api/AuthenticationSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@
}
});
},
current: function() {
current: function(organisation) {
var result = {};

var options = {};
if(organisation) {
options.headers = {
'X-Organisation': organisation
};
}

return $http
.get('./api/v1/user/current')
.get('./api/v1/user/current', options)
.then(function(response) {
self.currentUser = response.data;
UtilsSrv.shallowClearAndCopy(response.data, result);
Expand Down
7 changes: 6 additions & 1 deletion frontend/app/views/components/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<i class="fa fa-file-text"></i>
<span class="hpad5">Analyzer templates</span>
</a>
</li>
</li>
<!-- <li>
<a ui-sref="app.administration.ui-settings">
<i class="fa fa-cogs"></i>
Expand Down Expand Up @@ -175,6 +175,11 @@
</li>
</ul>
</li>
<li ng-if="currentUser.organisations.length > 0">
<a href ng-click="switchOrg()">
<i class="fa fa-exchange"></i>
</a>
</li>
</ul>
</div>

Expand Down
30 changes: 30 additions & 0 deletions frontend/app/views/components/org/orgSwitch.modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<form ng-submit="$modal.confirm()">
<div class="modal-header bg-primary">
<h3 class="modal-title">Switch organisation</h3>
</div>
<div class="modal-body">
<p class="mb-xs">
Please select the organisation you want to switch to:
</p>

<div class="form-group has-feedback has-feedback-left" ng-if="$dialog.currentUser.organisations.length > 5">
<input type="text" class="input input-lg form-control" placeholder="Filter organisations" ng-model="$modal.filter" autocomplete="off">
<i class="form-control-feedback glyphicon glyphicon-search"></i>
</div>


<ul class="nav nav-pills nav-stacked">
<div class="list-group">
<a href ng-click="$dialog.selectOrg(item.organisation)" class="list-group-item"
ng-class="{'active': $dialog.currentUser.organisation === item.organisation}"
ng-repeat="item in $dialog.currentUser.organisations | filter:$modal.filter track by $index">
<h4 class="list-group-item-heading">{{item.organisation}}</h4>
<p class="list-group-item-text">Profile: <strong>{{item.role}}</strong></p>
</a>
</div>
</ul>
</div>
<div class="modal-footer text-left">
<button class="btn btn-default" ng-click="$dialog.cancel()" type="button">Cancel</button>
</div>
</form>

0 comments on commit f03fb3f

Please sign in to comment.