Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: make deactivated projects invisible for all except sysadmin (DEV…
…-1261) (#821)

* fix: remove deactivated projects from overview of users except sysadmin

* adjust tests

* adjust tests even more

* fix tests
  • Loading branch information
mpro7 committed Sep 13, 2022
1 parent 45cf268 commit 88a2cbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/app/user/overview/overview.component.spec.ts
Expand Up @@ -143,6 +143,7 @@ describe('OverviewComponent', () => {
anythingProj.shortcode = '0001';
anythingProj.keywords = ['arbitrary test data', 'things'];
anythingProj.shortname = 'anything';
anythingProj.status = true;

// add project to list of users projects
loggedInUser.body.user.projects = [anythingProj];
Expand Down Expand Up @@ -272,7 +273,7 @@ describe('OverviewComponent', () => {

it('should populate project lists correctly', () => {
expect(testHostComponent.overviewComp.userProjects.length).toEqual(0);
expect(testHostComponent.overviewComp.otherProjects.length).toEqual(8);
expect(testHostComponent.overviewComp.otherProjects.length).toEqual(7);
});

it('should NOT show the "Create new project" button', async () => {
Expand Down
18 changes: 13 additions & 5 deletions src/app/user/overview/overview.component.ts
Expand Up @@ -39,7 +39,7 @@ export class OverviewComponent implements OnInit {
this.session = this._session.getSession();

// if session is null, user is not logged in
if(this.session) {
if (this.session) {
this.username = this.session.user.name;
this.sysAdmin = this.session.user.sysAdmin;
}
Expand Down Expand Up @@ -69,7 +69,13 @@ export class OverviewComponent implements OnInit {
this.otherProjects = [];

for (const project of response.body.projects) {
this.otherProjects.push(project);
// for not logged in user don't display deactivated projects
if (!this.session && project.status !== false) {
this.otherProjects.push(project);
}
if (this.sysAdmin) {
this.otherProjects.push(project);
}
}

this.loading = false;
Expand All @@ -87,17 +93,19 @@ export class OverviewComponent implements OnInit {
this.userProjects = [];
this.otherProjects = [];

// get list of all projects the user is a member of
// get list of all projects the user is a member of except the deactivated ones
for (const project of userResponse.body.user.projects) {
this.userProjects.push(project);
if (project.status !== false) {
this.userProjects.push(project);
}
}

this._dspApiConnection.admin.projectsEndpoint.getProjects().subscribe(
(projectsResponse: ApiResponseData<ProjectsResponse>) => {

// get list of all projects the user is NOT a member of
for (const project of projectsResponse.body.projects) {
if(this.userProjects.findIndex(userProj => userProj.id === project.id) === -1){
if (this.userProjects.findIndex(userProj => userProj.id === project.id) === -1) {
this.otherProjects.push(project);
}
}
Expand Down

0 comments on commit 88a2cbd

Please sign in to comment.