ComunicWeb/assets/js/components/groups/utils.js

61 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2018-07-07 13:27:27 +00:00
/**
* Groups utilities
*
* @author Pierre HUBERT
*/
ComunicWeb.components.groups.utils = {
/**
* Extract users ids from members list
*
* @param {Array} list The list of members to process
* @return {Array} The list of the IDs of the members of group
*/
getMembersIDs: function(list){
var IDs = [];
//Process the list of IDs
list.forEach(function(member){
IDs.push(member.user_id);
});
return IDs;
},
2018-07-19 12:34:19 +00:00
/**
* Check whether a user is a member (or more) of a group or not
*
* @param {Object} info Information about the target group
* @return {boolean} TRUE if the user is a member of the group
* FALSE else
*/
isGroupMember: function(info){
return info.membership == "member"
|| info.membership == "moderator"
|| info.membership == "administrator";
},
/**
* Check whether a user can create posts for a group or not
*
* @param {Object} info Information about the target group
* @return {boolean} TRUE if the user can create a post / FALSE else
*/
canCreatePosts: function(info){
//Administrator and moderators can always create posts
if(info.membership == "administrator" || info.membership == "moderator")
return true;
if(info.membership == "member" && info.posts_level == "members")
return true;
//In all the other case, the user can not create posts
return false;
},
2018-07-07 13:27:27 +00:00
}