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

[USH-1539] Collection-editing rights disappear in development after refreshing the mobile app on web #1364

Open
wants to merge 2 commits into
base: mobile-development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,25 @@ export class ChooseCollectionComponent {
});

this.userData$ = this.sessionService.currentUserData$.pipe(untilDestroyed(this));

this.userData$.subscribe((userData) => {
this.userRole = userData.role!;
this.currentUserId = userData.userId;
this.userPermissions = Array.isArray(userData.permissions)
? userData.permissions.join(',')
: userData.permissions!;

this.canManageCollections = this.checkManageCollections(userData);
if (this.userRole && this.userPermissions) {
this.canManageCollections = this.checkManageCollections(userData);
} else {
console.log('Cannot retrieve userRole and permissions');
}
this.initRoles();
});
}

private checkManageCollections(userData: UserInterface): boolean {
if (Array.isArray(userData.permissions!)) {
const hasPermission = userData.permissions!.includes('Manage Collections and Saved Searches');
return hasPermission;
} else {
console.log('User doesnt have the collection management rights');
return false;
}
private checkManageCollections(userData: UserInterface) {
const hasPermission = userData.permissions!.includes('Manage Collections and Saved Searches');
return hasPermission;
}

async ionViewWillEnter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export class CollectionItemComponent {
if (this.userRole === 'admin') {
return true;
}
return this.canManageCollections && this.collection.user_id === this.currentUserId;
return (
this.canManageCollections && String(this.collection.user_id) === String(this.currentUserId)
);
}

public editClickHandle(event: Event): void {
Expand Down
Loading