Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/backend/src/datasources/UserDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface UserDataSource {
): Promise<number>;
update(user: UpdateUserByIdArgs): Promise<User>;
setUserRoles(id: number, roles: number[]): Promise<void>;
removeUserRoles(id: number, roles: number[]): Promise<void>;
setUserNotPlaceholder(id: number): Promise<User | null>;
checkScientistToProposal(
userId: number,
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/datasources/mockups/UserDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ export class UserDataSourceMock implements UserDataSource {
async setUserRoles(id: number, roles: number[]): Promise<void> {
// Do something here or remove the function.
}
async removeUserRoles(id: number): Promise<void> {
return;
}
Comment on lines +478 to +480

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We are not mocking any thing here

async getUserRoles(id: number): Promise<Role[]> {
if (id == dummyUserOfficer.id) {
return [
Expand Down
6 changes: 6 additions & 0 deletions apps/backend/src/datasources/postgres/UserDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ export default class PostgresUserDataSource implements UserDataSource {
});
}

async removeUserRoles(id: number): Promise<void> {
return database.transaction(async (trx) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We may be missing await

await trx<RoleUserRecord>('role_user').where('user_id', id).del();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may leave some one with out any assigned role do not we need to leave at least the user role

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This will only remove the roles assigned in the role)user table all UOWS assigned roles will still be there and we give everyone at least one role from UOWS right?

});
}

async me(id: number): Promise<User | null> {
return database
.select()
Expand Down
12 changes: 11 additions & 1 deletion apps/backend/src/datasources/stfc/StfcUserDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ export class StfcUserDataSource implements UserDataSource {
(roleId) => !assignedRoleIds.has(roleId) && roleId !== userRole?.id
);

if (newRolesToAssign.length > 0) {
if (newRolesToAssign.length == 0) {
this.removeUserRoles(id);
this.stfcRolesCache.remove(String(id));
this.uopRolesCache.remove(String(id));
} else if (newRolesToAssign.length > 0) {
await postgresUserDataSource.setUserRoles(id, newRolesToAssign);
this.stfcRolesCache.remove(String(id));
this.uopRolesCache.remove(String(id));
Expand Down Expand Up @@ -522,6 +526,12 @@ export class StfcUserDataSource implements UserDataSource {
throw new Error('Method not implemented.');
}

async removeUserRoles(id: number): Promise<void> {
await postgresUserDataSource.removeUserRoles(id);

return;
}
Comment on lines +529 to +533

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We may need to pass this to the super class or implement it.


async me(id: number) {
return this.getUser(id);
}
Expand Down
Loading