models/communities/CommunitiesSettings.js

export default class CommunitiesSettings {
    /**
     * Creates a CommunitiesSettings.
     *
     * @constructor CommunitiesSettings
     * @param {Object} settingsMap - Settings parameters
     * @param {Object<number, boolean>} [settingsMap.allowedActions={}] - Allowed actions
     * @param {Object<string, string>} [settingsMap.properties={}] - Properties
     * @param {boolean} [settingsMap.isPrivate=false] - True if is private
     * @param {boolean} [settingsMap.isDiscoverable=false] - True if is discoverable
     * @param {Object<number, number>} [settingsMap.permissions={}] - Permissions
     * @param {string[]} [params.labels=[]] - Labels.
     */
    constructor(settingsMap) {
        this.allowedActions = settingsMap.allowedActions || {};
        this.properties = settingsMap.properties || {};
        this.isDiscoverable = settingsMap.isDiscoverable === true;
        this.isPrivate = settingsMap.isPrivate === true;
        this.permissions = settingsMap.permissions || {};
        this.labels = settingsMap.labels || [];
        Object.freeze(this);
    }

    /**
    * Check if current user is allowed to perform a certain action.
    *
    * @memberof CommunitiesSettings
    * @instance
    * @param {number} action - Action.
    * @return {boolean} - True, if current user is allowed to perform action, false otherwise.
    */
     isActionAllowed(action) {
        return !!this.allowedActions[action];
    }
}