@zextras/carbonio-shell-ui
Version:
The Zextras Carbonio web client
156 lines • 9.98 kB
JavaScript
;
/*
* SPDX-FileCopyrightText: 2021 Zextras <https://www.zextras.com>
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEditSettingsForApp = exports.editSettings = void 0;
const carbonio_ui_soap_lib_1 = require("@zextras/carbonio-ui-soap-lib");
const lodash_1 = require("lodash");
const constants_1 = require("../constants");
const account_1 = require("../store/account");
/**
* @deprecated Use a specific soap fetch request per module instead.
*
* The edit settings function is performing a xml request which leads to network errors due to
* the content, and it is highly linking shell with modules.
* When the data are not related to the account, the management of the settings should be internal
* to the module itself. When the data to update are something strictly related to the account, and
* are or might be useful to other modules, the network update should be performed by the module itself,
* and then be propagated to other modules, to let every module interested in those data to react to the update.
*
* See SHELL-226, SHELL-222 to see how to propagate the update of settings to all other modules.
*/
const editSettings = (mods, appId = constants_1.SHELL_APP_ID) => (0, carbonio_ui_soap_lib_1.legacyXmlSoapFetch)('Batch', `<BatchRequest xmlns="urn:zimbra" onerror="stop">${mods.props
? `<ModifyPropertiesRequest xmlns="urn:zimbraAccount">${(0, lodash_1.map)(mods.props, (prop, key) => `<prop name="${key}" zimlet="${prop.app ?? appId}">${prop.value}</prop>`)}</ModifyPropertiesRequest>`
: ''}${mods.prefs
? `<ModifyPrefsRequest xmlns="urn:zimbraAccount">${(0, lodash_1.map)(mods.prefs, (pref, key) => (0, lodash_1.isArray)(pref)
? (0, lodash_1.map)(pref, (p) => `<pref name="${key}">${p}</pref>`).join('')
: `<pref name="${key}">${pref}</pref>`).join('')}</ModifyPrefsRequest>`
: ''}${mods.identity?.modifyList
? (0, lodash_1.map)(mods.identity.modifyList, (item) => `<ModifyIdentityRequest xmlns="urn:zimbraAccount" requestId="0"><identity id="${item.id}">${(0, lodash_1.map)(item.prefs, (value, key) => `<a name="${key}">${value}</a>`).join('')}</identity></ModifyIdentityRequest>`).join('')
: ''}${mods.identity?.deleteList
? (0, lodash_1.map)(mods.identity.deleteList, (item) => `<DeleteIdentityRequest xmlns="urn:zimbraAccount" requestId="0"><identity id="${item}"/></DeleteIdentityRequest>`).join('')
: ''}${mods.identity?.createList
? (0, lodash_1.map)(mods.identity.createList, (item, index) => `<CreateIdentityRequest xmlns="urn:zimbraAccount" requestId="${index}"><identity name="${item.prefs.zimbraPrefIdentityName}"><a name="zimbraPrefIdentityName">${item.prefs.zimbraPrefIdentityName}</a><a name="zimbraPrefFromDisplay">${item.prefs.zimbraPrefFromDisplay}</a><a name="zimbraPrefFromAddress">${item.prefs.zimbraPrefFromAddress}</a><a name="zimbraPrefFromAddressType">sendAs</a><a name="zimbraPrefReplyToEnabled">${item.prefs.zimbraPrefReplyToEnabled}</a><a name="zimbraPrefReplyToDisplay">${item.prefs.zimbraPrefReplyToDisplay}</a><a name="zimbraPrefReplyToAddress">${item.prefs.zimbraPrefReplyToAddress}</a><a name="zimbraPrefDefaultSignatureId">${item.prefs.zimbraPrefDefaultSignatureId}</a><a name="zimbraPrefForwardReplySignatureId">${item.prefs.zimbraPrefForwardReplySignatureId}</a><a name="zimbraPrefWhenSentToEnabled">${item.prefs.zimbraPrefWhenSentToEnabled}</a><a name="zimbraPrefWhenInFoldersEnabled">${item.prefs.zimbraPrefWhenInFoldersEnabled}</a></identity></CreateIdentityRequest>`).join('')
: ''}${mods.permissions
? `<RevokeRightsRequest xmlns="urn:zimbraAccount" requestId="0">${mods.permissions.freeBusy
? (0, lodash_1.map)(mods.permissions.freeBusy.current, (right) => {
if (right.gt === 'dom')
return `<ace right="viewFreeBusy" gt="${right.gt}" zid="${right.zid}" d="zextras.com"/>`;
if (right.gt === 'all' && right.deny)
return `<ace right="viewFreeBusy" gt="${right.gt}" zid="${right.zid}" deny="1"/>`;
if (right.gt === 'usr')
return `<ace right="viewFreeBusy" gt="${right.gt}" zid="${right.zid}" d="${right.d}"/>`;
return `<ace right="viewFreeBusy" gt="${right.gt}" zid="${right.zid}" />`;
}).join('')
: ''}${mods.permissions.inviteRight
? (0, lodash_1.map)(mods.permissions.inviteRight.current, (right) => {
if (right.gt === 'all' && right.deny)
return `<ace right="invite" gt="${right.gt}" zid="${right.zid}" deny="1"/>`;
if (right.gt === 'usr')
return `<ace right="invite" gt="${right.gt}" zid="${right.zid}" d="${right.d}"/>`;
return `<ace right="invite" gt="${right.gt}" zid="${right.zid}" />`;
}).join('')
: ''}</RevokeRightsRequest><GrantRightsRequest xmlns="urn:zimbraAccount" requestId="1">${mods.permissions.freeBusy
? `${(() => {
if (mods.permissions.freeBusy.new.gt === 'dom') {
return `<ace right="viewFreeBusy" gt="${mods.permissions.freeBusy.new.gt}" d="zextras.com"/>`;
}
if (mods.permissions.freeBusy.new.gt === 'all' &&
mods.permissions.freeBusy.new.deny) {
return `<ace right="viewFreeBusy" gt="${mods.permissions.freeBusy.new.gt}" deny="1"/>`;
}
if (mods.permissions.freeBusy.new.gt === 'usr') {
return (0, lodash_1.map)(mods.permissions.freeBusy.new.d, (u) =>
// FIXME: usage differs from the declaration of the AccountACE
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
`<ace right="viewFreeBusy" gt="${mods.permissions?.freeBusy.new.gt}" d="${u.email}"/>`).join('');
}
return `<ace right="viewFreeBusy" gt="${mods.permissions.freeBusy.new.gt}" />`;
})()}`
: ''}${mods.permissions.inviteRight
? `${(() => {
if (mods.permissions.inviteRight.new.gt === 'all' &&
mods.permissions.inviteRight.new.deny) {
return `<ace right="invite" gt="${mods.permissions.inviteRight.new.gt}" deny="1"/>`;
}
if (mods.permissions.inviteRight.new.gt === 'usr') {
return (0, lodash_1.map)(mods.permissions.inviteRight.new.d, (u) =>
// FIXME: usage differs from the declaration of the AccountACE
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
`<ace right="invite" gt="${mods.permissions?.inviteRight.new.gt}" d="${u.email}"/>`).join('');
}
return `<ace right="invite" gt="${mods.permissions?.inviteRight.new.gt}" />`;
})()}`
: ''}
</GrantRightsRequest>`
: ''}</BatchRequest>`).then((r) => {
account_1.useAccountStore.setState((s) => ({
settings: {
...s.settings,
prefs: (0, lodash_1.reduce)(mods.prefs, (acc, pref, key) => ({
...acc,
[key]: pref
}), s.settings.prefs),
props: (0, lodash_1.reduce)(mods.props, (acc, { app, value }, key) => {
const propIndex = (0, lodash_1.findIndex)(acc, (p) => p.name === key && p.zimlet === app);
if (propIndex >= 0) {
// eslint-disable-next-line no-param-reassign
acc[propIndex] = {
name: key,
zimlet: app,
_content: value
};
}
else {
acc.push({
name: key,
zimlet: app,
_content: value
});
}
return acc;
}, s.settings.props)
},
account: {
...s.account,
displayName: (0, lodash_1.find)(mods?.identity?.modifyList, (item) => item.id === s?.account?.id)?.prefs
.zimbraPrefIdentityName || s.account?.displayName,
identities: {
identity: typeof s.account !== 'undefined'
? (0, lodash_1.reduce)(mods?.identity?.modifyList, (acc, { id, prefs }) => {
const propIndex = (0, lodash_1.findIndex)(acc, (itemMods, indexAccount) => acc[indexAccount].id === id);
if (propIndex > -1) {
// eslint-disable-next-line no-param-reassign
acc[propIndex]._attrs = {
...acc[propIndex]._attrs,
...prefs
};
if (prefs.zimbraPrefIdentityName && acc[propIndex].name !== 'DEFAULT') {
// eslint-disable-next-line no-param-reassign
acc[propIndex].name = prefs.zimbraPrefIdentityName;
}
}
return acc;
}, [
...(0, lodash_1.filter)(s.account.identities.identity, (item) => !mods?.identity?.deleteList?.includes(item.id)).filter((i) => i.name !== 'DEFAULT'),
...(0, lodash_1.map)(r?.CreateIdentityResponse, (item) => item.identity[0]),
...(0, lodash_1.filter)(s.account.identities.identity, (item) => !mods?.identity?.deleteList?.includes(item.id)).filter((i) => i.name === 'DEFAULT')
])
: undefined
}
}
}));
return r;
});
exports.editSettings = editSettings;
const getEditSettingsForApp = (app) => (mods) => (0, exports.editSettings)(mods, app).then((r) => ({
...r,
type: 'fulfilled'
}));
exports.getEditSettingsForApp = getEditSettingsForApp;
//# sourceMappingURL=edit-settings.js.map