Skip to content

Commit b902933

Browse files
Feature/1511 1414 fix user profile bugs (#219)
* (IOT-1511) Fix userprofiles not showing on details * (IOT-1502) Include permission type when fetching user * (IOT-1502) Updated max values and error text for service profile data rate (#220)
1 parent a77ba57 commit b902933

File tree

6 files changed

+49
-35
lines changed

6 files changed

+49
-35
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,7 @@ export class NewKombitCreationController {
165165
try {
166166
// Don't leak the passwordHash
167167
// eslint-disable-next-line @typescript-eslint/no-unused-vars
168-
const { passwordHash, ...user } = await this.userService.findOne(
169-
id,
170-
getExtendedInfo,
171-
getExtendedInfo
172-
);
168+
const { passwordHash, ...user } = await this.userService.findOne(id, getExtendedInfo);
173169

174170
return user;
175171
} catch (err) {

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

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ import { CreateUserDto } from "@dto/user-management/create-user.dto";
3333
import { UpdateUserDto } from "@dto/user-management/update-user.dto";
3434
import { UserResponseDto } from "@dto/user-response.dto";
3535
import { ErrorCodes } from "@entities/enum/error-codes.enum";
36-
import { checkIfUserIsGlobalAdmin, checkIfUserHasAccessToOrganization, OrganizationAccessScope } from "@helpers/security-helper";
36+
import {
37+
checkIfUserIsGlobalAdmin,
38+
checkIfUserHasAccessToOrganization,
39+
OrganizationAccessScope,
40+
} from "@helpers/security-helper";
3741
import { UserService } from "@services/user-management/user.service";
3842
import { ListAllUsersResponseDto } from "@dto/list-all-users-response.dto";
3943
import { ListAllUsersMinimalResponseDto } from "@dto/list-all-users-minimal-response.dto";
@@ -56,7 +60,7 @@ export class UserController {
5660
constructor(
5761
private userService: UserService,
5862
private organizationService: OrganizationService
59-
) { }
63+
) {}
6064

6165
private readonly logger = new Logger(UserController.name);
6266

@@ -111,7 +115,11 @@ export class UserController {
111115
@Req() req: AuthenticatedRequest,
112116
@Body() body: RejectUserDto
113117
): Promise<Organization> {
114-
checkIfUserHasAccessToOrganization(req, body.orgId, OrganizationAccessScope.UserAdministrationWrite);
118+
checkIfUserHasAccessToOrganization(
119+
req,
120+
body.orgId,
121+
OrganizationAccessScope.UserAdministrationWrite
122+
);
115123

116124
const user = await this.userService.findOne(body.userIdToReject);
117125
const organization = await this.organizationService.findByIdWithUsers(body.orgId);
@@ -130,17 +138,22 @@ export class UserController {
130138
// Verify that we have admin access to the user and that the user is on an organization
131139
const dbUser = await this.userService.findOneWithOrganizations(id);
132140

133-
// Requesting user has to be admin for at least one organization containing the user
141+
// Requesting user has to be admin for at least one organization containing the user
134142
// _OR_ be global admin
135-
if (!req.user.permissions.isGlobalAdmin && !dbUser.permissions.some(perm => req.user.permissions.hasUserAdminOnOrganization(perm.organization.id))) {
143+
if (
144+
!req.user.permissions.isGlobalAdmin &&
145+
!dbUser.permissions.some(perm =>
146+
req.user.permissions.hasUserAdminOnOrganization(perm.organization.id)
147+
)
148+
) {
136149
throw new ForbiddenException();
137-
}
138-
150+
}
151+
139152
// Only a global admin can modify a global admin user
140153
if (dto.globalAdmin) {
141154
checkIfUserIsGlobalAdmin(req);
142155
}
143-
156+
144157
// Don't leak the passwordHash
145158
const { passwordHash: _, ...user } = await this.userService.updateUser(
146159
id,
@@ -176,7 +189,7 @@ export class UserController {
176189
req.user.username
177190
);
178191

179-
return wasOk
192+
return wasOk;
180193
}
181194

182195
@Get("/awaitingUsers")
@@ -232,7 +245,6 @@ export class UserController {
232245
// Don't leak the passwordHash
233246
const { passwordHash: _, ...user } = await this.userService.findOne(
234247
id,
235-
getExtendedInfo,
236248
getExtendedInfo
237249
);
238250

@@ -243,7 +255,10 @@ export class UserController {
243255
}
244256

245257
@Get("organizationUsers/:organizationId")
246-
@ApiOperation({ summary: "Get all users for an organization. Requires UserAdmin priviledges for the specified organization" })
258+
@ApiOperation({
259+
summary:
260+
"Get all users for an organization. Requires UserAdmin priviledges for the specified organization",
261+
})
247262
async findByOrganizationId(
248263
@Req() req: AuthenticatedRequest,
249264
@Param("organizationId", new ParseIntPipe()) organizationId: number,
@@ -252,7 +267,9 @@ export class UserController {
252267
try {
253268
// Check if user has access to organization
254269
if (!req.user.permissions.hasUserAdminOnOrganization(organizationId)) {
255-
throw new ForbiddenException("User does not have org admin permissions for this organization");
270+
throw new ForbiddenException(
271+
"User does not have org admin permissions for this organization"
272+
);
256273
}
257274

258275
// Get user objects

src/entities/dto/chirpstack/service-profile.dto.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ export class ServiceProfileDto {
3232

3333
@ApiProperty({ required: false })
3434
@IsInt()
35-
@Min(0)
36-
@Max(5)
35+
@Min(0, { message: "Max data rate må ikke være negativ" })
36+
@Max(7, { message: "Max data rate må ikke være større end 7" })
3737
drMax?: number;
3838

3939
@ApiProperty({ required: true })
4040
@IsInt()
41-
@Min(0)
42-
@Max(5)
41+
@Min(0, { message: "Min data rate må ikke være negativ" })
42+
@Max(7, { message: "Min data rate må ikke være større end 7" })
4343
drMin?: number;
4444

4545
@ApiProperty({ required: false })

src/entities/dto/list-all-permissions.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ListAllEntitiesDto } from "./list-all-entities.dto";
33

44
export class ListAllPermissionsDto extends ListAllEntitiesDto {
55
@ApiProperty({ type: String, required: false })
6-
organisationId?: number;
6+
organisationId?: string;
77

88
@ApiProperty({ type: String, required: false })
99
userId?: string;

src/services/user-management/permission.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ export class PermissionService {
280280
}
281281
if (orgs) {
282282
qb = qb.andWhere({ organization: In(orgs) });
283-
} else if (query?.organisationId) {
283+
} else if (
284+
query?.organisationId !== undefined &&
285+
query.organisationId !== "undefined"
286+
) {
284287
qb = qb.andWhere("org.id = :orgId", { orgId: +query.organisationId });
285288
}
286289

src/services/user-management/user.service.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class UserService {
3939
@Inject(forwardRef(() => PermissionService))
4040
private permissionService: PermissionService,
4141
private configService: ConfigService,
42-
private oS2IoTMail: OS2IoTMail,
42+
private oS2IoTMail: OS2IoTMail
4343
) {}
4444

4545
private readonly logger = new Logger(UserService.name, { timestamp: true });
@@ -90,17 +90,13 @@ export class UserService {
9090
});
9191
}
9292

93-
async findOne(
94-
id: number,
95-
getPermissionOrganisationInfo = false,
96-
getPermissionUsersInfo = false
97-
): Promise<User> {
93+
async findOne(id: number, getExtendedInformation: boolean = false): Promise<User> {
9894
const relations = ["permissions", "requestedOrganizations"];
99-
if (getPermissionOrganisationInfo) {
95+
96+
if (getExtendedInformation) {
10097
relations.push("permissions.organization");
101-
}
102-
if (getPermissionUsersInfo) {
10398
relations.push("permissions.users");
99+
relations.push("permissions.type");
104100
}
105101

106102
return await this.userRepository.findOne({
@@ -221,7 +217,7 @@ export class UserService {
221217
if (user.nameId != null) {
222218
if (dto.name && user.name != dto.name) {
223219
throw new BadRequestException(ErrorCodes.CannotModifyOnKombitUser);
224-
}
220+
}
225221
if (dto.password) {
226222
throw new BadRequestException(ErrorCodes.CannotModifyOnKombitUser);
227223
}
@@ -352,11 +348,13 @@ export class UserService {
352348
}
353349
const order: "DESC" | "ASC" =
354350
query?.sort?.toLocaleUpperCase() == "DESC" ? "DESC" : "ASC";
355-
351+
356352
const [data, count] = await this.userRepository
357353
.createQueryBuilder("user")
358354
.innerJoin("user.permissions", "p")
359-
.where('"p"."organizationId" = :organizationId', { organizationId: organizationId })
355+
.where('"p"."organizationId" = :organizationId', {
356+
organizationId: organizationId,
357+
})
360358
.take(+query.limit)
361359
.skip(+query.offset)
362360
.orderBy(orderBy, order)

0 commit comments

Comments
 (0)