Description
Is there a way to replace existing role for the user or remove all roles and add a new one? I found an API that would allow me to add role to a user. But, I can’t find a way to remove old role before adding a new one.
https://developer.rocket.chat/api/rest-api/methods/roles/addusertorole
How can I replace current user’s role?
Hi.
Hmm - Can’t see one.
I can see they recently introduced this though not sure there an endpoint for it yet.
removeRolesByTeamIdAndUserId(teamId: string, userId: string, roles: Array<string>): Promise<UpdateWriteOpResult> {
import { Collection, FindOneOptions, Cursor, InsertOneWriteOpResult, UpdateWriteOpResult, DeleteWriteOpResultObject, FilterQuery } from 'mongodb';
import { BaseRaw } from './BaseRaw';
import { ITeamMember } from '../../../../definition/ITeam';
import { IUser } from '../../../../definition/IUser';
type T = ITeamMember;
export class TeamMemberRaw extends BaseRaw<T> {
constructor(
public readonly col: Collection<T>,
public readonly trash?: Collection<T>,
) {
super(col, trash);
this.col.createIndexes([
{ key: { teamId: 1 } },
]);
// teamId => userId should be unique
this.col.createIndex({ teamId: 1, userId: 1 }, { unique: true });
This file has been truncated. show original
I guess the risk is trying to remove a role with users still in it.
You could add a feature request.