Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: include zimbraAllowFromAddress in sender address list #542

Merged
merged 19 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions api-extractor/carbonio-shell-ui.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export type AccountSettings = {
type AccountSettingsAttrs = {
zimbraFeatureOptionsEnabled?: BooleanString;
zimbraIdentityMaxNumEntries?: number;
zimbraMailAlias?: string | Array<string>;
zimbraAllowFromAddress?: string | Array<string>;
[key: string]: string | number | Array<string | number> | undefined;
};

Expand Down Expand Up @@ -1731,11 +1733,11 @@ interface ZimletProp {
// lib/types/account/index.d.ts:38:9 - (ae-forgotten-export) The symbol "Signature" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:43:5 - (ae-forgotten-export) The symbol "AccountRights" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:47:5 - (ae-forgotten-export) The symbol "StringOfLength" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:92:5 - (ae-forgotten-export) The symbol "AccountSettingsAttrs" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:94:5 - (ae-forgotten-export) The symbol "ZimletProp" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:138:5 - (ae-forgotten-export) The symbol "AccountRightTargetEmail" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:143:9 - (ae-forgotten-export) The symbol "AccountRightName" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:144:9 - (ae-forgotten-export) The symbol "AccountRightTarget" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:94:5 - (ae-forgotten-export) The symbol "AccountSettingsAttrs" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:96:5 - (ae-forgotten-export) The symbol "ZimletProp" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:140:5 - (ae-forgotten-export) The symbol "AccountRightTargetEmail" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:145:9 - (ae-forgotten-export) The symbol "AccountRightName" needs to be exported by the entry point lib.d.ts
// lib/types/account/index.d.ts:146:9 - (ae-forgotten-export) The symbol "AccountRightTarget" needs to be exported by the entry point lib.d.ts
// lib/types/apps/index.d.ts:68:5 - (ae-forgotten-export) The symbol "PanelMode" needs to be exported by the entry point lib.d.ts
// lib/types/misc/index.d.ts:75:9 - (ae-forgotten-export) The symbol "SoapPolicy" needs to be exported by the entry point lib.d.ts
// lib/types/misc/index.d.ts:94:5 - (ae-forgotten-export) The symbol "FolderView" needs to be exported by the entry point lib.d.ts
Expand Down
24 changes: 23 additions & 1 deletion src/settings/components/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { dateToGenTime, genTimeToDate, humanFileSize } from './utils';
import { dateToGenTime, genTimeToDate, humanFileSize, asArray } from './utils';
import type { GeneralizedTime } from '../../types/account';

describe('dateToGenTime function', () => {
Expand Down Expand Up @@ -103,3 +103,25 @@ describe('humanFileSize function', () => {
expect(() => humanFileSize(1024 ** 9, undefined)).toThrow('Unsupported inputSize');
});
});

describe('asArray', () => {
beawar marked this conversation as resolved.
Show resolved Hide resolved
it('should return an array when the value is an array', () => {
const result = asArray(['value1', 'value2']);
expect(result).toEqual(['value1', 'value2']);
});

it('should return an array when the value is a single value', () => {
const result = asArray('singleValue');
expect(result).toEqual(['singleValue']);
});

it('should return an empty array when the value is undefined', () => {
const result = asArray(undefined);
expect(result).toEqual([]);
});

it('should return array of numbers', () => {
const result = asArray(123);
expect(result).toEqual([123]);
});
});
39 changes: 30 additions & 9 deletions src/settings/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import type React from 'react';

import type { TFunction } from 'i18next';
import { cloneDeep, filter, findIndex, isArray, isBoolean, reduce, uniq } from 'lodash';
import { cloneDeep, filter, findIndex, isBoolean, reduce, uniq } from 'lodash';

import { BASE_FONT_SIZE, SCALING_LIMIT, SCALING_OPTIONS } from '../../constants';
import type { LocaleDescriptor } from '../../constants/locales';
Expand Down Expand Up @@ -496,13 +496,38 @@ export function defaultAsFirstOrderIdentities(identities: Array<Identity>): Arra
return result;
}

/**
* Wraps a given value in an array if it is not already an array.
*
* @template T - The type of the input value.
* @param {T | T[] | undefined} value - The value to be transformed. Can be a single value of type `T`,
* an array of `T`, or `undefined`.
* @returns {T[]} - Returns an array of `T`. If `value` is an array, it is returned as-is. If `value`
* is a single item, it is wrapped in an array. If `value` is `undefined`, returns an empty array.
*
* @example
* asArray(5); // returns [5]
* asArray([5, 6]); // returns [5, 6]
* asArray(undefined); // returns []
*/
beawar marked this conversation as resolved.
Show resolved Hide resolved
export function asArray<T>(value: T | T[] | undefined): T[] {
if (value !== undefined) {
if (Array.isArray(value)) {
return value;
}
return [value];
}
return [];
}

/**
* Compose a unique list of all identities' email addresses
*
* The list is composed of:
* - the email address of the current account
* - the email addresses of all the shared accounts (taken from the rights infos)
* - all the aliases
* - all the email addresses from zimbraAllowFromAddress
*
* @param account
* @param settings
Expand Down Expand Up @@ -533,14 +558,10 @@ export const getAvailableEmailAddresses = (
});
}

// Adds all the aliases
if (settings.attrs.zimbraMailAlias) {
if (isArray(settings.attrs.zimbraMailAlias)) {
result.push(...(settings.attrs.zimbraMailAlias as string[]));
} else {
result.push(String(settings.attrs.zimbraMailAlias));
}
}
result.push(
...asArray(settings.attrs.zimbraMailAlias),
...asArray(settings.attrs.zimbraAllowFromAddress)
);

return uniq(result);
};
Expand Down
2 changes: 2 additions & 0 deletions src/types/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export interface AccountSettingsPrefs {
export type AccountSettingsAttrs = {
zimbraFeatureOptionsEnabled?: BooleanString;
zimbraIdentityMaxNumEntries?: number;
zimbraMailAlias?: string | Array<string>;
zimbraAllowFromAddress?: string | Array<string>;
beawar marked this conversation as resolved.
Show resolved Hide resolved
[key: string]: string | number | Array<string | number> | undefined;
};

Expand Down