mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 00:25:17 +00:00
Ready to return advanced information about a user
This commit is contained in:
@ -26,4 +26,20 @@ export class FriendsHelper {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out whether two users are friend or not
|
||||
*
|
||||
* @param userOne First user
|
||||
* @param userTwo Second user
|
||||
*/
|
||||
public static async AreFriend(userOne: number, userTwo: number) : Promise<boolean> {
|
||||
return await DatabaseHelper.Count({
|
||||
table: FRIENDS_TABLE,
|
||||
where: {
|
||||
ID_personne: userOne,
|
||||
ID_amis: userTwo,
|
||||
actif: 1
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { User, UserPageStatus } from "../entities/User";
|
||||
import { DatabaseHelper } from "./DatabaseHelper";
|
||||
import { AccountImageHelper } from "./AccountImageHelper";
|
||||
import { FriendsHelper } from "./FriendsHelper";
|
||||
|
||||
/**
|
||||
* User helper
|
||||
@ -86,6 +87,44 @@ export class UserHelper {
|
||||
return result == null ? -1 : Number(result.ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out whether a user is allowed to access another
|
||||
* user's page
|
||||
*
|
||||
* @param userID The ID of the user making the request
|
||||
* @param targetUser The target user page
|
||||
*/
|
||||
public static async CanSeeUserPage(userID: number, targetUser: number) : Promise<boolean> {
|
||||
|
||||
if(userID == targetUser)
|
||||
return true;
|
||||
|
||||
const visibility = await this.GetVisibility(targetUser);
|
||||
|
||||
// Open page = OK
|
||||
if(visibility == UserPageStatus.OPEN) return true;
|
||||
|
||||
// Else the user must be signed in
|
||||
if(userID <= 0) return false;
|
||||
|
||||
// Public page = OK for signed in users
|
||||
if(visibility == UserPageStatus.PUBLIC) return true;
|
||||
|
||||
// Check if the two users are friend
|
||||
if(!await FriendsHelper.AreFriend(userID, targetUser)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get the visibility level of a user
|
||||
*
|
||||
* @param userID ID of the target user
|
||||
*/
|
||||
private static async GetVisibility(userID: number) : Promise<UserPageStatus> {
|
||||
return (await this.GetUserInfo(userID)).pageStatus;
|
||||
}
|
||||
|
||||
|
||||
private static async DbToUser(row: any) : Promise<User> {
|
||||
return new User({
|
||||
|
Reference in New Issue
Block a user