diff --git a/src/controllers/GroupsController.ts b/src/controllers/GroupsController.ts index a7c2b75..4f9b93e 100644 --- a/src/controllers/GroupsController.ts +++ b/src/controllers/GroupsController.ts @@ -140,7 +140,7 @@ export class GroupsController { */ private static async GroupInfoToAPI(info: GroupInfo, h: RequestHandler, advanced: boolean = false) : Promise { - const membership = await GroupsHelper.GetMembershipInfo(info.id, h.getUserId()) + const membership = await GroupsHelper.GetMembershipInfo(info.id, h.optionnalUserID) const data = { id: info.id, diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index 5ccc318..61174a2 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -93,5 +93,5 @@ export const Routes : Route[] = [ {path: "/groups/get_multiple_info", cb: (h) => GroupsController.GetInfoMultiple(h)}, - {path: "/groups/get_advanced_info", cb: (h) => GroupsController.GetAdvancedInfo(h)}, + {path: "/groups/get_advanced_info", cb: (h) => GroupsController.GetAdvancedInfo(h), needLogin: false}, ] \ No newline at end of file diff --git a/src/entities/RequestHandler.ts b/src/entities/RequestHandler.ts index 8baf22b..fd89973 100644 --- a/src/entities/RequestHandler.ts +++ b/src/entities/RequestHandler.ts @@ -222,7 +222,7 @@ export class RequestHandler { public async postGroupIDWithAccess(name: string, minVisibility : GroupsAccessLevel) : Promise { const groupID = await this.postGroupID(name); - const access = await GroupsHelper.GetAccessLevel(groupID, this.getUserId()); + const access = await GroupsHelper.GetAccessLevel(groupID, this.optionnalUserID); if(access == GroupsAccessLevel.NO_ACCESS) this.error(404, "Specified group not found!"); @@ -369,6 +369,14 @@ export class RequestHandler { return this.userID; } + /** + * Get the ID of the current user (if any) + * or 0 if the user is not signed in + */ + public get optionnalUserID(): number { + return this.userID >= 1 ? this.userID : 0; + } + /** * Check out whether user is signed in or not */ diff --git a/src/helpers/GroupsHelper.ts b/src/helpers/GroupsHelper.ts index 0368dd1..92919dc 100644 --- a/src/helpers/GroupsHelper.ts +++ b/src/helpers/GroupsHelper.ts @@ -204,6 +204,10 @@ export class GroupsHelper { * @returns Membership info / null if none found */ public static async GetMembershipInfo(groupID: number, userID: number): Promise { + + if(userID == 0) + return null; + const data = await DatabaseHelper.QueryRow({ table: GROUPS_MEMBERS_TABLE, where: {