mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
170 lines (169 loc) • 6.48 kB
JavaScript
;
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAccessControlPolicy = getAccessControlPolicy;
exports.createAccessControlPolicy = createAccessControlPolicy;
exports.deleteAccessControlPolicy = deleteAccessControlPolicy;
exports.searchAccessControlPolicies = searchAccessControlPolicies;
exports.searchAccessControlPolicyChannels = searchAccessControlPolicyChannels;
exports.assignChannelsToAccessControlPolicy = assignChannelsToAccessControlPolicy;
exports.unassignChannelsFromAccessControlPolicy = unassignChannelsFromAccessControlPolicy;
exports.getAccessControlFields = getAccessControlFields;
exports.searchUsersForExpression = searchUsersForExpression;
exports.getVisualAST = getVisualAST;
exports.validateExpressionAgainstRequester = validateExpressionAgainstRequester;
exports.createAccessControlSyncJob = createAccessControlSyncJob;
exports.updateAccessControlPoliciesActive = updateAccessControlPoliciesActive;
const redux_batched_actions_1 = require("redux-batched-actions");
const action_types_1 = require("mattermost-redux/action_types");
const client_1 = require("mattermost-redux/client");
const helpers_1 = require("./helpers");
function getAccessControlPolicy(id, channelId) {
return (0, helpers_1.bindClientFunc)({
clientFunc: client_1.Client4.getAccessControlPolicy,
onSuccess: [action_types_1.AdminTypes.RECEIVED_ACCESS_CONTROL_POLICY],
params: [
id,
channelId,
],
});
}
function createAccessControlPolicy(policy) {
return async (dispatch, getState) => {
let data;
try {
data = await client_1.Client4.updateOrCreateAccessControlPolicy(policy);
}
catch (error) {
(0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState);
return { error };
}
dispatch({ type: action_types_1.AdminTypes.CREATE_ACCESS_CONTROL_POLICY_SUCCESS, data });
return { data };
};
}
function deleteAccessControlPolicy(id) {
return (0, helpers_1.bindClientFunc)({
clientFunc: client_1.Client4.deleteAccessControlPolicy,
onSuccess: [action_types_1.AdminTypes.DELETE_ACCESS_CONTROL_POLICY_SUCCESS],
params: [
id,
],
});
}
function searchAccessControlPolicies(term, type, after, limit) {
return async (dispatch, getState) => {
let data;
try {
data = await client_1.Client4.searchAccessControlPolicies(term, type, after, limit);
}
catch (error) {
(0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState);
return { error };
}
dispatch({ type: action_types_1.AdminTypes.RECEIVED_ACCESS_CONTROL_POLICIES_SEARCH, data: data.policies });
return { data };
};
}
function searchAccessControlPolicyChannels(id, term, opts) {
return async (dispatch, getState) => {
let data;
try {
data = await client_1.Client4.searchChildAccessControlPolicyChannels(id, term, opts);
}
catch (error) {
(0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState);
return { error };
}
const childs = {};
childs[id] = data.channels.map((channel) => channel.id);
dispatch((0, redux_batched_actions_1.batchActions)([
{ type: action_types_1.AdminTypes.RECEIVED_ACCESS_CONTROL_CHILD_POLICIES, data: childs },
{ type: action_types_1.ChannelTypes.RECEIVED_CHANNELS, data: data.channels },
]));
return { data };
};
}
function assignChannelsToAccessControlPolicy(policyId, channelIds) {
return (0, helpers_1.bindClientFunc)({
clientFunc: client_1.Client4.assignChannelsToAccessControlPolicy,
onSuccess: [action_types_1.AdminTypes.ASSIGN_CHANNELS_TO_ACCESS_CONTROL_POLICY_SUCCESS],
params: [
policyId,
channelIds,
],
});
}
function unassignChannelsFromAccessControlPolicy(policyId, channelIds) {
return (0, helpers_1.bindClientFunc)({
clientFunc: client_1.Client4.unassignChannelsFromAccessControlPolicy,
onSuccess: [action_types_1.AdminTypes.UNASSIGN_CHANNELS_FROM_ACCESS_CONTROL_POLICY_SUCCESS],
params: [
policyId,
channelIds,
],
});
}
function getAccessControlFields(after, limit, channelId) {
return (0, helpers_1.bindClientFunc)({
clientFunc: client_1.Client4.getAccessControlFields,
params: [
after,
limit,
channelId,
],
});
}
function searchUsersForExpression(expression, term, after, limit, channelId) {
return async (dispatch, getState) => {
let data;
try {
data = await client_1.Client4.testAccessControlExpression(expression, term, after, limit, channelId);
}
catch (error) {
(0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState);
return { error };
}
dispatch({ type: action_types_1.UserTypes.RECEIVED_PROFILES, data: data.users });
return { data };
};
}
function getVisualAST(expression, channelId) {
return (0, helpers_1.bindClientFunc)({
clientFunc: client_1.Client4.expressionToVisualFormat,
params: [expression, channelId],
});
}
function validateExpressionAgainstRequester(expression, channelId) {
return async (dispatch, getState) => {
let data;
try {
data = await client_1.Client4.validateExpressionAgainstRequester(expression, channelId);
}
catch (error) {
(0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState);
return { error };
}
return { data };
};
}
function createAccessControlSyncJob(jobData) {
return async (dispatch, getState) => {
let data;
try {
data = await client_1.Client4.createAccessControlSyncJob(jobData);
}
catch (error) {
(0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState);
return { error };
}
return { data };
};
}
function updateAccessControlPoliciesActive(states) {
return (0, helpers_1.bindClientFunc)({
clientFunc: client_1.Client4.updateAccessControlPoliciesActive,
params: [states],
});
}