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 all 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
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