Skip to content

Commit

Permalink
fixed issue with study permissions not being set resulting in broken …
Browse files Browse the repository at this point in the history
…review links
  • Loading branch information
calstevemart committed Dec 5, 2024
1 parent 82e08da commit a156c91
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/app/auth-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ export class AuthGuard implements OnInit {
}
async checkStudyObfuscationCode(url: string, obfuscationCode: string, state: RouterStateSnapshot, studyId: string) {
const studyPermission = await this.editorService.getStudyPermissionByObfuscationCode(obfuscationCode);
const permissions = studyPermission;
this.store.dispatch(new StudyPermissionNS.Set(permissions))
if (studyPermission === null || studyPermission.studyId === "") {
this.editorService.redirectUrl = url;
const errorCode = "E-0001-002";
Expand All @@ -209,14 +211,14 @@ export class AuthGuard implements OnInit {
return false;
}
if (url.startsWith("/reviewer")) {

if (studyPermission.view) {
if (url.startsWith("/reviewer")) {
const params = { reviewCode: obfuscationCode };
this.router.navigate(["/" + studyPermission.studyId + "/files"], { queryParams: params });
return false;
}
const permissions = studyPermission;
this.store.dispatch(new StudyPermissionNS.Set(permissions))

return true;
}
}
Expand Down
18 changes: 16 additions & 2 deletions src/app/ngxs-store/non-study/application/application.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Action, Selector, State, StateContext } from "@ngxs/store";
import { StudyPermission } from "../../../services/headers";
import { BackendVersion, BannerMessage, DefaultControlLists, EditorVersion, Guides,
GuidesMappings, MaintenanceMode, SetProtocolExpand,
SetReadonly, SetSelectedLanguage, SetStudyError } from "./application.actions";
SetReadonly, SetSelectedLanguage, SetStudyError,
StudyPermissionNS} from "./application.actions";
import { Injectable } from "@angular/core";
import { ApplicationService } from "src/app/services/decomposed/application.service";

Expand Down Expand Up @@ -356,7 +357,6 @@ export class ApplicationState {
@Action(SetProtocolExpand)
SetProtocolsExpanded(ctx: StateContext<ApplicationStateModel>, action: SetProtocolExpand) {
const state = ctx.getState();
console.log(action.expand)
ctx.setState({
...state,
isProtocolsExpanded: action.expand
Expand All @@ -373,5 +373,19 @@ export class ApplicationState {
return state.toastrSettings
}

@Action(StudyPermissionNS.Set)
SetStudyPermissions(ctx: StateContext<ApplicationStateModel>, action: StudyPermissionNS.Set) {
const state = ctx.getState();
ctx.setState({
...state,
studyPermission: action.permission
})
}

@Selector()
static studyPermission(state: ApplicationStateModel) {
return state.studyPermission;
}


}
12 changes: 9 additions & 3 deletions src/app/services/interceptors/header.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Observable } from "rxjs";
import { disambiguateUserObj } from "../editor.service";
import { ConfigurationService } from "src/app/configuration.service";
import { Store } from "@ngxs/store";
import { environment } from "src/environments/environment";

/* eslint-disable @typescript-eslint/naming-convention */
@Injectable()
export class HeaderInterceptor implements HttpInterceptor {
Expand Down Expand Up @@ -51,8 +51,14 @@ export class HeaderInterceptor implements HttpInterceptor {
}
let permissions = null
permissions = this.store.snapshot().application.studyPermission

if (permissions && permissions.obfuscationCode && permissions.studyStatus.toUpperCase() === "INREVIEW"){
if (request.url.includes('/reviewer') && ['INREVIEW', 'INCURATION'].includes(permissions.studyStatus.toUpperCase())) {
request = request.clone({
setHeaders: {
obfuscation_code: permissions.obfuscationCode
}
});
}
else if (permissions && permissions.obfuscationCode && permissions.studyStatus.toUpperCase() === "INREVIEW"){
const user = this.store.snapshot().user.user;
if (user === null || (user !== null && user.userName === permissions.userName)) {
request = request.clone({
Expand Down

0 comments on commit a156c91

Please sign in to comment.