Commit 625fed9d authored by Anthony Jacob's avatar Anthony Jacob
Browse files

prevent changes on admin / demo user

parent f6830be9
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -66,7 +66,9 @@ export class UsersService {
  }

  async update(id: number, dto: UpdateUserDto, updatedById: number) {

    if (id == 1) {
      throw new ConflictException('Cannot update admin user');
    }
    const user = await this.repo.findOne({ where: { id }, relations: ['roles'] });
    if (!user) throw new NotFoundException("User not found");

@@ -122,6 +124,10 @@ export class UsersService {
  }

  async addRole(userId: number, roleName: string, addedById: number) {
    if (userId == 1) {
      throw new ConflictException('Cannot modify admin user');
    }

    const user = await this.repo.findOne({
      where: { id: userId },
      relations: ['roles'],
@@ -144,6 +150,10 @@ export class UsersService {
  }

  async removeRole(userId: number, roleName: string, removedById: number) {
    if (userId == 1) {
      throw new ConflictException('Cannot modify admin user');
    }

    const user = await this.repo.findOne({
      where: { id: userId },
      relations: ['roles'],
@@ -159,11 +169,17 @@ export class UsersService {
  }

  async setEnabled(userId: number, enabled: boolean, updatedById: number) {
    if (userId == 1) {
      throw new ConflictException('Cannot modify admin user');
    }
    await this.repo.update(userId, { enabled, updatedById, updatedAt: new Date() });
    return this.findOne(userId);
  }

  async setForceLogin(userId: number, forceLogin: boolean, updatedById: number) {
    if (userId == 1) {
      throw new ConflictException('Cannot modify admin user');
    }
    await this.repo.update(userId, { forceLogin, updatedById, updatedAt: new Date() });
    return this.findOne(userId);
  }