Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make deactivated projects invisible for all except sysadmin (DEV-1261) #821

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/user/overview/overview.component.spec.ts
Expand Up @@ -168,8 +168,8 @@ describe('OverviewComponent', () => {

it('should populate project lists correctly', () => {

expect(testHostComponent.overviewComp.userProjects.length).toEqual(1);
expect(testHostComponent.overviewComp.otherProjects.length).toEqual(7);
expect(testHostComponent.overviewComp.userProjects.length).toEqual(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this, I would suggest setting the status of the mocked anything project to true and then you don't need to change these numbers and you can ensure that the list of projects the user is a member of still works. You can set the status to true just after line 145.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True that, but only in this test. In the other the number need to be changed. Well written and very easy to understand tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the alternative

expect(testHostComponent.overviewComp.otherProjects.length).toEqual(8);
});
});

Expand Down Expand Up @@ -272,7 +272,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 of 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