1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 00:25:17 +00:00

Completed advanced info

This commit is contained in:
2019-12-28 14:29:00 +01:00
parent d1ea274281
commit 92723b487a
3 changed files with 74 additions and 3 deletions

View File

@ -57,4 +57,27 @@ export class FriendsHelper {
}
}) > 0;
}
/**
* Check out whether friendship allows to create posts or not
*
* @param userID User wishing to create a post
* @param targetID Target user ID
*/
public static async CanPostTexts(userID: number, targetID: number) : Promise<boolean> {
const result = await DatabaseHelper.QueryRow({
table: FRIENDS_TABLE,
where: {
ID_personne: targetID,
ID_amis: userID,
actif: 1
},
fields: ["autoriser_post_page"]
});
if(result == null)
return false;
return result["autoriser_post_page"] == 1;
}
}

View File

@ -125,6 +125,50 @@ export class UserHelper {
return (await this.GetUserInfo(userID)).pageStatus;
}
/**
* Check out whether a user allows posts from his
* friends on his page or not
*
* This is a convenience method
*
* @param userID Target user ID
*/
private static async AllowPostsOnHisPage(userID: number) : Promise<boolean> {
return (await this.GetUserInfo(userID)).allowPostsFromFriends;
}
/**
* Check out whether a user can create a post on another user
* page
*
* @param userID The user who wish to create a post
* @param targetID The target page
*/
public static async CanCreatePosts(userID: number, targetID: number) {
// User MUST be signed in
if(userID < 1)
return false;
// A user can always create posts on his page
if(userID == targetID) return true;
// User must be able to see the page
if(!await this.CanSeeUserPage(userID, targetID))
return false;
//Check if the user allow posts on his page
if(!await this.AllowPostsOnHisPage(targetID))
return false;
//Check if the friendship of the user allows him to create posts
if(!await FriendsHelper.CanPostTexts(userID, targetID))
return false;
// yes by default
return true;
}
private static async DbToUser(row: any) : Promise<User> {
return new User({