Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
yurikuzn committed Jun 20, 2023
1 parent cc32089 commit fc8be6d
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 72 deletions.
23 changes: 12 additions & 11 deletions client/src/acl-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class AclManager {
getPermissionLevel(permission) {
let permissionKey = permission;

if (permission.substr(-10) !== 'Permission') {
if (permission.slice(-10) !== 'Permission') {
permissionKey = permission + 'Permission';
}

Expand Down Expand Up @@ -201,7 +201,7 @@ class AclManager {
* @param {string} scope A scope.
* @param {module:acl-manager~action|null} [action=null] An action.
* @param {boolean} [precise=false] Deprecated. Not used.
* @returns {boolean} True if has access.
* @returns {boolean} True if access allowed.
*/
checkScope(scope, action, precise) {
let data = (this.data.table || {})[scope];
Expand All @@ -220,7 +220,7 @@ class AclManager {
* @param {module:acl-manager~action|null} [action=null] An action.
* @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.
* @returns {boolean|null} True if access allowed, null if not enough data to determine.
*/
checkModel(model, action, precise) {
var scope = model.name;
Expand Down Expand Up @@ -264,7 +264,7 @@ class AclManager {
* @param {module:acl-manager~action|null} [action=null] An action.
* @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} {boolean|null} True if has access, null if not clear.
* @returns {boolean|null} True if access allowed, null if not enough data to determine.
*/
check(subject, action, precise) {
if (typeof subject === 'string') {
Expand All @@ -284,6 +284,7 @@ class AclManager {
return this.getImplementation(model.name).checkIsOwner(model);
}

// noinspection JSUnusedGlobalSymbols
/**
* Check if a user in a team of a model.
*
Expand All @@ -298,7 +299,7 @@ class AclManager {
* Check an assignment permission to a user.
*
* @param {module:models/user} user A user.
* @returns {boolean} True if has access.
* @returns {boolean} True if access allowed.
*/
checkAssignmentPermission(user) {
return this.checkPermission('assignmentPermission', user);
Expand All @@ -308,7 +309,7 @@ class AclManager {
* Check a user permission to a user.
*
* @param {module:models/user} user A user.
* @returns {boolean} True if has access.
* @returns {boolean} True if access allowed.
*/
checkUserPermission(user) {
return this.checkPermission('userPermission', user);
Expand All @@ -319,14 +320,14 @@ class AclManager {
*
* @param {string} permission A permission name.
* @param {module:models/user} user A user.
* @returns {boolean} True if has access.
* @returns {boolean} True if access allowed.
*/
checkPermission(permission, user) {
if (this.getUser().isAdmin()) {
return true;
}

let level = this.get(permission);
let level = this.getPermissionLevel(permission);

if (level === 'no') {
if (user.id === this.getUser().id) {
Expand Down Expand Up @@ -458,10 +459,10 @@ class AclManager {
* Check an assignment permission to a team.
*
* @param {string} teamId A team ID.
* @returns {boolean} True if has access.
* @returns {boolean} True if access allowed.
*/
checkTeamAssignmentPermission(teamId) {
if (this.get('assignmentPermission') === 'all') {
if (this.getPermissionLevel('assignmentPermission') === 'all') {
return true;
}

Expand All @@ -473,7 +474,7 @@ class AclManager {
* @param {string} scope An entity type.
* @param {string} field A field.
* @param {'read'|'edit'} [action='read'] An action.
* @returns {boolean} True if has access.
* @returns {boolean} True if access allowed.
*/
checkField(scope, field, action) {
return !~this.getScopeForbiddenFieldList(scope, action).indexOf(field);
Expand Down
14 changes: 12 additions & 2 deletions client/src/acl-portal-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,34 @@ import AclPortal from 'acl-portal';
*/
class AclPortalManager extends AclManager {

// noinspection JSUnusedGlobalSymbols
/**
* Check if a user in an account of a model.
*
* @param {module:model} model A model.
* @returns {boolean|null} True if in an account, null if not clear.
*/
checkInAccount(model) {
return this.getImplementation(model.name).checkInAccount(model);
const impl =
/** @type {module:acl-portal} */
this.getImplementation(model.name);

return impl.checkInAccount(model);
}

// noinspection JSUnusedGlobalSymbols
/**
* Check if a user is a contact-owner to a model.
*
* @param {module:model} model A model.
* @returns {boolean|null} True if in a contact-owner, null if not clear.
*/
checkIsOwnContact(model) {
return this.getImplementation(model.name).checkIsOwnContact(model);
const impl =
/** @type {module:acl-portal} */
this.getImplementation(model.name);

return impl.checkIsOwnContact(model);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions client/src/acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Acl {
* @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.
* @returns {boolean|null} True if access allowed.
*/
checkScope(data, action, precise, entityAccessData) {
entityAccessData = entityAccessData || {};
Expand Down Expand Up @@ -178,7 +178,7 @@ class Acl {
* @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.
* @returns {boolean|null} True if access allowed, null if not enough data to determine.
*/
checkModel(model, data, action, precise) {
if (this.getUser().isAdmin()) {
Expand All @@ -193,14 +193,15 @@ class Acl {
return this.checkScope(data, action, precise, entityAccessData);
}

// noinspection JSUnusedGlobalSymbols
/**
* Check `delete` access to model.
*
* @param {module:model} model A model.
* @param {Object.<string, string>|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.
* @returns {boolean} True if access allowed.
*/
checkModelDelete(model, data, precise) {
let result = this.checkModel(model, data, 'delete', precise);
Expand Down Expand Up @@ -288,7 +289,7 @@ class Acl {
* Check if a user in a team of a model.
*
* @param {module:model} model A model.
* @returns {boolean|null} True if in a team. Null if not clear.
* @returns {boolean|null} True if in a team. Null if not enough data to determine.
*/
checkInTeam(model) {
var userTeamIdList = this.getUser().getTeamIdList();
Expand Down
14 changes: 9 additions & 5 deletions client/src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

/** @module ajax */

// noinspection JSUnusedGlobalSymbols

/**
* Functions for API HTTP requests.
*/
Expand Down Expand Up @@ -106,7 +108,7 @@ const Ajax = Espo.Ajax = {
data = JSON.stringify(data);
}

return Ajax.request(url, 'POST', data, options);
return /** @type {Promise<any>} */ Ajax.request(url, 'POST', data, options);
},

/**
Expand All @@ -122,7 +124,7 @@ const Ajax = Espo.Ajax = {
data = JSON.stringify(data);
}

return Ajax.request(url, 'PATCH', data, options);
return /** @type {Promise<any>} */ Ajax.request(url, 'PATCH', data, options);
},

/**
Expand All @@ -138,7 +140,7 @@ const Ajax = Espo.Ajax = {
data = JSON.stringify(data);
}

return Ajax.request(url, 'PUT', data, options);
return /** @type {Promise<any>} */ Ajax.request(url, 'PUT', data, options);
},

/**
Expand All @@ -154,7 +156,7 @@ const Ajax = Espo.Ajax = {
data = JSON.stringify(data);
}

return Ajax.request(url, 'DELETE', data, options);
return /** @type {Promise<any>} */ Ajax.request(url, 'DELETE', data, options);
},

/**
Expand All @@ -166,7 +168,7 @@ const Ajax = Espo.Ajax = {
* @returns {Promise<any>}
*/
getRequest: function (url, data, options) {
return Ajax.request(url, 'GET', data, options);
return /** @type {Promise<any>} */ Ajax.request(url, 'GET', data, options);
},
};

Expand Down Expand Up @@ -257,13 +259,15 @@ class XhrWrapper {
return this.xhr.status;
}

// noinspection JSUnusedGlobalSymbols
/**
* @return {*}
*/
getResponseParsedBody() {
return this.xhr.responseJSON;
}

// noinspection JSUnusedGlobalSymbols
/**
* @return {string}
*/
Expand Down
2 changes: 1 addition & 1 deletion client/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class App {

/**
* @private
* @type {module:number-util|null}
* @type {module:num-util|null}
*/
numberUtil = null

Expand Down
15 changes: 9 additions & 6 deletions client/src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class Collection {
* @param {Model[]|Model|string} models Models, a model or a model ID.
* @param {{
* silent?: boolean,
* }} [options] Options.
* } & Object.<string, *>} [options] Options.
* @return {this}
* @fires Collection#update
*/
Expand Down Expand Up @@ -273,7 +273,7 @@ class Collection {
* merge?: boolean,
* remove?: boolean,
* index?: number,
* }} [options]
* } & Object.<string, *>} [options]
* @return {Model[]}
*/
set(models, options) {
Expand Down Expand Up @@ -427,7 +427,7 @@ class Collection {
* @param {Model[]|null} [models] Models to replace the collection with.
* @param {{
* silent?: boolean,
* }} [options]
* } & Object.<string, *>} [options]
* @return {this}
* @fires Collection#reset
*/
Expand Down Expand Up @@ -897,8 +897,9 @@ class Collection {
return this._prepareModel({});
}

// noinspection JSUnusedGlobalSymbols
/**
* Compose a URL for syncing.
* Compose a URL for syncing. Called from Model.sync.
*
* @protected
* @return {string}
Expand Down Expand Up @@ -1017,6 +1018,7 @@ class Collection {
this.trigger.apply(this, arguments);
}

// noinspection JSDeprecatedSymbols
/** @private*/
_prepareModel(attributes) {
if (this._isModel(attributes)) {
Expand All @@ -1027,9 +1029,10 @@ class Collection {
return attributes;
}

const Model = this.model;
const ModelClass = this.model;

return new Model(attributes, {
// noinspection JSValidateTypes
return new ModelClass(attributes, {
collection: this,
entityType: this.entityType || this.name,
defs: this.defs,
Expand Down
2 changes: 1 addition & 1 deletion client/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class Controller {
continue;
}

let key = k.substr(15);
let key = k.slice(15);

this.clearStoredMainView(key);
}
Expand Down
Loading

0 comments on commit fc8be6d

Please sign in to comment.