This commit is contained in:
Yuri Kuznetsov
2024-04-15 17:57:24 +03:00
parent d7b9b65990
commit a0ab01a77f
3 changed files with 45 additions and 42 deletions
+6 -5
View File
@@ -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);
}
/**
+7 -5
View File
@@ -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];
+32 -32
View File
@@ -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;