Skip to content

Commit

Permalink
Merge pull request #1058 from SciCatProject/SWAP-3281-make-snackbar-i…
Browse files Browse the repository at this point in the history
…nterceptor-configurable

feat: make snackbar notifications configurable
  • Loading branch information
nitrosx authored May 11, 2023
2 parents 1e306bc + 3bebf6f commit ef20c16
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
13 changes: 7 additions & 6 deletions CI/ESS/e2e/config.e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"externalAuthEndpoint": "/auth/msad",
"facility": "ESS",
"loginFacilityLabel": "ESS",
"loginLdapLabel" : "Ldap",
"loginLocalLabel" : "Local",
"loginFacilityEnabled" : true,
"loginLdapEnabled" : true,
"loginLocalEnabled" : true,
"loginLdapLabel": "Ldap",
"loginLocalLabel": "Local",
"loginFacilityEnabled": true,
"loginLdapEnabled": true,
"loginLocalEnabled": true,
"fileColorEnabled": true,
"fileDownloadEnabled": true,
"gettingStarted": null,
Expand Down Expand Up @@ -120,5 +120,6 @@
"shoppingCartEnabled": true,
"shoppingCartOnHeader": true,
"tableSciDataEnabled": true,
"datasetDetailsShowMissingProposalId": false
"datasetDetailsShowMissingProposalId": false,
"notificationInterceptorEnabled": true
}
1 change: 1 addition & 0 deletions src/app/app-config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const appConfig: AppConfig = {
fileserverButtonLabel: "",
datasetDetailsShowMissingProposalId: true,
helpMessages: new HelpMessages(),
notificationInterceptorEnabled: true,
};

describe("AppConfigService", () => {
Expand Down
1 change: 1 addition & 0 deletions src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface AppConfig {
datasetDetailsShowMissingProposalId: boolean;
helpMessages?: HelpMessages;
prefix: string | undefined;
notificationInterceptorEnabled: boolean;
}

@Injectable()
Expand Down
14 changes: 11 additions & 3 deletions src/app/datasets/batch-view/batch-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ export class BatchViewComponent implements OnInit, OnDestroy {
const shouldHaveInfoMessage =
!this.isAdmin &&
this.datasetList.some(
(item) => item.ownerEmail !== this.userProfile.email
(item) =>
item.ownerEmail !== this.userProfile.email &&
!this.userProfile.accessGroups.includes(item.ownerGroup)
);

const disableShareButton =
!this.isAdmin &&
this.datasetList.every(
(item) => item.ownerEmail !== this.userProfile.email
(item) =>
item.ownerEmail !== this.userProfile.email &&
!this.userProfile.accessGroups.includes(item.ownerGroup)
);

const infoMessage = shouldHaveInfoMessage
Expand All @@ -102,7 +106,11 @@ export class BatchViewComponent implements OnInit, OnDestroy {
if (result && result.users && result.users.length > 0) {
this.datasetList.forEach((dataset) => {
// NOTE: If the logged in user is not an owner of the dataset or and not admin then skip sharing.
if (!this.isAdmin && dataset.ownerEmail !== this.userProfile.email) {
if (
(!this.isAdmin && dataset.ownerEmail !== this.userProfile.email) ||
(!this.isAdmin &&
!this.userProfile.accessGroups.includes(dataset.ownerGroup))
) {
return;
}

Expand Down
30 changes: 17 additions & 13 deletions src/app/shared/interceptors/snackbar.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import {
import { Observable, throwError } from "rxjs";
import { catchError, tap } from "rxjs/operators";
import { MatSnackBar } from "@angular/material/snack-bar";
import { AppConfigService } from "app-config.service";

@Injectable()
export class SnackbarInterceptor implements HttpInterceptor {
constructor(private snackBar: MatSnackBar) {}
constructor(private snackBar: MatSnackBar, public config: AppConfigService) {}

intercept(
request: HttpRequest<unknown>,
Expand All @@ -22,10 +23,11 @@ export class SnackbarInterceptor implements HttpInterceptor {
return next.handle(request).pipe(
tap((e) => {
if (
request.method == "POST" ||
request.method == "PUT" ||
request.method == "PATCH" ||
request.method == "DELETE"
this.config.getConfig().notificationInterceptorEnabled &&
(request.method == "POST" ||
request.method == "PUT" ||
request.method == "PATCH" ||
request.method == "DELETE")
) {
if (
e instanceof HttpResponse &&
Expand All @@ -39,14 +41,16 @@ export class SnackbarInterceptor implements HttpInterceptor {
}
}),
catchError((error: HttpErrorResponse) => {
this.snackBar.open(
`Error occurred: ${error.status} ${error.statusText}`,
"close",
{
duration: 3000,
panelClass: "snackbar-error",
}
);
if (this.config.getConfig().notificationInterceptorEnabled) {
this.snackBar.open(
`Error occurred: ${error.status} ${error.statusText}`,
"close",
{
duration: 3000,
panelClass: "snackbar-error",
}
);
}
return throwError(error);
})
);
Expand Down

0 comments on commit ef20c16

Please sign in to comment.