auth tokens in admin

This commit is contained in:
Yuri Kuznetsov
2014-06-26 16:32:18 +03:00
parent 3d4d8aa7d3
commit aa761d5ef7
14 changed files with 285 additions and 7 deletions

View File

@@ -0,0 +1,66 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014 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/.
************************************************************************/
namespace Espo\Controllers;
use \Espo\Core\Exceptions\Forbidden;
class AuthToken extends \Espo\Core\Controllers\Record
{
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
}
public function actionUpdate($params, $data)
{
throw new Forbidden();
}
public function actionCreate($params, $data)
{
throw new Forbidden();
}
public function actionListLinked($params, $data)
{
throw new Forbidden();
}
public function actionMassUpdate($params, $data)
{
throw new Forbidden();
}
public function actionCreateLink($params, $data)
{
throw new Forbidden();
}
public function actionRemoveLink($params, $data)
{
throw new Forbidden();
}
}

View File

@@ -27,7 +27,8 @@
"Import": "Import",
"Layout Manager": "Layout Manager",
"Field Manager": "Field Manager",
"User Interface": "User Interface"
"User Interface": "User Interface",
"Auth Tokens": "Auth Tokens"
},
"layouts": {
"list": "List",
@@ -109,7 +110,8 @@
"import": "Import data from CSV file.",
"layoutManager": "Customize layouts (list, detail, edit, search, mass update).",
"fieldManager": "Create new fields or customize existing ones.",
"userInterface": "Configure UI."
"userInterface": "Configure UI.",
"authTokens": "Active auth sessions. IP and date of last access."
},
"options": {
"previewSize": {

View File

@@ -0,0 +1,9 @@
{
"fields": {
"user": "User",
"ipAddress": "IP Address",
"lastAccess": "Last Access Date",
"createdAt": "Login Date"
}
}

View File

@@ -0,0 +1,6 @@
[
{"name":"user"},
{"name":"ipAddress"},
{"name":"lastAccess"},
{"name":"createdAt"}
]

View File

@@ -46,6 +46,11 @@
"url":"#Role",
"label":"Roles",
"description":"roles"
},
{
"url":"#Admin/authTokens",
"label":"Auth Tokens",
"description":"authTokens"
}
]
},

View File

@@ -0,0 +1,5 @@
{
"recordViews":{
"list":"Admin.AuthToken.Record.List"
}
}

View File

@@ -13,6 +13,9 @@
"type": "varchar",
"maxLength": "36"
},
"user": {
"type": "link"
},
"ipAddress": {
"type": "varchar",
"maxLength": "36"
@@ -28,5 +31,15 @@
"type": "datetime",
"readOnly": true
}
},
"links": {
"user": {
"type": "belongsTo",
"entity": "User"
}
},
"collection": {
"sortBy": "lastAccess",
"asc": false
}
}

View File

@@ -0,0 +1,33 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014 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/.
************************************************************************/
namespace Espo\Services;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\Error;
use \Espo\Core\Exceptions\NotFound;
class AuthToken extends Record
{
protected $internalFields = array('hash', 'token');
}

View File

@@ -90,6 +90,21 @@ Espo.define('Controllers.Admin', 'Controller', function (Dep) {
model.fetch();
},
authTokens: function () {
this.collectionFactory.create('AuthToken', function (collection) {
var searchManager = new Espo.SearchManager(collection, 'list', this.getStorage(), this.getDateTime());
searchManager.loadStored();
collection.where = searchManager.getWhere();
collection.maxSize = this.getConfig().get('recordsPerPage') || collection.maxSize;
this.main('Admin.AuthToken.List', {
scope: 'AuthToken',
collection: collection,
searchManager: searchManager,
});
}, this);
},
userInterface: function () {
var model = this.getSettingsModel();

View File

@@ -0,0 +1,43 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014 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.Admin.AuthToken.List', 'Views.List', function (Dep) {
return Dep.extend({
searchPanel: false,
setup: function () {
Dep.prototype.setup.call(this);
this.menu.buttons = [];
},
getHeader: function () {
return '<a href="#Admin">' + this.translate('Administration') + "</a> » " + this.getLanguage().translate('Auth Tokens', 'labels', 'Administration');
},
updatePageTitle: function () {
this.setPageTitle(this.getLanguage().translate(this.collection.name, 'scopeNamesPlural'));
},
});
});

View File

@@ -0,0 +1,36 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014 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.Admin.AuthToken.Record.ListButtons.Remove', 'View', function (Dep) {
return Dep.extend({
_template: '<a href="javascript:" data-action="quickRemove" data-id="{{id}}">{{translate "Remove"}}</a>',
data: function () {
return {
id: this.model.id
};
}
});
});

View File

@@ -0,0 +1,44 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014 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.Admin.AuthToken.Record.List', 'Views.Record.List', function (Dep) {
return Dep.extend({
rowButtons: 'Admin.AuthToken.Record.ListButtons.Remove',
setup: function () {
Dep.prototype.setup.call(this);
var actions = [];
this.actions.forEach(function (item) {
if (item.name == 'delete') {
actions.push(item);
}
}, this);
this.actions = actions;
},
});
});

View File

@@ -60,7 +60,7 @@ Espo.define('Views.List', 'Views.Main', function (Dep) {
afterRender: function () {
this.notify('Loading...');
var listViewName = this.getMetadata().get('clientDefs.' + this.name + '.recordViews.list') || 'Record.List';
var listViewName = this.getMetadata().get('clientDefs.' + this.scope + '.recordViews.list') || 'Record.List';
this.listenToOnce(this.collection, 'sync', function () {
this.createView('list', listViewName, {

View File

@@ -141,7 +141,7 @@ Espo.define('Views.Record.List', 'View', function (Dep) {
actions: [
{
name: 'delete',
label: 'Delete',
label: 'Remove',
action: function (e) {
if (!this.getAcl().check(this.scope, 'delete')) {
this.notify('Access denied', 'error');
@@ -155,7 +155,7 @@ Espo.define('Views.Record.List', 'View', function (Dep) {
if (confirm(this.translate('Are you sure?'))) {
// TODO mass delete
this.notify('Deleting...');
this.notify('Removing...');
for (var i in this.checkedList) {
var id = this.checkedList[i];
var model = this.collection.get(id);
@@ -320,7 +320,8 @@ Espo.define('Views.Record.List', 'View', function (Dep) {
}
this.scope = this.collection.name || null;
this.events = _.clone(this.events);
this.events = Espo.Utils.clone(this.events);
this.actions = Espo.Utils.clone(this.actions);
if (this.selectable) {
this.events['click .list a.link'] = function (e) {
@@ -343,7 +344,7 @@ Espo.define('Views.Record.List', 'View', function (Dep) {
this.actions = [];
}
if (this.checkboxes) {
if (this.checkboxes) {
this.actions.forEach(function (item) {
this.events['click .actions a[data-action="' + item.name + '"]'] = function (e) {
item.action.call(this, e);