Skip to content

Commit

Permalink
fix(project): bug fix in project member management (DSP-1563) (#425)
Browse files Browse the repository at this point in the history
* fix(project): add user to project

* fix(project): store project in cache as ReadProject

* refactor(project): no need for project cache in user form
  • Loading branch information
kilchenmann committed Apr 22, 2021
1 parent 5b39ad3 commit ac820dd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/app/project/collaboration/add-user/add-user.component.ts
Expand Up @@ -7,6 +7,7 @@ import {
KnoraApiConnection,
MembersResponse,
ProjectResponse,
ReadProject,
ReadUser,
UserResponse,
UsersResponse
Expand Down Expand Up @@ -298,9 +299,9 @@ export class AddUserComponent implements OnInit {

// get project iri by projectcode
this._cache.get(this.projectcode).subscribe(
(p: ApiResponseData<ProjectResponse>) => {
(p: ReadProject) => {
// add user to project
this._dspApiConnection.admin.usersEndpoint.addUserToProjectMembership(this.selectedUser.id, p.body.project.id).subscribe(
this._dspApiConnection.admin.usersEndpoint.addUserToProjectMembership(this.selectedUser.id, p.id).subscribe(
(userAdded: ApiResponseData<UserResponse>) => {

// successful post
Expand Down
6 changes: 4 additions & 2 deletions src/app/project/project-form/project-form.component.ts
Expand Up @@ -509,10 +509,12 @@ export class ProjectFormComponent implements OnInit {
this.loading = true;
// update the cache
this._cache.del(this.projectcode);
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode).subscribe(
(response: ApiResponseData<ProjectResponse>) => {
this.project = response.body.project;

this._cache.set(this.projectcode, this.project);

this.buildForm(this.project);
window.location.reload();
this.loading = false;
Expand Down
9 changes: 4 additions & 5 deletions src/app/user/user-form/user-form.component.ts
Expand Up @@ -7,6 +7,7 @@ import {
Constants,
KnoraApiConnection,
ProjectResponse,
ReadProject,
ReadUser,
StringLiteral,
UpdateUserRequest,
Expand Down Expand Up @@ -422,14 +423,12 @@ export class UserFormComponent implements OnInit, OnChanges {
if (this.projectcode) {
// if a projectcode exists, add the user to the project
// get project iri by projectcode
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
(res: ApiResponseData<ProjectResponse>) => {
this._cache.get(this.projectcode).subscribe(
(res: ReadProject) => {
// add user to project
this._dspApiConnection.admin.usersEndpoint.addUserToProjectMembership(this.user.id, res.body.project.id).subscribe(
this._dspApiConnection.admin.usersEndpoint.addUserToProjectMembership(this.user.id, res.id).subscribe(
() => {
// update project cache and member of project cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));
this._cache.get('members_of_' + this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectMembersByShortcode(this.projectcode));
this.closeDialog.emit(this.user);
this.loading = false;
Expand Down

0 comments on commit ac820dd

Please sign in to comment.