Skip to content

Commit 1eb3d2c

Browse files
get one with security and removed minimal from org controller
1 parent 52f02c9 commit 1eb3d2c

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/controllers/user-management/new-kombit-creation.controller.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
Param,
2020
ParseIntPipe,
2121
Put,
22-
Query,
2322
Req,
2423
UseGuards,
2524
} from "@nestjs/common";
@@ -35,6 +34,7 @@ import { OrganizationService } from "@services/user-management/organization.serv
3534
import { PermissionService } from "@services/user-management/permission.service";
3635
import { UserService } from "@services/user-management/user.service";
3736
import { ApiAuth } from "@auth/swagger-auth-decorator";
37+
import { checkIfUserHasAccessToUser } from "@helpers/security-helper";
3838

3939
@UseGuards(JwtAuthGuard)
4040
@ApiAuth()
@@ -130,4 +130,31 @@ export class NewKombitCreationController {
130130
throw err;
131131
}
132132
}
133+
134+
@Get(":id")
135+
@ApiOperation({ summary: "Get one user" })
136+
async find(@Req() req: AuthenticatedRequest, @Param("id", new ParseIntPipe()) id: number): Promise<UserResponseDto> {
137+
let dbUser;
138+
139+
try {
140+
dbUser = await this.userService.findOne(id);
141+
} catch (err) {
142+
throw new NotFoundException(ErrorCodes.IdDoesNotExists);
143+
}
144+
145+
try {
146+
checkIfUserHasAccessToUser(req, dbUser);
147+
148+
dbUser.permissions.forEach(perm => {
149+
delete perm.organization;
150+
});
151+
152+
// Don't leak the passwordHash
153+
const { passwordHash: _, ...user } = dbUser;
154+
155+
return user;
156+
} catch (err) {
157+
throw err;
158+
}
159+
}
133160
}

src/controllers/user-management/organization.controller.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,10 @@ export class OrganizationController {
8989
}
9090
}
9191

92-
@Get("minimal")
93-
@ApiOperation({
94-
summary: "Get list of the minimal representation of organizations, i.e. id and name.",
95-
})
96-
@Read()
97-
async findAllMinimal(): Promise<ListAllMinimalOrganizationsResponseDto> {
98-
return await this.organizationService.findAllMinimal();
99-
}
100-
101-
findAll(
92+
@Get()
93+
@ApiOperation({ summary: "Get list of all Organizations" })
94+
@UserAdmin()
95+
async findAll(
10296
@Req() req: AuthenticatedRequest,
10397
@Query() query?: ListAllEntitiesDto
10498
): Promise<ListAllOrganizationsResponseDto> {

0 commit comments

Comments
 (0)