From a0ab01a77f9edb32b45af5042ebe02c41fa14c7c Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 15 Apr 2024 17:57:24 +0300 Subject: [PATCH] ref --- client/src/acl-manager.js | 11 +++--- client/src/acl-portal-manager.js | 12 +++--- client/src/acl-portal.js | 64 ++++++++++++++++---------------- 3 files changed, 45 insertions(+), 42 deletions(-) diff --git a/client/src/acl-manager.js b/client/src/acl-manager.js index 874d934583..f96b2934de 100644 --- a/client/src/acl-manager.js +++ b/client/src/acl-manager.js @@ -97,7 +97,7 @@ class AclManager { const params = { aclAllowDeleteCreated: this.aclAllowDeleteCreated, - teamsFieldIsForbidden: !!~forbiddenFieldList.indexOf('teams'), + teamsFieldIsForbidden: forbiddenFieldList.includes('teams'), forbiddenFieldList: forbiddenFieldList, }; @@ -108,6 +108,7 @@ class AclManager { } /** + * @return {import('models/user').default} * @protected */ getUser() { @@ -353,7 +354,7 @@ class AclManager { const teamsIds = user.get('teamsIds') || []; teamsIds.forEach(id => { - if (~(this.getUser().get('teamsIds') || []).indexOf(id)) { + if ((this.getUser().get('teamsIds') || []).includes(id)) { result = true; } }); @@ -403,7 +404,7 @@ class AclManager { const list = actionData[level] || []; list.forEach(field => { - if (~fieldList.indexOf(field)) { + if (fieldList.includes(field)) { return; } @@ -448,7 +449,7 @@ class AclManager { const list = actionData[level] || []; list.forEach(attribute => { - if (~attributeList.indexOf(attribute)) { + if (attributeList.includes(attribute)) { return; } @@ -472,7 +473,7 @@ class AclManager { return true; } - return !!~this.getUser().getLinkMultipleIdList('teams').indexOf(teamId); + return this.getUser().getLinkMultipleIdList('teams').includes(teamId); } /** diff --git a/client/src/acl-portal-manager.js b/client/src/acl-portal-manager.js index c1ac150acb..7f5960af53 100644 --- a/client/src/acl-portal-manager.js +++ b/client/src/acl-portal-manager.js @@ -44,9 +44,7 @@ class AclPortalManager extends AclManager { * @returns {boolean|null} True if in an account, null if not clear. */ checkInAccount(model) { - const impl = - /** @type {module:acl-portal} */ - this.getImplementation(model.entityType); + const impl = /** @type {module:acl-portal} */this.getImplementation(model.entityType); return impl.checkInAccount(model); } @@ -78,8 +76,12 @@ class AclPortalManager extends AclManager { implementationClass = this.implementationClassMap[scope]; } - this.implementationHash[scope] = - new implementationClass(this.getUser(), scope, this.aclAllowDeleteCreated); + const params = { + aclAllowDeleteCreated: false, + forbiddenFieldList: this.getScopeForbiddenFieldList(scope), + }; + + this.implementationHash[scope] = new implementationClass(this.getUser(), scope, params); } return this.implementationHash[scope]; diff --git a/client/src/acl-portal.js b/client/src/acl-portal.js index fb5bd80f60..32f6c8d246 100644 --- a/client/src/acl-portal.js +++ b/client/src/acl-portal.js @@ -40,9 +40,9 @@ class AclPortal extends Acl { checkScope(data, action, precise, entityAccessData) { entityAccessData = entityAccessData || {}; - let inAccount = entityAccessData.inAccount; - let isOwnContact = entityAccessData.isOwnContact; - let isOwner = entityAccessData.isOwner; + const inAccount = entityAccessData.inAccount; + const isOwnContact = entityAccessData.isOwnContact; + const isOwner = entityAccessData.isOwner; if (this.getUser().isAdmin()) { return true; @@ -74,7 +74,7 @@ class AclPortal extends Acl { return false; } - var value = data[action]; + const value = data[action]; if (value === 'all') { return true; @@ -98,15 +98,15 @@ class AclPortal extends Acl { } } - var result = false; + let result = false; if (value === 'account') { result = inAccount; + if (inAccount === null) { if (precise) { result = null; - } - else { + } else { return true; } } @@ -121,8 +121,7 @@ class AclPortal extends Acl { if (isOwnContact === null) { if (precise) { result = null; - } - else { + } else { return true; } } @@ -134,8 +133,7 @@ class AclPortal extends Acl { if (isOwner === null) { if (precise) { result = null; - } - else { + } else { return true; } } @@ -149,7 +147,7 @@ class AclPortal extends Acl { return true; } - let entityAccessData = { + const entityAccessData = { isOwner: this.checkIsOwner(model), inAccount: this.checkInAccount(model), isOwnContact: this.checkIsOwnContact(model), @@ -160,10 +158,11 @@ class AclPortal extends Acl { /** @inheritDoc */ checkIsOwner(model) { - if (model.hasField('createdBy')) { - if (this.getUser().id === model.get('createdById')) { - return true; - } + if ( + model.hasField('createdBy') && + this.getUser().id === model.get('createdById') + ) { + return true; } return false; @@ -176,21 +175,21 @@ class AclPortal extends Acl { * @returns {boolean|null} True if in an account, null if not clear. */ checkInAccount(model) { - let accountIdList = this.getUser().getLinkMultipleIdList('accounts'); + const accountIdList = this.getUser().getLinkMultipleIdList('accounts'); if (!accountIdList.length) { return false; } - if (model.hasField('account')) { - if (model.get('accountId')) { - if (~accountIdList.indexOf(model.get('accountId'))) { - return true; - } - } + if ( + model.hasField('account') && + model.get('accountId') && + accountIdList.includes(model.get('accountId')) + ) { + return true; } - var result = false; + let result = false; if (model.hasField('accounts') && model.hasLink('accounts')) { if (!model.has('accountsIds')) { @@ -198,18 +197,19 @@ class AclPortal extends Acl { } (model.getLinkMultipleIdList('accounts')).forEach(id => { - if (~accountIdList.indexOf(id)) { + if (accountIdList.includes(id)) { result = true; } }); } - if (model.hasField('parent') && model.hasLink('parent')) { - if (model.get('parentType') === 'Account') { - if (!accountIdList.indexOf(model.get('parentId'))) { - return true; - } - } + if ( + model.hasField('parent') && + model.hasLink('parent') && + model.get('parentType') === 'Account' && + accountIdList.includes(model.get('parentId')) + ) { + return true; } if (result === false) { @@ -228,7 +228,7 @@ class AclPortal extends Acl { * @returns {boolean|null} True if in a contact-owner, null if not clear. */ checkIsOwnContact(model) { - let contactId = this.getUser().get('contactId'); + const contactId = this.getUser().get('contactId'); if (!contactId) { return false;