Skip to content

Commit

Permalink
Merge pull request #136 from wri/fix/context-menu-for-backend-admins
Browse files Browse the repository at this point in the history
fix context menu for backend admins
  • Loading branch information
tsubik authored Sep 17, 2024
2 parents 32973d9 + 8d0c7cc commit 717c821
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: wri/fti_api
ref: develop
ref: master
path: otp_api

- name: Save OTP API Commit SHA
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
run: yarn cypress run

- name: Uploading Test Artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: e2e-tests-artifacts
Expand Down
20 changes: 6 additions & 14 deletions src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,18 @@ export class AuthService {
const response = await this.http.get(`${environment.apiUrl}/users/current-user`).toPromise() as any;
const relationships = response.data.relationships;
const userPermissions = (response.included || []).find(i => i.type === 'user-permissions');

this.userId = response.data.id;
this.userRole = userPermissions && userPermissions.attributes['user-role'];
this.qc1ObserverIds = (response.data.attributes['qc1-observer-ids'] || []).map((d) => d.toString());
this.qc2ObserverIds = (response.data.attributes['qc2-observer-ids'] || []).map((d) => d.toString());
const userObserverId = relationships.observer.data && relationships.observer.data.id;
// TODO: remove this we don't need it anymore
// const managedObserverIds = (response.data.attributes['managed-observer-ids'] || []).map((d) => d.toString());
const managedObserverIds = [];
if (this.isBackendAdmin()) {
await this.observersService.getAll({ sort: 'name' }).then(data => {
//set all observers as available
managedObserverIds.push(...data.map(o => o.id));
});
}
const allManagedOberverIds = uniq([userObserverId, ...managedObserverIds].filter(x => x));
const availableObserverIds = uniq([...allManagedOberverIds, ...this.qc1ObserverIds, ...this.qc2ObserverIds].filter(x => x));
const savedUserObserverId = parseInt(localStorage.getItem('userObserverId'), 10);
Expand All @@ -127,17 +130,6 @@ export class AuthService {
} else {
this.userObserverId = availableObserverIds[0];
}

// if user is backend admin and has no observer context saved in localstorage
// take the first observer id
if (!this.userObserverId && this.isBackendAdmin()) {
await this.observersService.getAll({ sort: 'name' }).then(data => {
//set all observers as available
this.managedObserverIds = data.map(o => o.id);
this.availableObserverIds = data.map(o => o.id);
this.userObserverId = data[0].id;
});
}
this.userCountryId = relationships.country && relationships.country.data && relationships.country.data.id;

await this.setObserverCountriesIds();
Expand Down

0 comments on commit 717c821

Please sign in to comment.