From 3bb439e4b10ebf55aa66e9976fc6e75da3fe21c1 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 31 Jul 2023 10:14:40 +0300 Subject: [PATCH] ref --- client/src/acl-portal/email.js | 56 +++++----- client/src/acl-portal/notification.js | 22 ++-- client/src/acl-portal/preferences.js | 21 ++-- client/src/acl/email.js | 152 +++++++++++++------------- client/src/acl/foreign.js | 27 ++--- client/src/acl/import.js | 38 ++++--- client/src/acl/notification.js | 21 ++-- client/src/acl/preferences.js | 21 ++-- client/src/acl/team.js | 17 +-- client/src/acl/user.js | 30 ++--- 10 files changed, 211 insertions(+), 194 deletions(-) diff --git a/client/src/acl-portal/email.js b/client/src/acl-portal/email.js index 7adb82ad2a..2daeed62cf 100644 --- a/client/src/acl-portal/email.js +++ b/client/src/acl-portal/email.js @@ -26,37 +26,39 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl-portal/email', ['acl-portal'], function (Dep) { +import AclPortal from 'acl-portal'; - return Dep.extend({ +class EmailAclPortal extends AclPortal { - checkModelRead: function (model, data, precise) { - var result = this.checkModel(model, data, 'read', precise); + // noinspection JSUnusedGlobalSymbols + checkModelRead(model, data, precise) { + let result = this.checkModel(model, data, 'read', precise); - if (result) { + if (result) { + return true; + } + + if (data === false) { + return false; + } + + let d = data || {}; + + if (d.read === 'no') { + return false; + } + + if (model.has('usersIds')) { + if (~(model.get('usersIds') || []).indexOf(this.getUser().id)) { return true; } + } + else if (precise) { + return null; + } - if (data === false) { - return false; - } + return result; + } +} - var d = data || {}; - if (d.read === 'no') { - return false; - } - - if (model.has('usersIds')) { - if (~(model.get('usersIds') || []).indexOf(this.getUser().id)) { - return true; - } - } else { - if (precise) { - return null; - } - } - - return result; - }, - }); -}); +export default EmailAclPortal; diff --git a/client/src/acl-portal/notification.js b/client/src/acl-portal/notification.js index af483fb349..eca748507e 100644 --- a/client/src/acl-portal/notification.js +++ b/client/src/acl-portal/notification.js @@ -26,15 +26,17 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl-portal/notification', ['acl-portal'], function (Dep) { +import AclPortal from 'acl-portal'; - return Dep.extend({ +class NotificationAclPortal extends AclPortal { - checkIsOwner: function (model) { - if (this.getUser().id === model.get('userId')) { - return true; - } - return false; - }, - }); -}); + checkIsOwner(model) { + if (this.getUser().id === model.get('userId')) { + return true; + } + + return false; + } +} + +export default NotificationAclPortal; diff --git a/client/src/acl-portal/preferences.js b/client/src/acl-portal/preferences.js index 86bcd77a8a..1f05ca0439 100644 --- a/client/src/acl-portal/preferences.js +++ b/client/src/acl-portal/preferences.js @@ -26,16 +26,17 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl-portal/preferences', ['acl-portal'], function (Dep) { +import AclPortal from 'acl-portal'; - return Dep.extend({ +class PreferencesAclPortal extends AclPortal { - checkIsOwner: function (model) { - if (this.getUser().id === model.id) { - return true; - } + checkIsOwner(model) { + if (this.getUser().id === model.id) { + return true; + } - return false; - }, - }); -}); + return false; + } +} + +export default PreferencesAclPortal; diff --git a/client/src/acl/email.js b/client/src/acl/email.js index f54d7df8da..8a3c2814b2 100644 --- a/client/src/acl/email.js +++ b/client/src/acl/email.js @@ -26,92 +26,96 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl/email', ['acl'], function (Dep) { +import Acl from 'acl'; - return Dep.extend({ +class EmailAcl extends Acl { - checkModelRead: function (model, data, precise) { - var result = this.checkModel(model, data, 'read', precise); + // noinspection JSUnusedGlobalSymbols + checkModelRead(model, data, precise) { + let result = this.checkModel(model, data, 'read', precise); - if (result) { - return true; - } - - if (data === false) { - return false; - } - - var d = data || {}; - if (d.read === 'no') { - return false; - } - - if (model.has('usersIds')) { - if (~(model.get('usersIds') || []).indexOf(this.getUser().id)) { - return true; - } - } else { - if (precise) { - return null; - } - } - - return result; - }, - - checkIsOwner: function (model) { - if ( - this.getUser().id === model.get('assignedUserId') || - this.getUser().id === model.get('createdById') - ) { - return true; - } - - if (!model.has('assignedUsersIds')) { - return null; - } - - if (~(model.get('assignedUsersIds') || []).indexOf(this.getUser().id)) { - return true; - } + if (result) { + return true; + } + if (data === false) { return false; - }, + } - checkModelEdit: function (model, data, precise) { - if ( - model.get('status') === 'Draft' && - model.get('createdById') === this.getUser().id - ) { + let d = data || {}; + + if (d.read === 'no') { + return false; + } + + if (model.has('usersIds')) { + if (~(model.get('usersIds') || []).indexOf(this.getUser().id)) { return true; } + } + else if (precise) { + return null; + } - return this.checkModel(model, data, 'edit', precise); - }, + return result; + } - checkModelDelete: function (model, data, precise) { - var result = this.checkModel(model, data, 'delete', precise); + checkIsOwner(model) { + if ( + this.getUser().id === model.get('assignedUserId') || + this.getUser().id === model.get('createdById') + ) { + return true; + } - if (result) { + if (!model.has('assignedUsersIds')) { + return null; + } + + if (~(model.get('assignedUsersIds') || []).indexOf(this.getUser().id)) { + return true; + } + + return false; + } + + // noinspection JSUnusedGlobalSymbols + checkModelEdit(model, data, precise) { + if ( + model.get('status') === 'Draft' && + model.get('createdById') === this.getUser().id + ) { + return true; + } + + return this.checkModel(model, data, 'edit', precise); + } + + checkModelDelete(model, data, precise) { + let result = this.checkModel(model, data, 'delete', precise); + + if (result) { + return true; + } + + if (data === false) { + return false; + } + + let d = data || {}; + + if (d.read === 'no') { + return false; + } + + if (model.get('createdById') === this.getUser().id) { + if (model.get('status') !== 'Sent' && model.get('status') !== 'Archived') { return true; } + } - if (data === false) { - return false; - } + return result; + } +} - var d = data || {}; - if (d.read === 'no') { - return false; - } - - if (model.get('createdById') === this.getUser().id) { - if (model.get('status') !== 'Sent' && model.get('status') !== 'Archived') { - return true; - } - } - - return result; - }, - }); -}); +export default EmailAcl; diff --git a/client/src/acl/foreign.js b/client/src/acl/foreign.js index ba4537ad54..a83de492fb 100644 --- a/client/src/acl/foreign.js +++ b/client/src/acl/foreign.js @@ -26,19 +26,20 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl/foreign', ['acl'], function (Dep) { +import Acl from 'acl'; - /** - * To be used for entities for which access is determined by access to a foreign record. - */ - return Dep.extend({ +/** + * To be used for entities for which access is determined by access to a foreign record. + */ +class ForeignAcl extends Acl { - checkIsOwner: function (model) { - return true; - }, + checkIsOwner(model) { + return true; + } - checkInTeam: function (model) { - return true; - }, - }); -}); + checkInTeam(model) { + return true; + } +} + +export default ForeignAcl; diff --git a/client/src/acl/import.js b/client/src/acl/import.js index e30d391e6e..d6db8edf85 100644 --- a/client/src/acl/import.js +++ b/client/src/acl/import.js @@ -26,28 +26,30 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl/import', ['acl'], function (Dep) { +import Acl from 'acl'; - return Dep.extend({ +class ImportAcl extends Acl { - checkScope: function (data, action, precise, entityAccessData) { - return !!data; - }, + checkScope(data, action, precise, entityAccessData) { + return !!data; + } - checkModelRead: function (model, data, precise) { + // noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols + checkModelRead(model, data, precise) { + return true; + } + + checkIsOwner(model) { + if (this.getUser().id === model.get('createdById')) { return true; - }, + } - checkIsOwner: function (model) { - if (this.getUser().id === model.get('createdById')) { - return true; - } + return false; + } - return false; - }, + checkModelDelete(model, data, precise) { + return true; + } +} - checkModelDelete: function (model, data, precise) { - return true; - }, - }); -}); +export default ImportAcl; diff --git a/client/src/acl/notification.js b/client/src/acl/notification.js index 9c311a1144..d48df75119 100644 --- a/client/src/acl/notification.js +++ b/client/src/acl/notification.js @@ -26,16 +26,17 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl/notification', ['acl'], function (Dep) { +import Acl from 'acl'; - return Dep.extend({ +class NotificationAcl extends Acl { - checkIsOwner: function (model) { - if (this.getUser().id === model.get('userId')) { - return true; - } - - return false; + checkIsOwner(model) { + if (this.getUser().id === model.get('userId')) { + return true; } - }); -}); + + return false; + } +} + +export default NotificationAcl; diff --git a/client/src/acl/preferences.js b/client/src/acl/preferences.js index c81ad84222..a12e10fd46 100644 --- a/client/src/acl/preferences.js +++ b/client/src/acl/preferences.js @@ -26,16 +26,17 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl/preferences', ['acl'], function (Dep) { +import Acl from 'acl'; - return Dep.extend({ +class PreferencesAcl extends Acl { - checkIsOwner: function (model) { - if (this.getUser().id === model.id) { - return true; - } + checkIsOwner(model) { + if (this.getUser().id === model.id) { + return true; + } - return false; - }, - }); -}); + return false; + } +} + +export default PreferencesAcl; diff --git a/client/src/acl/team.js b/client/src/acl/team.js index 39796e48ec..ebcde41ba7 100644 --- a/client/src/acl/team.js +++ b/client/src/acl/team.js @@ -26,14 +26,15 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl/team', ['acl'], function (Dep) { +import Acl from 'acl'; - return Dep.extend({ +class TeamAcl extends Acl { - checkInTeam: function (model) { - var userTeamIdList = this.getUser().getTeamIdList(); + checkInTeam(model) { + const userTeamIdList = this.getUser().getTeamIdList(); - return (userTeamIdList.indexOf(model.id) != -1); - }, - }); -}); + return (userTeamIdList.indexOf(model.id) !== -1); + } +} + +export default TeamAcl; diff --git a/client/src/acl/user.js b/client/src/acl/user.js index 21d0014ce2..d7381c5acd 100644 --- a/client/src/acl/user.js +++ b/client/src/acl/user.js @@ -26,22 +26,24 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl/user', ['acl'], function (Dep) { +import Acl from 'acl'; - return Dep.extend({ +class UserAcl extends Acl { - checkModelRead: function (model, data, precise) { - if (model.isPortal()) { - if (this.get('portalPermission') === 'yes') { - return true; - } + // noinspection JSUnusedGlobalSymbols + checkModelRead(model, data, precise) { + if (model.isPortal()) { + if (this.get('portalPermission') === 'yes') { + return true; } + } - return this.checkModel(model, data, 'read', precise); - }, + return this.checkModel(model, data, 'read', precise); + } - checkIsOwner: function (model) { - return this.getUser().id === model.id; - }, - }); -}); + checkIsOwner(model) { + return this.getUser().id === model.id; + } +} + +export default UserAcl;