Source

auth/view-as-actions.js

const CANCEL = 'auth/viewAs/CANCEL';
const CLOSE = 'auth/viewAs/CLOSE';
const CLEAR = 'auth/viewAs/CLEAR';
const REFRESH = 'auth/viewAs/REFRESH';
const SHOW = 'auth/viewAs/SHOW';
const SET_DATA = 'auth/viewAs/SET_DATA';
const SET_STAGED_DATA = 'auth/viewAs/SET_STAGED_DATA';
const CHANGE_PRISTINE_STATE = 'auth/viewAs/CHANGE_PRISTINE_STATE';

/**
 * Allows dynamically to apply permissions for the specific role or user on CI level.
 * It helps to admin user to see what user or role can do in the system.
 *
 * @module auth/viewAs
 */
export default {
    CANCEL,
    /**
     * Rejects all pending changes and closes popup.
     * @property {string} type - CANCEL
     */
    cancel: () => ({type: CANCEL}),
    CHANGE_PRISTINE_STATE,
    /**
     * Changes the pristinity state of opened "View as" popup.
     * Visually it is represented by asterisk on the title of modal dialog.
     * If pristinity is false and user clicks on "Cancel", first confirmation will be asked before changes be lost.
     *
     * @param {boolean} pristine - the new pristinity value
     * @property {string} type - CHANGE_PRISTINE_STATE
     */
    changePristineState: (pristine) => ({
        pristine,
        type: CHANGE_PRISTINE_STATE
    }),
    CLEAR,
    /**
     * Removes selected role or user.
     * What means that no permissions filtering happens anymore on CI level.
     * @property {string} type - CLEAR
     */
    clear: () => ({type: CLEAR}),
    CLOSE,
    /**
     * Closes view as popup, changes pristinity to true.
     * There is no check performed before closing popup whether user has pending changes or not.
     * Use {cancel} for that.
     * @property {string} type - CLOSE
     */
    close: () => ({type: CLOSE}),
    REFRESH,
    /**
     * Applies permissions on CIs based on selected user/roles.
     * @param {object} data - Object which contains selected user or roles. Represented as
     * {user, roles}, where user is string and roles - array of strings.
     *
     * Only one of fields should be defined.
     * @property {string} type - REFRESH
     */
    refresh: (data) => ({
        data,
        type: REFRESH
    }),
    SET_DATA,
    SET_STAGED_DATA,
    /**
     * Saves selected user or roles.
     *
     * @param {object} data - Object which contains selected user or roles. Represented as
     * {user, roles}, where user is string and roles - array of strings.
     * @property {string} type - SET_DATA
     */
    setData: (data) => ({
        data,
        type: SET_DATA
    }),
    SHOW,
    /**
     * Opens a "View as" modal dialog.
     * @property {string} type - SHOW
     */
    show: () => ({type: SHOW}),
    /**
     * Saves typed in user's information in "View as" modal dialog but which is not saved yet.
     *
     * @param {object} data - Object which contains selected user or roles. Represented as
     * {user, roles}, where user is string and roles - array of strings.
     * @property {string} type - SET_STAGED_DATA
     */
    stageData: (data) => ({
        data,
        type: SET_STAGED_DATA
    })
};