Skip to content

Commit abb0556

Browse files
committed
frontend: fixes
- route protection - items in sidebar being displayed after a user has deleted his account
1 parent 04d1bf0 commit abb0556

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

frontend/src/main/javascript/src/js/components/forms/userEditForm.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {events} from '../../constants';
18+
1719
/**
1820
* The component for the form to edit the password and the email of a user or to delete the user.
1921
*/
@@ -27,14 +29,16 @@ class UserEditForm {
2729
* @param {ToastService} ToastService
2830
* @param {UserResource} UserResource
2931
* @param {PromptService} PromptService
32+
* @param {EventBus} EventBus
3033
*/
3134
// @ngInject
32-
constructor($state, SessionService, ToastService, UserResource, PromptService) {
35+
constructor($state, SessionService, ToastService, UserResource, PromptService, EventBus) {
3336
this.$state = $state;
3437
this.SessionService = SessionService;
3538
this.ToastService = ToastService;
3639
this.UserResource = UserResource;
3740
this.PromptService = PromptService;
41+
this.EventBus = EventBus;
3842

3943
/**
4044
* The model for the input of the old password.
@@ -116,6 +120,8 @@ class UserEditForm {
116120

117121
// remove the users jwt so that he cannot do anything after being deleted
118122
this.SessionService.removeUser();
123+
this.EventBus.emit(events.USER_LOGGED_IN, {user: null});
124+
this.EventBus.emit(events.PROJECT_OPENED, {project: null});
119125
this.$state.go('home');
120126
})
121127
.catch(response => {

frontend/src/main/javascript/src/js/routes.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,31 @@ export function config($stateProvider, $urlRouterProvider) {
128128
/**
129129
* Validate routes on state change.
130130
*
131-
* @param $rootScope
132-
* @param $state
131+
* @param {TransitionService} $transitions
133132
* @param {SessionService} SessionService
134133
* @param {ToastService} ToastService
135134
*/
136135
// @ngInject
137-
export function run($rootScope, $state, SessionService, ToastService) {
136+
export function run($transitions, SessionService, ToastService) {
138137

139138
// route validation
140-
$rootScope.$on('$stateChangeStart', stateChangeStart);
139+
$transitions.onBefore({}, onBefore, {});
140+
$transitions.onSuccess({}, onSuccess, {});
141141

142-
function stateChangeStart(event, toState) {
143-
if (toState.data) {
144-
const user = SessionService.getUser();
145-
const project = SessionService.getProject();
142+
function onBefore(transition) {
143+
const user = SessionService.getUser();
144+
const project = SessionService.getProject();
146145

147-
document.querySelector('title').innerHTML = 'ALEX | ' + toState.data.title;
146+
const data = transition.to().data;
147+
if ((data.roles && (user === null || data.roles.indexOf(user.role) === -1))
148+
|| (data.requiresProject && project === null)) {
148149

149-
if ((toState.data.roles && (user === null
150-
|| toState.data.roles.indexOf(user.role) === -1))
151-
|| (toState.data.requiresProject && project === null)) {
152-
153-
ToastService.danger('You are not allowed to go to this page!');
154-
155-
$state.go('home');
156-
event.preventDefault();
157-
}
150+
ToastService.danger('You cannot access this page!');
151+
return transition.router.stateService.target('home');
158152
}
159153
}
154+
155+
function onSuccess(transition) {
156+
document.querySelector('title').innerHTML = 'ALEX | ' + transition.to().data.title;
157+
}
160158
}

0 commit comments

Comments
 (0)