Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Metauriel committed Oct 17, 2024
1 parent 6971bd7 commit 889c21d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions apps/server/src/modules/school/api/school.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AuthorizationContextBuilder, AuthorizationService } from '@modules/auth
import { Injectable } from '@nestjs/common';
import { PaginationParams } from '@shared/controller';
import { Page, UserDO } from '@shared/domain/domainobject';
import { User } from '@shared/domain/entity';
import { Permission, RoleName, SortOrder } from '@shared/domain/interface';
import { EntityId } from '@shared/domain/types';
import { UserService } from '@src/modules/user';
Expand All @@ -18,7 +19,6 @@ import { SchoolUserListResponse } from './dto/response/school-user.response';
import { SchoolResponseMapper, SystemResponseMapper } from './mapper';
import { SchoolUserResponseMapper } from './mapper/school-user.response.mapper';
import { YearsResponseMapper } from './mapper/years.response.mapper';
import { User } from '@shared/domain/entity';

@Injectable()
export class SchoolUc {
Expand Down Expand Up @@ -146,8 +146,7 @@ export class SchoolUc {

this.checkHasPermissionToAccessTeachers(user);

const authContext = AuthorizationContextBuilder.read([Permission.TEACHER_LIST]);
const isUserOfSchool = this.authorizationService.hasPermission(user, school, authContext);
const isUserOfSchool = this.isSchoolInternalUser(user, school);

let result: Page<UserDO>;
if (isUserOfSchool) {
Expand All @@ -163,4 +162,10 @@ export class SchoolUc {
private checkHasPermissionToAccessTeachers(user: User) {
this.authorizationService.checkAllPermissions(user, [Permission.TEACHER_LIST]);
}

private isSchoolInternalUser(user: User, school: School): boolean {
const authContext = AuthorizationContextBuilder.read([Permission.TEACHER_LIST]);
const isUserOfSchool = this.authorizationService.hasPermission(user, school, authContext);
return isUserOfSchool;
}
}

0 comments on commit 889c21d

Please sign in to comment.