diff --git a/client/src/acl-manager.js b/client/src/acl-manager.js index a4a0e25ab9..78d6db6580 100644 --- a/client/src/acl-manager.js +++ b/client/src/acl-manager.js @@ -30,24 +30,7 @@ import Acl from 'acl'; import Utils from 'utils'; - -/** - * Access checking. - * - * @class - * @name Class - * @param {module:models/user} user A user. - * @param {Object} implementationClassMap `acl` implementations. - * @param {boolean} aclAllowDeleteCreated Allow a user to delete records they created regardless a - * role access level. - */ -const Class = function (user, implementationClassMap, aclAllowDeleteCreated) { - this.setEmpty(); - - this.user = user || null; - this.implementationClassMap = implementationClassMap || {}; - this.aclAllowDeleteCreated = aclAllowDeleteCreated; -}; +import {View as BullView} from 'lib!bullbone'; /** * An action. @@ -55,19 +38,34 @@ const Class = function (user, implementationClassMap, aclAllowDeleteCreated) { * @typedef {'create'|'read'|'edit'|'delete'|'stream'} module:acl-manager~action */ -_.extend(Class.prototype, /** @lends Class# */{ +/** + * An access checking class for a specific scope. + */ +class AclManager { /** @protected */ - data: null, - /** @protected */ - user: null, - /** @protected */ - fieldLevelList: ['yes', 'no'], + data = null + fieldLevelList = ['yes', 'no'] + + /** + * @param {module:models/user} user A user. + * @param {Object} implementationClassMap `acl` implementations. + * @param {boolean} aclAllowDeleteCreated Allow a user to delete records they created regardless a + * role access level. + */ + constructor(user, implementationClassMap, aclAllowDeleteCreated) { + this.setEmpty(); + + /** @protected */ + this.user = user || null; + this.implementationClassMap = implementationClassMap || {}; + this.aclAllowDeleteCreated = aclAllowDeleteCreated; + } /** * @protected */ - setEmpty: function () { + setEmpty() { this.data = { table: {}, fieldTable: {}, @@ -78,7 +76,7 @@ _.extend(Class.prototype, /** @lends Class# */{ this.forbiddenFieldsCache = {}; this.implementationClassMap = {}; this.forbiddenAttributesCache = {}; - }, + } /** * Get an `acl` implementation. @@ -87,7 +85,7 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {string} scope A scope. * @returns {module:acl} */ - getImplementation: function (scope) { + getImplementation(scope) { if (!(scope in this.implementationHash)) { let implementationClass = Acl; @@ -107,35 +105,35 @@ _.extend(Class.prototype, /** @lends Class# */{ } return this.implementationHash[scope]; - }, + } /** * @protected */ - getUser: function () { + getUser() { return this.user; - }, + } /** * @internal */ - set: function (data) { + set(data) { data = data || {}; this.data = data; this.data.table = this.data.table || {}; this.data.fieldTable = this.data.fieldTable || {}; this.data.attributeTable = this.data.attributeTable || {}; - }, + } /** * @deprecated Use `getPermissionLevel`. * * @returns {string|null} */ - get: function (name) { + get(name) { return this.data[name] || null; - }, + } /** * Get a permission level. @@ -143,7 +141,7 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {string} permission A permission name. * @returns {'yes'|'all'|'team'|'no'} */ - getPermissionLevel: function (permission) { + getPermissionLevel(permission) { let permissionKey = permission; if (permission.substr(-10) !== 'Permission') { @@ -151,7 +149,7 @@ _.extend(Class.prototype, /** @lends Class# */{ } return this.data[permissionKey] || 'no'; - }, + } /** * Get access level to a scope action. @@ -160,7 +158,7 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {module:acl-manager~action} action An action. * @returns {'yes'|'all'|'team'|'no'|null} */ - getLevel: function (scope, action) { + getLevel(scope, action) { if (!(scope in this.data.table)) { return null; } @@ -170,16 +168,16 @@ _.extend(Class.prototype, /** @lends Class# */{ } return this.data.table[scope][action]; - }, + } /** * Clear access data. * * @internal */ - clear: function () { + clear() { this.setEmpty(); - }, + } /** * Check whether a scope has ACL. @@ -187,7 +185,7 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {string} scope A scope. * @returns {boolean} */ - checkScopeHasAcl: function (scope) { + checkScopeHasAcl(scope) { var data = (this.data.table || {})[scope]; if (typeof data === 'undefined') { @@ -195,7 +193,7 @@ _.extend(Class.prototype, /** @lends Class# */{ } return true; - }, + } /** * Check access to a scope. @@ -205,7 +203,7 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {boolean} [precise=false] Deprecated. Not used. * @returns {boolean} True if has access. */ - checkScope: function (scope, action, precise) { + checkScope(scope, action, precise) { let data = (this.data.table || {})[scope]; if (typeof data === 'undefined') { @@ -213,7 +211,7 @@ _.extend(Class.prototype, /** @lends Class# */{ } return this.getImplementation(scope).checkScope(data, action, precise); - }, + } /** * Check access to a model. @@ -224,7 +222,7 @@ _.extend(Class.prototype, /** @lends Class# */{ * E.g. the `teams` field is not yet loaded. * @returns {boolean|null} True if has access, null if not clear. */ - checkModel: function (model, action, precise) { + checkModel(model, action, precise) { var scope = model.name; // todo move this to custom acl @@ -257,7 +255,7 @@ _.extend(Class.prototype, /** @lends Class# */{ } return impl.checkModel(model, data, action, precise); - }, + } /** * Check access to a scope or a model. @@ -268,13 +266,13 @@ _.extend(Class.prototype, /** @lends Class# */{ * E.g. the `teams` field is not yet loaded. * @returns {boolean|null} {boolean|null} True if has access, null if not clear. */ - check: function (subject, action, precise) { + check(subject, action, precise) { if (typeof subject === 'string') { return this.checkScope(subject, action, precise); } return this.checkModel(subject, action, precise); - }, + } /** * Check if a user is owner to a model. @@ -282,9 +280,9 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {module:model} model A model. * @returns {boolean|null} True if owner, null if not clear. */ - checkIsOwner: function (model) { + checkIsOwner(model) { return this.getImplementation(model.name).checkIsOwner(model); - }, + } /** * Check if a user in a team of a model. @@ -292,9 +290,9 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {module:model} model A model. * @returns {boolean|null} True if in a team, null if not clear. */ - checkInTeam: function (model) { + checkInTeam(model) { return this.getImplementation(model.name).checkInTeam(model); - }, + } /** * Check an assignment permission to a user. @@ -302,9 +300,9 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {module:models/user} user A user. * @returns {boolean} True if has access. */ - checkAssignmentPermission: function (user) { + checkAssignmentPermission(user) { return this.checkPermission('assignmentPermission', user); - }, + } /** * Check a user permission to a user. @@ -312,9 +310,9 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {module:models/user} user A user. * @returns {boolean} True if has access. */ - checkUserPermission: function (user) { + checkUserPermission(user) { return this.checkPermission('userPermission', user); - }, + } /** * Check a specific permission to a user. @@ -323,7 +321,7 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {module:models/user} user A user. * @returns {boolean} True if has access. */ - checkPermission: function (permission, user) { + checkPermission(permission, user) { if (this.getUser().isAdmin()) { return true; } @@ -365,7 +363,7 @@ _.extend(Class.prototype, /** @lends Class# */{ } return false; - }, + } /** * Get a list of forbidden fields for an entity type. @@ -375,7 +373,7 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {'yes'|'no'} [thresholdLevel='no'] A threshold level. * @returns {string[]} A forbidden field list. */ - getScopeForbiddenFieldList: function (scope, action, thresholdLevel) { + getScopeForbiddenFieldList(scope, action, thresholdLevel) { action = action || 'read'; thresholdLevel = thresholdLevel || 'no'; @@ -409,7 +407,7 @@ _.extend(Class.prototype, /** @lends Class# */{ this.forbiddenFieldsCache[key] = fieldList; return Utils.clone(fieldList); - }, + } /** * Get a list of forbidden attributes for an entity type. @@ -419,7 +417,7 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {'yes'|'no'} [thresholdLevel='no'] A threshold level. * @returns {string[]} A forbidden attribute list. */ - getScopeForbiddenAttributeList: function (scope, action, thresholdLevel) { + getScopeForbiddenAttributeList(scope, action, thresholdLevel) { action = action || 'read'; thresholdLevel = thresholdLevel || 'no'; @@ -454,7 +452,7 @@ _.extend(Class.prototype, /** @lends Class# */{ this.forbiddenAttributesCache[key] = attributeList; return Utils.clone(attributeList); - }, + } /** * Check an assignment permission to a team. @@ -462,13 +460,13 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {string} teamId A team ID. * @returns {boolean} True if has access. */ - checkTeamAssignmentPermission: function (teamId) { + checkTeamAssignmentPermission(teamId) { if (this.get('assignmentPermission') === 'all') { return true; } return !!~this.getUser().getLinkMultipleIdList('teams').indexOf(teamId); - }, + } /** * Check access to a field. @@ -477,11 +475,11 @@ _.extend(Class.prototype, /** @lends Class# */{ * @param {'read'|'edit'} [action='read'] An action. * @returns {boolean} True if has access. */ - checkField: function (scope, field, action) { + checkField(scope, field, action) { return !~this.getScopeForbiddenFieldList(scope, action).indexOf(field); - }, -}); + } +} -Class.extend = Bull.View.extend; +AclManager.extend = BullView.extend; -export default Class; +export default AclManager; diff --git a/client/src/acl-portal-manager.js b/client/src/acl-portal-manager.js index 76f7e8d080..a500f3861a 100644 --- a/client/src/acl-portal-manager.js +++ b/client/src/acl-portal-manager.js @@ -28,17 +28,13 @@ /** @module acl-portal-manager */ -import Dep from 'acl-manager'; +import AclManager from 'acl-manager'; import AclPortal from 'acl-portal'; /** - * Portal access checking. - * - * @class - * @name Class - * @extends module:acl-manager + * An access checking class for a specific scope for portals. */ -export default Dep.extend(/** @lends Class# */{ +class AclPortalManager extends AclManager { /** * Check if a user in an account of a model. @@ -46,9 +42,9 @@ export default Dep.extend(/** @lends Class# */{ * @param {module:model} model A model. * @returns {boolean|null} True if in an account, null if not clear. */ - checkInAccount: function (model) { + checkInAccount(model) { return this.getImplementation(model.name).checkInAccount(model); - }, + } /** * Check if a user is a contact-owner to a model. @@ -56,14 +52,15 @@ export default Dep.extend(/** @lends Class# */{ * @param {module:model} model A model. * @returns {boolean|null} True if in a contact-owner, null if not clear. */ - checkIsOwnContact: function (model) { + checkIsOwnContact(model) { return this.getImplementation(model.name).checkIsOwnContact(model); - }, + } /** - * @inheritDoc + * @param {string} scope A scope. + * @returns {module:acl-portal} */ - getImplementation: function (scope) { + getImplementation(scope) { if (!(scope in this.implementationHash)) { let implementationClass = AclPortal; @@ -76,5 +73,7 @@ export default Dep.extend(/** @lends Class# */{ } return this.implementationHash[scope]; - }, -}); + } +} + +export default AclPortalManager; diff --git a/client/src/acl-portal.js b/client/src/acl-portal.js index 7ecf5196c0..e089319fbb 100644 --- a/client/src/acl-portal.js +++ b/client/src/acl-portal.js @@ -28,32 +28,16 @@ /** @module acl-portal */ -import Dep from 'acl'; +import Acl from 'acl'; /** * Internal class for portal access checking. Can be extended to customize access checking * for a specific scope. - * - * @class - * @name Class - * @extends Dep */ -export default Dep.extend(/** @lends Class# */{ +class AclPortal extends Acl { /** @inheritDoc */ - user: null, - - /** - * @inheritDoc - */ - getUser: function () { - return this.user; - }, - - /** - * @inheritDoc - */ - checkScope: function (data, action, precise, entityAccessData) { + checkScope(data, action, precise, entityAccessData) { entityAccessData = entityAccessData || {}; let inAccount = entityAccessData.inAccount; @@ -157,12 +141,10 @@ export default Dep.extend(/** @lends Class# */{ } return result; - }, + } - /** - * @inheritDoc - */ - checkModel: function (model, data, action, precise) { + /** @inheritDoc */ + checkModel(model, data, action, precise) { if (this.getUser().isAdmin()) { return true; } @@ -174,12 +156,10 @@ export default Dep.extend(/** @lends Class# */{ }; return this.checkScope(data, action, precise, entityAccessData); - }, + } - /** - * @inheritDoc - */ - checkIsOwner: function (model) { + /** @inheritDoc */ + checkIsOwner(model) { if (model.hasField('createdBy')) { if (this.getUser().id === model.get('createdById')) { return true; @@ -187,7 +167,7 @@ export default Dep.extend(/** @lends Class# */{ } return false; - }, + } /** * Check if a user in an account of a model. @@ -195,7 +175,7 @@ export default Dep.extend(/** @lends Class# */{ * @param {module:model} model A model. * @returns {boolean|null} True if in an account, null if not clear. */ - checkInAccount: function (model) { + checkInAccount(model) { let accountIdList = this.getUser().getLinkMultipleIdList('accounts'); if (!accountIdList.length) { @@ -239,7 +219,7 @@ export default Dep.extend(/** @lends Class# */{ } return result; - }, + } /** * Check if a user is a contact-owner to a model. @@ -247,7 +227,7 @@ export default Dep.extend(/** @lends Class# */{ * @param {module:model} model A model. * @returns {boolean|null} True if in a contact-owner, null if not clear. */ - checkIsOwnContact: function (model) { + checkIsOwnContact(model) { let contactId = this.getUser().get('contactId'); if (!contactId) { @@ -289,5 +269,7 @@ export default Dep.extend(/** @lends Class# */{ } return result; - }, -}); + } +} + +export default AclPortal; diff --git a/client/src/acl.js b/client/src/acl.js index bf181a35dc..b27124aba4 100644 --- a/client/src/acl.js +++ b/client/src/acl.js @@ -28,35 +28,35 @@ /** @module acl */ +import {View as BullView} from 'lib!bullbone'; + /** * Internal class for access checking. Can be extended to customize access checking * for a specific scope. - * - * @class - * @param {module:models/user} user A user. - * @param {string} scope A scope. - * @param {Object} params Parameters. */ -const Class = function (user, scope, params) { - this.user = user || null; - this.scope = scope; - - params = params || {}; - - this.aclAllowDeleteCreated = params.aclAllowDeleteCreated; - this.teamsFieldIsForbidden = params.teamsFieldIsForbidden; - this.forbiddenFieldList = params.forbiddenFieldList; -}; - -_.extend(Class.prototype, /** @lends Class# */ { +class Acl { /** - * A user. - * - * @type {module:models/user} - * @protected + * @param {module:models/user} user A user. + * @param {string} scope A scope. + * @param {Object} params Parameters. */ - user: null, + constructor(user, scope, params) { + /** + * A user. + * + * @type {module:models/user|null} + * @protected + */ + this.user = user || null; + this.scope = scope; + + params = params || {}; + + this.aclAllowDeleteCreated = params.aclAllowDeleteCreated; + this.teamsFieldIsForbidden = params.teamsFieldIsForbidden; + this.forbiddenFieldList = params.forbiddenFieldList; + } /** * Get a user. @@ -64,24 +64,24 @@ _.extend(Class.prototype, /** @lends Class# */ { * @returns {module:models/user} * @protected */ - getUser: function () { + getUser() { return this.user; - }, + } /** * Check access to a scope. * - * @param {string|boolean|Object} data Access data. + * @param {string|boolean|Object.} data Access data. * @param {module:acl-manager~action|null} [action=null] An action. * @param {boolean} [precise=false] To return `null` if `inTeam == null`. * @param {Object|null} [entityAccessData=null] Entity access data. `inTeam`, `isOwner`. * @returns {boolean|null} True if has access. */ - checkScope: function (data, action, precise, entityAccessData) { + checkScope(data, action, precise, entityAccessData) { entityAccessData = entityAccessData || {}; - var inTeam = entityAccessData.inTeam; - var isOwner = entityAccessData.isOwner; + let inTeam = entityAccessData.inTeam; + let isOwner = entityAccessData.isOwner; if (this.getUser().isAdmin()) { if (data === false) { @@ -140,7 +140,7 @@ _.extend(Class.prototype, /** @lends Class# */ { } } - var result = false; + let result = false; if (value === 'team') { result = inTeam; @@ -168,19 +168,19 @@ _.extend(Class.prototype, /** @lends Class# */ { } return result; - }, + } /** * Check access to model (entity). * * @param {module:model} model A model. - * @param {Object|string|null} data Access data. + * @param {Object.|string|null} data Access data. * @param {module:acl-manager~action|null} [action=null] Action to check. * @param {boolean} [precise=false] To return `null` if not enough data is set in a model. * E.g. the `teams` field is not yet loaded. * @returns {boolean|null} True if has access, null if not clear. */ - checkModel: function (model, data, action, precise) { + checkModel(model, data, action, precise) { if (this.getUser().isAdmin()) { return true; } @@ -191,18 +191,18 @@ _.extend(Class.prototype, /** @lends Class# */ { }; return this.checkScope(data, action, precise, entityAccessData); - }, + } /** * Check `delete` access to model. * * @param {module:model} model A model. - * @param {Object|string|null} data Access data. + * @param {Object.|string|null} data Access data. * @param {boolean} [precise=false] To return `null` if not enough data is set in a model. * E.g. the `teams` field is not yet loaded. * @returns {boolean} True if has access. */ - checkModelDelete: function (model, data, precise) { + checkModelDelete(model, data, precise) { let result = this.checkModel(model, data, 'delete', precise); if (result) { @@ -213,7 +213,7 @@ _.extend(Class.prototype, /** @lends Class# */ { return false; } - var d = data || {}; + let d = data || {}; if (d.read === 'no') { return false; @@ -237,7 +237,7 @@ _.extend(Class.prototype, /** @lends Class# */ { } return result; - }, + } /** * Check if a user is owner to a model. @@ -245,7 +245,7 @@ _.extend(Class.prototype, /** @lends Class# */ { * @param {module:model} model A model. * @returns {boolean|null} True if owner. Null if not clear. */ - checkIsOwner: function (model) { + checkIsOwner(model) { let result = false; if (model.hasField('assignedUser')) { @@ -282,7 +282,7 @@ _.extend(Class.prototype, /** @lends Class# */ { } return result; - }, + } /** * Check if a user in a team of a model. @@ -290,7 +290,7 @@ _.extend(Class.prototype, /** @lends Class# */ { * @param {module:model} model A model. * @returns {boolean|null} True if in a team. Null if not clear. */ - checkInTeam: function (model) { + checkInTeam(model) { var userTeamIdList = this.getUser().getTeamIdList(); if (!model.has('teamsIds')) { @@ -301,9 +301,9 @@ _.extend(Class.prototype, /** @lends Class# */ { return null; } - var teamIdList = model.getTeamIdList(); + let teamIdList = model.getTeamIdList(); - var inTeam = false; + let inTeam = false; userTeamIdList.forEach(id => { if (~teamIdList.indexOf(id)) { @@ -312,10 +312,9 @@ _.extend(Class.prototype, /** @lends Class# */ { }); return inTeam; - }, + } +} -}); +Acl.extend = BullView.extend; -Class.extend = Bull.View.extend; - -export default Class; +export default Acl; diff --git a/client/src/action-handler.js b/client/src/action-handler.js index 187a91944c..9196a770ff 100644 --- a/client/src/action-handler.js +++ b/client/src/action-handler.js @@ -28,115 +28,115 @@ /** @module action-handler */ +import {View as BullView} from 'lib!bullbone'; + /** * An action handler. To be extended by specific action handlers. - * - * @constructor - * @param {module:view} view A view. - * @memberOf module:action-handler */ -const ActionHandler = function (view) { - /** - * @memberof ActionHandler# - * @protected - */ - this.view = view; -}; +class ActionHandler { -_.extend(ActionHandler.prototype, /** @lends ActionHandler# */{ + /** + * @param {module:view} view A view. + */ + constructor(view) { + /** + * @protected + */ + this.view = view; + } /** * @deprecated Use `this.view`. */ - getConfig: function () { + getConfig() { return this.view.getConfig(); - }, + } /** * @deprecated Use `this.view`. */ - getMetadata: function () { + getMetadata() { return this.view.getMetadata(); - }, + } /** * @deprecated Use `this.view`. */ - getAcl: function () { + getAcl() { return this.view.getAcl(); - }, + } /** * @deprecated Use `this.view`. */ - getUser: function () { + getUser() { return this.view.getUser(); - }, + } /** * @deprecated Use `this.view`. */ - getRouter: function () { + getRouter() { return this.view.getRouter(); - }, + } /** * @deprecated Use `this.view`. */ - getHelper: function () { + getHelper() { return this.view.getHelper(); - }, + } /** * @deprecated Use `this.view`. */ - getLanguage: function () { + getLanguage() { return this.view.getLanguage(); - }, + } /** * @deprecated Use `this.view`. */ - getModelFactory: function () { + getModelFactory() { return this.view.getModelFactory(); - }, + } /** * @deprecated Use `this.view`. */ - getCollectionFactory: function () { + getCollectionFactory() { return this.view.getCollectionFactory(); - }, + } /** * @deprecated Use `Espo.Ajax`. */ - ajaxPostRequest: function () { + ajaxPostRequest() { return Espo.Ajax.postRequest.apply(this.view, arguments); - }, + } /** * @deprecated Use `Espo.Ajax`. */ - ajaxPutRequest: function () { + ajaxPutRequest() { return Espo.Ajax.putRequest.apply(this.view, arguments); - }, + } /** * @deprecated Use `Espo.Ajax`. */ - ajaxGetRequest: function () { + ajaxGetRequest() { return Espo.Ajax.getRequest.apply(this.view, arguments); - }, + } /** * @deprecated Use `this.view`. */ - confirm: function () { + confirm() { return this.view.confirm.apply(this.view, arguments); - }, -}); + } +} -ActionHandler.extend = Bull.View.extend; +ActionHandler.extend = BullView.extend; export default ActionHandler; diff --git a/client/src/dynamic-handler.js b/client/src/dynamic-handler.js index 04a91a42cf..8860192ff5 100644 --- a/client/src/dynamic-handler.js +++ b/client/src/dynamic-handler.js @@ -28,6 +28,8 @@ /** @module dynamic-handler */ +import {View as BullView} from 'lib!bullbone'; + /** * A dynamic handler. To be extended by a specific handler. */ @@ -82,6 +84,6 @@ class DynamicHandler { } } -DynamicHandler.extend = Bull.View.extend; +DynamicHandler.extend = BullView.extend; export default DynamicHandler;