diff --git a/web/ASC.Web.Components/src/components/email-input/email-input.test.js b/web/ASC.Web.Components/src/components/email-input/email-input.test.js index d4b16d7e94..6407f16185 100644 --- a/web/ASC.Web.Components/src/components/email-input/email-input.test.js +++ b/web/ASC.Web.Components/src/components/email-input/email-input.test.js @@ -1,7 +1,7 @@ import React from 'react'; import { mount, shallow } from 'enzyme'; import EmailInput from '.'; -import { EmailSettings } from '../../utils/email'; +import { EmailSettings } from '../../utils/email/'; const baseProps = { diff --git a/web/ASC.Web.Components/src/components/email-input/index.js b/web/ASC.Web.Components/src/components/email-input/index.js index 435dbfe06e..58feba1ad3 100644 --- a/web/ASC.Web.Components/src/components/email-input/index.js +++ b/web/ASC.Web.Components/src/components/email-input/index.js @@ -3,7 +3,7 @@ import styled from 'styled-components' import PropTypes from 'prop-types' import isEqual from "lodash/isEqual"; import TextInput from '../text-input' -import { EmailSettings, parseAddress, checkAndConvertEmailSettings, isEqualEmailSettings } from '../../utils/email'; +import { EmailSettings, parseAddress, checkAndConvertEmailSettings, isEqualEmailSettings } from '../../utils/email/'; const borderColor = { default: '#D0D5DA', diff --git a/web/ASC.Web.Components/src/utils/email.js b/web/ASC.Web.Components/src/utils/email/email.js similarity index 62% rename from web/ASC.Web.Components/src/utils/email.js rename to web/ASC.Web.Components/src/utils/email/email.js index d00636ecbe..6c57177e22 100644 --- a/web/ASC.Web.Components/src/utils/email.js +++ b/web/ASC.Web.Components/src/utils/email/email.js @@ -1,6 +1,7 @@ import emailAddresses from "email-addresses"; import punycode from "punycode"; -import { parseErrorTypes } from "./constants"; +import { parseErrorTypes } from "./../constants"; +import { EmailSettings } from './index'; const getParts = string => { let mass = []; @@ -260,154 +261,3 @@ export class Email { return false; }; } - -export class EmailSettings { - constructor() { - this.allowDomainPunycode = false; - this.allowLocalPartPunycode = false; - this.allowDomainIp = false; - this.allowStrictLocalPart = true; - this.allowSpaces = false; - this.allowName = false; - this.allowLocalDomainName = false; - } - - get allowDomainPunycode() { - return this._allowDomainPunycode; - } - - set allowDomainPunycode(value) { - if (value !== undefined && typeof value === 'boolean') { - this._allowDomainPunycode = value; - } - else { - throw `Invalid value ${value} for allowDomainPunycode option. Use boolean value` - } - } - - get allowLocalPartPunycode() { - return this._allowLocalPartPunycode; - } - - set allowLocalPartPunycode(value) { - if (value !== undefined && typeof value === 'boolean') { - this._allowLocalPartPunycode = value; - } - else { - throw `Invalid value ${value} for allowLocalPartPunycode option. Use boolean value` - } - } - - get allowDomainIp() { - return this._allowDomainIp; - } - - set allowDomainIp(value) { - if (value !== undefined && typeof value === 'boolean') { - this._allowDomainIp = value; - } - else { - throw `Invalid value ${value} for allowDomainIp option. Use boolean value` - } - } - - get allowStrictLocalPart() { - return this._allowStrictLocalPart; - } - - set allowStrictLocalPart(value) { - if (value !== undefined && typeof value === 'boolean') { - this._allowStrictLocalPart = value; - } - else { - throw `Invalid value ${value} for allowStrictLocalPart option. Use boolean value` - } - } - - get allowSpaces() { - return this._allowSpaces; - } - - set allowSpaces(value) { - if (value !== undefined && typeof value === 'boolean') { - this._allowSpaces = value; - } - else { - throw `Invalid value ${value} for allowSpaces option. Use boolean value` - } - } - - get allowName() { - return this._allowName; - } - - set allowName(value) { - if (value !== undefined && typeof value === 'boolean') { - this._allowName = value; - } - else { - throw `Invalid value ${value} for allowName option. Use boolean value` - } - } - - get allowLocalDomainName() { - return this._allowLocalDomainName; - } - - set allowLocalDomainName(value) { - if (value !== undefined && typeof value === 'boolean') { - this._allowLocalDomainName = value; - } - else { - throw `Invalid value ${value} for allowLocalDomainName option. Use boolean value` - } - } - - getSettings() { - return { - allowDomainPunycode: this.allowDomainPunycode, - allowLocalPartPunycode: this.allowLocalPartPunycode, - allowDomainIp: this.allowDomainIp, - allowStrictLocalPart: this.allowStrictLocalPart, - allowSpaces: this.allowSpaces, - allowName: this.allowName, - allowLocalDomainName: this.allowLocalDomainName - } - } -} - -export const checkAndConvertEmailSettings = (settings) => { - if (typeof settings === 'object' && !(settings instanceof EmailSettings)) { - const defaultSettings = new EmailSettings(); - Object.keys(settings).map((item) => { - if (defaultSettings[item] !== null && defaultSettings[item] != settings[item]) { - defaultSettings[item] = settings[item]; - } - }); - return defaultSettings; - } - - else if (typeof settings === 'object' && settings instanceof EmailSettings) { - return settings; - } -} - -export const isEqualEmailSettings = (settings1, settings2) => { - const comparedProperties = [ - 'allowDomainPunycode', - 'allowLocalPartPunycode', - 'allowDomainIp', - 'allowStrictLocalPart', - 'allowSpaces', - 'allowName', - 'allowLocalDomainName' - ]; - const propLength = comparedProperties.length; - for (let i = 0; i < propLength; i++) { - const comparedProp = comparedProperties[i] - if (settings1[comparedProp] !== settings2[comparedProp]) { - return false; - } - } - return true; -} \ No newline at end of file diff --git a/web/ASC.Web.Components/src/utils/email/emailSettings.js b/web/ASC.Web.Components/src/utils/email/emailSettings.js new file mode 100644 index 0000000000..20fdea573e --- /dev/null +++ b/web/ASC.Web.Components/src/utils/email/emailSettings.js @@ -0,0 +1,150 @@ +export class EmailSettings { + constructor() { + this.allowDomainPunycode = false; + this.allowLocalPartPunycode = false; + this.allowDomainIp = false; + this.allowStrictLocalPart = true; + this.allowSpaces = false; + this.allowName = false; + this.allowLocalDomainName = false; + } + + get allowDomainPunycode() { + return this._allowDomainPunycode; + } + + set allowDomainPunycode(value) { + if (value !== undefined && typeof value === 'boolean') { + this._allowDomainPunycode = value; + } + else { + throw `Invalid value ${value} for allowDomainPunycode option. Use boolean value` + } + } + + get allowLocalPartPunycode() { + return this._allowLocalPartPunycode; + } + + set allowLocalPartPunycode(value) { + if (value !== undefined && typeof value === 'boolean') { + this._allowLocalPartPunycode = value; + } + else { + throw `Invalid value ${value} for allowLocalPartPunycode option. Use boolean value` + } + } + + get allowDomainIp() { + return this._allowDomainIp; + } + + set allowDomainIp(value) { + if (value !== undefined && typeof value === 'boolean') { + this._allowDomainIp = value; + } + else { + throw `Invalid value ${value} for allowDomainIp option. Use boolean value` + } + } + + get allowStrictLocalPart() { + return this._allowStrictLocalPart; + } + + set allowStrictLocalPart(value) { + if (value !== undefined && typeof value === 'boolean') { + this._allowStrictLocalPart = value; + } + else { + throw `Invalid value ${value} for allowStrictLocalPart option. Use boolean value` + } + } + + get allowSpaces() { + return this._allowSpaces; + } + + set allowSpaces(value) { + if (value !== undefined && typeof value === 'boolean') { + this._allowSpaces = value; + } + else { + throw `Invalid value ${value} for allowSpaces option. Use boolean value` + } + } + + get allowName() { + return this._allowName; + } + + set allowName(value) { + if (value !== undefined && typeof value === 'boolean') { + this._allowName = value; + } + else { + throw `Invalid value ${value} for allowName option. Use boolean value` + } + } + + get allowLocalDomainName() { + return this._allowLocalDomainName; + } + + set allowLocalDomainName(value) { + if (value !== undefined && typeof value === 'boolean') { + this._allowLocalDomainName = value; + } + else { + throw `Invalid value ${value} for allowLocalDomainName option. Use boolean value` + } + } + + getSettings() { + return { + allowDomainPunycode: this.allowDomainPunycode, + allowLocalPartPunycode: this.allowLocalPartPunycode, + allowDomainIp: this.allowDomainIp, + allowStrictLocalPart: this.allowStrictLocalPart, + allowSpaces: this.allowSpaces, + allowName: this.allowName, + allowLocalDomainName: this.allowLocalDomainName + } + } +} + +export const checkAndConvertEmailSettings = (settings) => { + if (typeof settings === 'object' && !(settings instanceof EmailSettings)) { + const defaultSettings = new EmailSettings(); + Object.keys(settings).map((item) => { + if (defaultSettings[item] !== null && defaultSettings[item] != settings[item]) { + defaultSettings[item] = settings[item]; + } + }); + return defaultSettings; + } + + else if (typeof settings === 'object' && settings instanceof EmailSettings) { + return settings; + } +} + +export const isEqualEmailSettings = (settings1, settings2) => { + const comparedProperties = [ + 'allowDomainPunycode', + 'allowLocalPartPunycode', + 'allowDomainIp', + 'allowStrictLocalPart', + 'allowSpaces', + 'allowName', + 'allowLocalDomainName' + ]; + const propLength = comparedProperties.length; + for (let i = 0; i < propLength; i++) { + const comparedProp = comparedProperties[i] + if (settings1[comparedProp] !== settings2[comparedProp]) { + return false; + } + } + return true; +} diff --git a/web/ASC.Web.Components/src/utils/email/index.js b/web/ASC.Web.Components/src/utils/email/index.js new file mode 100644 index 0000000000..f0af4f95a2 --- /dev/null +++ b/web/ASC.Web.Components/src/utils/email/index.js @@ -0,0 +1,2 @@ +export { parseAddress } from './email'; +export { EmailSettings, checkAndConvertEmailSettings, isEqualEmailSettings } from './emailSettings'; \ No newline at end of file