mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			61 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/**
 | 
						|
 * 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;
 | 
						|
 | 
						|
	},
 | 
						|
 | 
						|
	/**
 | 
						|
	 * 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;
 | 
						|
 | 
						|
	},
 | 
						|
 | 
						|
} |