From 716e434099feca53a763e547fcaa9cd29033ec0c Mon Sep 17 00:00:00 2001 From: yuri Date: Wed, 11 Mar 2015 12:15:51 +0200 Subject: [PATCH] assignmentPermission 2 --- .../Espo/Resources/i18n/en_US/Role.json | 3 ++ .../Espo/Resources/i18n/en_US/User.json | 3 ++ .../Resources/metadata/clientDefs/Team.json | 3 +- .../Resources/metadata/clientDefs/User.json | 3 +- .../Resources/metadata/entityDefs/Role.json | 3 +- application/Espo/SelectManagers/Team.php | 39 +++++++++++++++ application/Espo/SelectManagers/User.php | 15 ++++++ frontend/client/src/acl.js | 9 +++- frontend/client/src/search-manager.js | 5 ++ .../client/src/views/fields/assigned-user.js | 47 +++++++++++++++++++ frontend/client/src/views/fields/base.js | 3 +- .../client/src/views/fields/link-multiple.js | 3 ++ .../client/src/views/fields/link-parent.js | 12 +++-- frontend/client/src/views/fields/link.js | 5 +- frontend/client/src/views/fields/teams.js | 37 +++++++++++++++ .../client/src/views/modals/select-records.js | 8 +++- .../client/src/views/record/detail-side.js | 7 ++- frontend/client/src/views/record/edit-side.js | 13 ++++- 18 files changed, 204 insertions(+), 14 deletions(-) create mode 100644 application/Espo/SelectManagers/Team.php create mode 100644 frontend/client/src/views/fields/assigned-user.js create mode 100644 frontend/client/src/views/fields/teams.js diff --git a/application/Espo/Resources/i18n/en_US/Role.json b/application/Espo/Resources/i18n/en_US/Role.json index d9a5296506..770afd358f 100644 --- a/application/Espo/Resources/i18n/en_US/Role.json +++ b/application/Espo/Resources/i18n/en_US/Role.json @@ -8,6 +8,9 @@ "users": "Users", "teams": "Teams" }, + "tooltips": { + "assignmentPermission": "Allows to restrict an ability for users to assign records to other users.\n\nall - no restriction\n\nteam - can assign users from own teams\n\nno - can assign only to self" + }, "labels": { "Access": "Access", "Create Role": "Create Role" diff --git a/application/Espo/Resources/i18n/en_US/User.json b/application/Espo/Resources/i18n/en_US/User.json index 82d9f989fe..cef0754bcc 100644 --- a/application/Espo/Resources/i18n/en_US/User.json +++ b/application/Espo/Resources/i18n/en_US/User.json @@ -55,5 +55,8 @@ "forbidden": "Forbidden, please try later", "uniqueLinkHasBeenSent": "The unique link has been sent to the specified email address.", "passwordChangedByRequest": "Password has been changed." + }, + "boolFilters": { + "onlyMyTeam": "Only My Team" } } diff --git a/application/Espo/Resources/metadata/clientDefs/Team.json b/application/Espo/Resources/metadata/clientDefs/Team.json index 1708bf2bbc..9503f16774 100644 --- a/application/Espo/Resources/metadata/clientDefs/Team.json +++ b/application/Espo/Resources/metadata/clientDefs/Team.json @@ -10,5 +10,6 @@ "detail":"Team.Record.Detail", "edit":"Team.Record.Edit", "list":"Team.Record.List" - } + }, + "boolFilters": ["onlyMy"] } diff --git a/application/Espo/Resources/metadata/clientDefs/User.json b/application/Espo/Resources/metadata/clientDefs/User.json index eeeb98479f..d17d30132d 100644 --- a/application/Espo/Resources/metadata/clientDefs/User.json +++ b/application/Espo/Resources/metadata/clientDefs/User.json @@ -4,5 +4,6 @@ "edit":"User.Record.Edit", "editQuick":"User.Record.Edit", "list":"User.Record.List" - } + }, + "boolFilters": ["onlyMyTeam"] } diff --git a/application/Espo/Resources/metadata/entityDefs/Role.json b/application/Espo/Resources/metadata/entityDefs/Role.json index a61562a1c5..0480dd131b 100644 --- a/application/Espo/Resources/metadata/entityDefs/Role.json +++ b/application/Espo/Resources/metadata/entityDefs/Role.json @@ -8,7 +8,8 @@ "assignmentPermission": { "type": "enum", "options": ["not-set", "all", "team", "no"], - "default": "not-set" + "default": "not-set", + "tooltip": true }, "data": { "type": "jsonObject" diff --git a/application/Espo/SelectManagers/Team.php b/application/Espo/SelectManagers/Team.php new file mode 100644 index 0000000000..2808997d21 --- /dev/null +++ b/application/Espo/SelectManagers/Team.php @@ -0,0 +1,39 @@ + $this->getUser()->id + ); + $result['distinct'] = true; + } +} + diff --git a/application/Espo/SelectManagers/User.php b/application/Espo/SelectManagers/User.php index 39c0b960ba..61dda36bda 100644 --- a/application/Espo/SelectManagers/User.php +++ b/application/Espo/SelectManagers/User.php @@ -33,5 +33,20 @@ class User extends \Espo\Core\SelectManagers\Base ); } } + + protected function boolFilterOnlyMyTeam(&$result) + { + if (!in_array('teams', $result['joins'])) { + $result['joins'][] = 'teams'; + } + $teamIds = $this->getUser()->get('teamsIds'); + if (empty($teamIds)) { + $teamIds = []; + } + $result['whereClause'][] = array( + 'teamUser.teamId' => $teamIds + ); + $result['distinct'] = true; + } } diff --git a/frontend/client/src/acl.js b/frontend/client/src/acl.js index c967c8868a..e7f670470b 100644 --- a/frontend/client/src/acl.js +++ b/frontend/client/src/acl.js @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ /** @@ -48,6 +48,13 @@ _.extend(Espo.Acl.prototype, { this.data.table = this.data.table || {}; }, + get: function (name) { + if (this.user.isAdmin()) { + return true; + } + return this.data[name] || null; + }, + check: function (controller, action, isOwner, inTeam) { if (this.user.isAdmin()) { return true; diff --git a/frontend/client/src/search-manager.js b/frontend/client/src/search-manager.js index 84f29c9450..24a73891a1 100644 --- a/frontend/client/src/search-manager.js +++ b/frontend/client/src/search-manager.js @@ -153,6 +153,11 @@ this.data.advanced = advanced; }, + setBool: function (bool) { + this.data = Espo.Utils.clone(this.data); + this.data.bool = bool; + }, + set: function (data) { this.data = data; if (this.storage) { diff --git a/frontend/client/src/views/fields/assigned-user.js b/frontend/client/src/views/fields/assigned-user.js new file mode 100644 index 0000000000..fd1fcbeaab --- /dev/null +++ b/frontend/client/src/views/fields/assigned-user.js @@ -0,0 +1,47 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko + * Website: http://www.espocrm.com + * + * EspoCRM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EspoCRM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EspoCRM. If not, see http://www.gnu.org/licenses/. + ************************************************************************/ + +Espo.define('Views.Fields.AssignedUser', 'Views.Fields.UserWithAvatar', function (Dep) { + + return Dep.extend({ + + init: function () { + + if (this.getAcl().get('assignmentPermission') == 'no') { + this.readOnly = true; + + /*if (this.mode == 'edit') { + this.mode = 'detail'; + }*/ + } + Dep.prototype.init.call(this); + }, + + getSelectBoolFilters: function () { + var assignmentPermission = this.getAcl().get('assignmentPermission'); + if (assignmentPermission == 'team') { + return {'onlyMyTeam': true}; + } + }, + + }); +}); + diff --git a/frontend/client/src/views/fields/base.js b/frontend/client/src/views/fields/base.js index 005cea624f..19fdd4f6f6 100644 --- a/frontend/client/src/views/fields/base.js +++ b/frontend/client/src/views/fields/base.js @@ -212,7 +212,8 @@ Espo.define('Views.Fields.Base', 'View', function (Dep) { $a.popover({ placement: 'bottom', container: 'body', - content: this.translate(this.name, 'tooltips', this.model.name), + html: true, + content: this.translate(this.name, 'tooltips', this.model.name).replace(/\n/g, "
"), trigger: 'click', }).on('shown.bs.popover', function () { $('body').one('click', function () { diff --git a/frontend/client/src/views/fields/link-multiple.js b/frontend/client/src/views/fields/link-multiple.js index fca0845166..647f3aa46c 100644 --- a/frontend/client/src/views/fields/link-multiple.js +++ b/frontend/client/src/views/fields/link-multiple.js @@ -54,6 +54,8 @@ Espo.define('Views.Fields.LinkMultiple', 'Views.Fields.Base', function (Dep) { getSelectFilters: function () {}, + getSelectBoolFilters: function () {}, + setup: function () { this.nameHashName = this.name + 'Names'; this.idsName = this.name + 'Ids'; @@ -82,6 +84,7 @@ Espo.define('Views.Fields.LinkMultiple', 'Views.Fields.Base', function (Dep) { scope: this.foreignScope, createButton: this.mode != 'search', filters: this.getSelectFilters(), + boolFilters: this.getSelectBoolFilters(), multiple: true }, function (dialog) { dialog.render(); diff --git a/frontend/client/src/views/fields/link-parent.js b/frontend/client/src/views/fields/link-parent.js index 9dfabb3ebe..fa98d55f2e 100644 --- a/frontend/client/src/views/fields/link-parent.js +++ b/frontend/client/src/views/fields/link-parent.js @@ -52,6 +52,10 @@ Espo.define('Views.Fields.LinkParent', 'Views.Fields.Base', function (Dep) { }, Dep.prototype.data.call(this)); }, + getSelectFilters: function () {}, + + getSelectBoolFilters: function () {}, + setup: function () { this.nameName = this.name + 'Name'; this.typeName = this.name + 'Type'; @@ -76,9 +80,11 @@ Espo.define('Views.Fields.LinkParent', 'Views.Fields.Base', function (Dep) { this.addActionHandler('selectLink', function () { this.notify('Loading...'); this.createView('dialog', 'Modals.SelectRecords', { - scope: this.foreignScope, - createButton: this.mode != 'search' - }, function (dialog) { + scope: this.foreignScope, + createButton: this.mode != 'search', + filters: this.getSelectFilters(), + boolFilters: this.getSelectBoolFilters(), + }, function (dialog) { dialog.render(); Espo.Ui.notify(false); dialog.once('select', function (model) { diff --git a/frontend/client/src/views/fields/link.js b/frontend/client/src/views/fields/link.js index 50d48fc1fa..0cf8e0886f 100644 --- a/frontend/client/src/views/fields/link.js +++ b/frontend/client/src/views/fields/link.js @@ -51,6 +51,8 @@ Espo.define('Views.Fields.Link', 'Views.Fields.Base', function (Dep) { getSelectFilters: function () {}, + getSelectBoolFilters: function () {}, + setup: function () { this.nameName = this.name + 'Name'; this.idName = this.name + 'Id'; @@ -67,7 +69,8 @@ Espo.define('Views.Fields.Link', 'Views.Fields.Base', function (Dep) { this.createView('dialog', 'Modals.SelectRecords', { scope: this.foreignScope, createButton: this.mode != 'search', - filters: this.getSelectFilters() + filters: this.getSelectFilters(), + boolFilters: this.getSelectBoolFilters(), }, function (dialog) { dialog.render(); self.notify(false); diff --git a/frontend/client/src/views/fields/teams.js b/frontend/client/src/views/fields/teams.js new file mode 100644 index 0000000000..45471a8faf --- /dev/null +++ b/frontend/client/src/views/fields/teams.js @@ -0,0 +1,37 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko + * Website: http://www.espocrm.com + * + * EspoCRM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EspoCRM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EspoCRM. If not, see http://www.gnu.org/licenses/. + ************************************************************************/ + +Espo.define('Views.Fields.Teams', 'Views.Fields.LinkMultiple', function (Dep) { + + return Dep.extend({ + + getSelectBoolFilters: function () { + var assignmentPermission = this.getAcl().get('assignmentPermission'); + if (assignmentPermission == 'team' || assignmentPermission == 'no') { + return {'onlyMy': true}; + } + }, + + + }); +}); + + diff --git a/frontend/client/src/views/modals/select-records.js b/frontend/client/src/views/modals/select-records.js index 9ec1042e61..6e94f01b5d 100644 --- a/frontend/client/src/views/modals/select-records.js +++ b/frontend/client/src/views/modals/select-records.js @@ -50,6 +50,7 @@ Espo.define('Views.Modals.SelectRecords', 'Views.Modal', function (Dep) { setup: function () { this.filters = this.options.filters || {}; + this.boolFilters = this.options.boolFilters || {}; if ('multiple' in this.options) { this.multiple = this.options.multiple; @@ -116,7 +117,12 @@ Espo.define('Views.Modals.SelectRecords', 'Views.Modal', function (Dep) { var searchManager = new SearchManager(collection, 'listSelect', null, this.getDateTime()); searchManager.emptyOnReset = true; - searchManager.setAdvanced(this.filters); + if (this.filters) { + searchManager.setAdvanced(this.filters); + } + if (this.boolFilters) { + searchManager.setBool(this.boolFilters); + } collection.where = searchManager.getWhere(); this.createView('search', 'Record.Search', { diff --git a/frontend/client/src/views/record/detail-side.js b/frontend/client/src/views/record/detail-side.js index 1e86eaa7f4..ae631354ba 100644 --- a/frontend/client/src/views/record/detail-side.js +++ b/frontend/client/src/views/record/detail-side.js @@ -37,9 +37,12 @@ fieldList: [ { name: 'assignedUser', - view: 'Fields.UserWithAvatar' + view: 'Fields.AssignedUser' }, - 'teams' + { + name: 'teams', + view: 'Fields.Teams' + } ], mode: 'detail', } diff --git a/frontend/client/src/views/record/edit-side.js b/frontend/client/src/views/record/edit-side.js index f11438019c..075a3b5b84 100644 --- a/frontend/client/src/views/record/edit-side.js +++ b/frontend/client/src/views/record/edit-side.js @@ -31,11 +31,20 @@ Espo.define('Views.Record.EditSide', 'Views.Record.DetailSide', function (Dep) { label: false, view: 'Record.Panels.Side', options: { - fieldList: ['assignedUser', 'teams'], + fieldList: [ + { + name: 'assignedUser', + view: 'Fields.AssignedUser' + }, + { + name: 'teams', + view: 'Fields.Teams' + } + ], mode: 'edit', } } - ], + ] }); });