user api type

This commit is contained in:
yuri
2018-10-24 16:46:48 +03:00
parent a235ad1bc3
commit b28bae20b7
24 changed files with 262 additions and 11 deletions
@@ -54,6 +54,8 @@ class EntityManager
private $linkForbiddenNameList = ['posts', 'stream', 'subscription'];
private $forbiddenEntityTypeNameList = ['PortalUser', 'ApiUser'];
public function __construct(Metadata $metadata, Language $language, File\Manager $fileManager, Config $config, Container $container = null)
{
$this->metadata = $metadata;
@@ -192,6 +194,10 @@ class EntityManager
throw new Conflict('Entity name \''.$name.'\' is not allowed.');
}
if (in_array($name, $this->forbiddenEntityTypeNameList)) {
throw new Conflict('Entity name \''.$name.'\' is not allowed.');
}
if (in_array(strtolower($name), $this->reservedWordList)) {
throw new Conflict('Entity name \''.$name.'\' is not allowed.');
}
+26
View File
@@ -51,6 +51,11 @@ class User extends \Espo\Core\Entities\Person
return $this->isPortal();
}
public function isRegular()
{
return $this->get('type') === 'regular';
}
public function isApi()
{
return $this->get('type') === 'api';
@@ -84,4 +89,25 @@ class User extends \Espo\Core\Entities\Person
}
}
}
protected function _getName()
{
if (!array_key_exists('name', $this->valuesContainer) || !$this->valuesContainer['name']) {
if ($this->get('userName')) {
return $this->get('userName');
}
}
return $this->valuesContainer['name'];
}
protected function _hasName()
{
if (array_key_exists('name', $this->valuesContainer)) {
return true;
}
if ($this->has('userName')) {
return true;
}
return false;
}
}
+2
View File
@@ -203,6 +203,8 @@ class Stream extends \Espo\Core\Hooks\Base
if (
!$this->getUser()->isSystem()
&&
!$this->getUser()->isApi()
&&
$createdById
&&
$createdById === $this->getUser()->id
+15
View File
@@ -133,4 +133,19 @@ class User extends \Espo\Core\ORM\Repositories\RDB
}
return false;
}
public function handleSelectParams(&$params)
{
parent::handleSelectParams($params);
if (array_key_exists('select', $params)) {
if (in_array('name', $params['select'])) {
$additionalAttributeList = ['userName'];
foreach ($additionalAttributeList as $attribute) {
if (!in_array($attribute, $params['select'])) {
$params['select'][] = $attribute;
}
}
}
}
}
}
@@ -0,0 +1,5 @@
{
"labels": {
"Create ApiUser": "Create API User"
}
}
@@ -24,6 +24,7 @@
"Attachment": "Attachment",
"EmailFolder": "Email Folder",
"PortalUser": "Portal User",
"ApiUser": "API User",
"ScheduledJobLogRecord": "Scheduled Job Log Record",
"PasswordChangeRequest": "Password Change Request",
"ActionHistoryRecord": "Action History Record",
@@ -74,6 +75,7 @@
"Attachment": "Attachments",
"EmailFolder": "Email Folders",
"PortalUser": "Portal Users",
"ApiUser": "API Users",
"ScheduledJobLogRecord": "Scheduled Job Log Records",
"PasswordChangeRequest": "Password Change Requests",
"ActionHistoryRecord": "Action History",
@@ -30,7 +30,8 @@
"ipAddress": "IP Address",
"passwordPreview": "Password Preview",
"isSuperAdmin": "Is Super Admin",
"lastAccess": "Last Access"
"lastAccess": "Last Access",
"apiKey": "API Key"
},
"links": {
"teams": "Teams",
@@ -4,7 +4,7 @@
"createdBy",
"emailAddress",
"title",
"isAdmin",
"type",
"isActive",
"position",
"portals",
@@ -0,0 +1,34 @@
{
"controller": "controllers/api-user",
"views": {
"detail": "views/user/detail",
"list": "views/api-user/list"
},
"recordViews": {
"list": "views/user/record/list",
"detail": "views/user/record/detail",
"edit":"views/user/record/edit",
"detailSmall":"views/user/record/detail-quick",
"editSmall":"views/user/record/edit-quick"
},
"defaultSidePanelFieldLists": {
"detail": [
"avatar",
"createdAt",
"lastAccess"
],
"detailSmall": [
"avatar",
"createdAt"
],
"edit": [
"avatar"
],
"editSmall": [
"avatar"
]
},
"filterList": [
],
"boolFilterList": []
}
@@ -37,6 +37,15 @@
"disabled": true,
"notStorable": true
},
"apiKey": {
"type": "varchar",
"maxLength": 36,
"readOnly": true,
"layoutMassUpdateDisabled": true,
"layoutDetailDisabled": true,
"layoutFiltersDisabled": true,
"layoutListDisabled": true
},
"salutationName": {
"type": "enum",
"options": ["", "Mr.", "Ms.", "Mrs.", "Dr."]
+1 -1
View File
@@ -69,7 +69,7 @@ class Note extends Record
if ($preferences && $preferences->get('followEntityOnStreamPost')) {
if ($this->getMetadata()->get(['scopes', $entity->get('parentType'), 'stream'])) {
$parent = $this->getEntityManager()->getEntity($entity->get('parentType'), $entity->get('parentId'));
if ($parent) {
if ($parent && !$this->getUser()->isSystem() && !$this->getUser()->isApi()) {
$this->getServiceFactory()->create('Stream')->followEntity($parent, $this->getUser()->id);
}
}
+1 -1
View File
@@ -545,7 +545,7 @@ class Stream extends \Espo\Core\Services\Base
'order' => 'DESC'
];
if (!$user->isPortal() || $user->isAdmin()) {
if ((!$user->isPortal() || $user->isAdmin()) && !$user->isApi()) {
$selectParamsList[] = [
'select' => $select,
'leftJoins' => ['createdBy'],
+2 -1
View File
@@ -61,7 +61,8 @@ class User extends Record
'portalRolesIds',
'contactId',
'accountsIds',
'type'
'type',
'apiKey'
];
protected $mandatorySelectAttributeList = [
+63
View File
@@ -0,0 +1,63 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2018 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/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
Espo.define('controllers/api-user', 'controllers/record', function (Dep) {
return Dep.extend({
entityType: 'User',
getCollection: function (callback, context, usePreviouslyFetched) {
context = context || this;
Dep.prototype.getCollection.call(this, function (collection) {
collection.data.filterList = ['api'];
callback.call(context, collection);
}, context, usePreviouslyFetched);
},
createViewView: function (options, model) {
if (!model.isApi()) {
if (model.isPortal()) {
this.getRouter().dispatch('PortalUser', 'view', {id: model.id, model: model});
return;
}
this.getRouter().dispatch('User', 'view', {id: model.id, model: model});
return;
}
Dep.prototype.createViewView.call(this, options, model);
},
create: function (options) {
options = options || {};
options.attributes = options.attributes || {};
options.attributes.type = 'api';
Dep.prototype.create.call(this, options);
}
});
});
+11
View File
@@ -42,10 +42,21 @@ Espo.define('controllers/portal-user', 'controllers/record', function (Dep) {
createViewView: function (options, model) {
if (!model.isPortal()) {
if (model.isApi()) {
this.getRouter().dispatch('ApiUser', 'view', {id: model.id, model: model});
return;
}
this.getRouter().dispatch('User', 'view', {id: model.id, model: model});
return;
}
Dep.prototype.createViewView.call(this, options, model);
},
create: function (options) {
options = options || {};
options.attributes = options.attributes || {};
options.attributes.type = 'portal';
Dep.prototype.create.call(this, options);
}
});
+4
View File
@@ -43,6 +43,10 @@ Espo.define('controllers/user', 'controllers/record', function (Dep) {
this.getRouter().dispatch('PortalUser', 'view', {id: model.id, model: model});
return;
}
if (model.isApi()) {
this.getRouter().dispatch('ApiUser', 'view', {id: model.id, model: model});
return;
}
Dep.prototype.createViewView.call(this, options, model);
}
+4
View File
@@ -41,6 +41,10 @@ Espo.define('models/user', 'model', function (Dep) {
isApi: function () {
return this.get('type') == 'api';
},
isRegular: function () {
return this.get('type') == 'regular';
}
});
});
+51
View File
@@ -0,0 +1,51 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2018 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/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
Espo.define('views/api-user/list', 'views/list', function (Dep) {
return Dep.extend({
setup: function () {
Dep.prototype.setup.call(this);
},
actionCreate: function () {
var attributes = {
type: 'api'
};
var router = this.getRouter();
var url = '#' + this.scope + '/create';
router.dispatch(this.scope, 'create', {
attributes: attributes
});
router.navigate(url, {trigger: false});
}
});
});
+1
View File
@@ -370,6 +370,7 @@ Espo.define('views/modals/detail', 'views/modal', function (Dep) {
var viewName = this.getMetadata().get(['clientDefs', this.scope, 'modalViews', 'edit']) || 'views/modals/edit';
this.createView('quickEdit', viewName, {
scope: this.scope,
entityType: this.model.entityType,
id: this.id,
fullFormDisabled: this.fullFormDisabled
}, function (view) {
+4 -1
View File
@@ -89,6 +89,9 @@ Espo.define('views/modals/edit', 'views/modal', function (Dep) {
});
this.scope = this.scope || this.options.scope;
this.entityType = this.options.entityType || this.scope;
this.id = this.options.id;
if (!this.id) {
@@ -113,7 +116,7 @@ Espo.define('views/modals/edit', 'views/modal', function (Dep) {
this.waitForView('edit');
this.getModelFactory().create(this.scope, function (model) {
this.getModelFactory().create(this.entityType, function (model) {
if (this.id) {
if (this.sourceModel) {
model = this.model = this.sourceModel.clone();
-1
View File
@@ -101,4 +101,3 @@ Espo.define('views/user/detail', 'views/detail', function (Dep) {
},
});
});
+7 -2
View File
@@ -26,7 +26,7 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
Espo.define('views/user/record/detail-quick', 'views/record/detail-small', function (Dep) {
Espo.define('views/user/record/detail-quick', ['views/record/detail-small', 'views/user/record/detail'], function (Dep, Detail) {
return Dep.extend({
@@ -38,9 +38,14 @@ Espo.define('views/user/record/detail-quick', 'views/record/detail-small', funct
setup: function () {
Dep.prototype.setup.call(this);
Detail.prototype.setupNonAdminFieldsAccess.call(this);
Detail.prototype.setupFieldAppearance.call(this);
},
controlFieldAppearance: function () {
Detail.prototype.controlFieldAppearance.call(this);
}
});
});
+10 -1
View File
@@ -50,7 +50,7 @@ Espo.define('views/user/record/detail', 'views/record/detail', function (Dep) {
});
}
if (this.model.id == this.getUser().id) {
if (this.model.id == this.getUser().id && !this.model.isApi()) {
this.dropdownItemList.push({
name: 'changePassword',
label: 'Change Password',
@@ -59,6 +59,10 @@ Espo.define('views/user/record/detail', 'views/record/detail', function (Dep) {
}
}
if (this.model.isPortal() || this.model.isApi()) {
this.hideActionItem('duplicate');
}
if (this.model.id == this.getUser().id) {
this.listenTo(this.model, 'after:save', function () {
this.getUser().set(this.model.toJSON());
@@ -124,6 +128,11 @@ Espo.define('views/user/record/detail', 'views/record/detail', function (Dep) {
if (this.model.get('type') === 'api') {
this.hideField('title');
this.hideField('emailAddress');
this.hideField('phoneNumber');
this.hideField('name');
this.hideField('gender');
} else {
this.showField('title');
}
+1 -1
View File
@@ -110,7 +110,7 @@ Espo.define('views/user/record/edit', ['views/record/edit', 'views/user/record/d
]
});
if (this.type == 'edit' && this.getUser().isAdmin()) {
if (this.type == 'edit' && this.getUser().isAdmin() && !this.model.isApi()) {
layout.push({
label: 'Password',
rows: [