Skip to content

Commit

Permalink
fix(admin-ui): Only check jobs if Admin has ReadSettings permission
Browse files Browse the repository at this point in the history
Fixes #383
  • Loading branch information
michaelbromley committed Jun 29, 2020
1 parent 2c710b9 commit daca6b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable, OnDestroy } from '@angular/core';
import { EMPTY, interval, Observable, of, Subject, Subscription, timer } from 'rxjs';
import { debounceTime, map, mapTo, scan, shareReplay, switchMap } from 'rxjs/operators';

import { JobInfoFragment, JobState } from '../../common/generated-types';
import { JobInfoFragment, JobState, Permission } from '../../common/generated-types';
import { DataService } from '../../data/providers/data.service';

@Injectable({
Expand Down Expand Up @@ -61,12 +61,14 @@ export class JobQueueService implements OnDestroy {
checkForJobs(delay: number = 1000) {
timer(delay)
.pipe(
switchMap(() =>
this.dataService.client.userStatus().mapSingle((data) => data.userStatus.isLoggedIn),
),
switchMap((isLoggedIn) =>
isLoggedIn ? this.dataService.settings.getRunningJobs().single$ : EMPTY,
),
switchMap(() => this.dataService.client.userStatus().mapSingle((data) => data.userStatus)),
switchMap((userStatus) => {
if (userStatus.permissions.includes(Permission.ReadSettings) && userStatus.isLoggedIn) {
return this.dataService.settings.getRunningJobs().single$;
} else {
return EMPTY;
}
}),
)
.subscribe((data) => data.jobs.items.forEach((job) => this.updateJob$.next(job)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnIni
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { BaseDetailComponent } from '@vendure/admin-ui/core';
import { CreateRoleInput, LanguageCode, Permission, Role, UpdateRoleInput } from '@vendure/admin-ui/core';
import { NotificationService } from '@vendure/admin-ui/core';
import { DataService } from '@vendure/admin-ui/core';
import { ServerConfigService } from '@vendure/admin-ui/core';
import {
BaseDetailComponent,
CreateRoleInput,
DataService,
LanguageCode,
NotificationService,
Permission,
Role,
ServerConfigService,
UpdateRoleInput,
} from '@vendure/admin-ui/core';
import { normalizeString } from '@vendure/common/lib/normalize-string';
import { Observable } from 'rxjs';
import { mergeMap, take } from 'rxjs/operators';
Expand Down

0 comments on commit daca6b6

Please sign in to comment.