Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Commit fb7cf32

Browse files
committed
feat: Filter out disabled users in search and retrieval methods in UserController
1 parent 7c0c679 commit fb7cf32

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

dist/controllers/UserController.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,12 @@ let Users = class Users {
478478
return this.sendError(res, 400, "Missing search query");
479479
}
480480
try {
481-
const users = await this.userService.searchUsersByUsername(query);
481+
// Only return non-disabled users (assume disabled is present if returned from service)
482+
const usersRaw = await this.userService.searchUsersByUsername(query);
483+
const users = usersRaw.filter(user => {
484+
// Accept if disabled is not present or is falsy
485+
return !("disabled" in user) || !user["disabled"];
486+
});
482487
await this.createLog(req, "searchUsers", "users", 200);
483488
res.send(users.map((user) => this.mapUserSearch(user)));
484489
}
@@ -497,7 +502,8 @@ let Users = class Users {
497502
}
498503
const { userId } = req.params;
499504
const userWithData = await this.userService.getUserWithPublicProfile(userId);
500-
if (!userWithData) {
505+
// Only allow non-disabled users
506+
if (!userWithData || ("disabled" in userWithData && userWithData["disabled"])) {
501507
await this.createLog(req, "getUser", "users", 404);
502508
return this.sendError(res, 404, "User not found");
503509
}
@@ -869,7 +875,7 @@ __decorate([
869875
},
870876
example: "GET /api/users/123",
871877
}),
872-
(0, inversify_express_utils_1.httpGet)("/:userId"),
878+
(0, inversify_express_utils_1.httpGet)(":userId"),
873879
__metadata("design:type", Function),
874880
__metadata("design:paramtypes", [Object, Object]),
875881
__metadata("design:returntype", Promise)

dist/interfaces/User.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ export interface Oauth2User {
5050
discord_id?: string;
5151
google_id?: string;
5252
}
53+
export interface Friend {
54+
user_1: string;
55+
user_2: string;
56+
datetime?: string;
57+
status: 'pending' | 'approved';
58+
}

src/controllers/UserController.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,12 @@ export class Users {
542542
return this.sendError(res, 400, "Missing search query");
543543
}
544544
try {
545-
const users: PublicUser[] = await this.userService.searchUsersByUsername(query);
545+
// Only return non-disabled users (assume disabled is present if returned from service)
546+
const usersRaw = await this.userService.searchUsersByUsername(query);
547+
const users = usersRaw.filter(user => {
548+
// Accept if disabled is not present or is falsy
549+
return !("disabled" in user) || !user["disabled"];
550+
});
546551
await this.createLog(req, "searchUsers", "users", 200);
547552
res.send(users.map((user) => this.mapUserSearch(user)));
548553
} catch (error) {
@@ -571,7 +576,7 @@ export class Users {
571576
},
572577
example: "GET /api/users/123",
573578
})
574-
@httpGet("/:userId")
579+
@httpGet(":userId")
575580
public async getUser(req: Request, res: Response) {
576581
try {
577582
await userIdParamValidator.validate(req.params);
@@ -581,7 +586,8 @@ export class Users {
581586
}
582587
const { userId } = req.params;
583588
const userWithData = await this.userService.getUserWithPublicProfile(userId);
584-
if (!userWithData) {
589+
// Only allow non-disabled users
590+
if (!userWithData || ("disabled" in userWithData && userWithData["disabled"])) {
585591
await this.createLog(req, "getUser", "users", 404);
586592
return this.sendError(res, 404, "User not found");
587593
}

0 commit comments

Comments
 (0)