portal id

This commit is contained in:
yuri
2016-06-16 16:59:10 +03:00
parent ec7d49cdbc
commit 4bf938107d
11 changed files with 128 additions and 9 deletions

View File

@@ -315,7 +315,7 @@ class Application
return $_GET['portalId'];
}
if (!empty($_COOKIE['auth-token'])) {
$token = $this->getContainer()->get('entityManager')->getRepository('AuthToken')->where(array('token'=>$_COOKIE['auth-token']))->findOne();
$token = $this->getContainer()->get('entityManager')->getRepository('AuthToken')->where(array('token' => $_COOKIE['auth-token']))->findOne();
if ($token && $token->get('portalId')) {
return $token->get('portalId');

View File

@@ -49,6 +49,12 @@ class Application extends \Espo\Core\Application
$portal = $this->getContainer()->get('entityManager')->getEntity('Portal', $portalId);
if (!$portal) {
$portal = $this->getContainer()->get('entityManager')->getRepository('Portal')->where(array(
'customId' => $portalId
))->findOne();
}
if (!$portal) {
throw new NotFound();
}

View File

@@ -44,7 +44,10 @@ class Portal extends \Espo\Core\EntryPoints\Base
} else if (!empty($data['id'])) {
$id = $data['id'];
} else {
$id = $this->getConfig()->get('defaultPortalId');
$id = explode('/', $_SERVER['REQUEST_URI'])[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1];
if (!$id) {
$id = $this->getConfig()->get('defaultPortalId');
}
if (!$id) {
throw new NotFound();
}

View File

@@ -17,7 +17,8 @@
"timeZone": "Time Zone",
"weekStart": "First Day of Week",
"defaultCurrency": "Default Currency",
"customUrl": "Custom URL"
"customUrl": "Custom URL",
"customId": "Custom ID"
},
"links": {
"users": "Users",

View File

@@ -4,7 +4,7 @@
"rows": [
[{"name": "name"}, {"name": "isActive"}],
[{"name": "url"}, {"name": "isDefault"}],
[{"name": "portalRoles"}, {"name": "language"}],
[{"name": "portalRoles"}, {"name": "customId"}],
[false, {"name": "customUrl"}]
]
},
@@ -13,7 +13,7 @@
"rows": [
[{"name": "dateFormat"}, {"name": "timeZone"}],
[{"name": "timeFormat"}, {"name": "weekStart"}],
[{"name": "defaultCurrency"}, false]
[{"name": "defaultCurrency"}, {"name": "language"}]
]
},
{

View File

@@ -13,6 +13,13 @@
"notStorable": true,
"readOnly": true
},
"customId": {
"type": "varchar",
"maxLength": 36,
"view": "views/portal/fields/custom-id",
"trim": true,
"index": true
},
"isActive": {
"type": "bool",
"default": true

View File

@@ -47,6 +47,12 @@ class Portal extends Record
$this->loadUrlField($entity);
}
protected function afterUpdate(Entity $entity, array $data = array())
{
parent::afterUpdate($entity, $data);
$this->loadUrlField($entity);
}
protected function loadUrlField(Entity $entity)
{
if ($entity->get('customUrl')) {
@@ -55,12 +61,16 @@ class Portal extends Record
}
$siteUrl = $this->getConfig()->get('siteUrl');
$siteUrl = rtrim($siteUrl , '/') . '/';
$url = $siteUrl . 'portal';
$url = $siteUrl . 'portal/';
if ($entity->id === $this->getConfig()->get('defaultPortalId')) {
$entity->set('isDefault', true);
$entity->setFetched('isDefault', true);
} else {
$url .= '?id=' . $entity->id;
if ($entity->get('customId')) {
$url .= $entity->get('customId') . '/';
} else {
$url .= $entity->id . '/';
}
$entity->setFetched('isDefault', false);
}
$entity->set('url', $url);

View File

@@ -0,0 +1,50 @@
/************************************************************************
* 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/.
*
* 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/portal/fields/custom-id', 'views/fields/varchar', function (Dep) {
return Dep.extend({
setup: function () {
Dep.prototype.setup.call(this);
this.listenTo(this, 'change', function () {
var value = this.model.get('customId');
if (!value || value === '') return;
value = value.replace(/ /i, '-').toLowerCase();
value = encodeURIComponent(value);
this.model.set('customId', value);
}, this);
},
});
});

12
portal/.htaccess Executable file
View File

@@ -0,0 +1,12 @@
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
RewriteRule .* - [E=HTTP_ESPO_CGI_AUTH:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

View File

@@ -34,11 +34,26 @@ if (!$app->isInstalled()) {
exit;
}
if (!empty($_GET['entryPoint'])) {
$a = explode('?', $_SERVER['REQUEST_URI']);
if (substr($a[0], -1) !== '/') {
$url = $a[0] . '/';
if (count($a) > 1) {
$url .= '?' . $a[1];
}
header("Location: " . $url);
exit();
}
$portalId = explode('/', $_SERVER['REQUEST_URI'])[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1];
if ($portalId) {
$app->setBasePath('../../');
} else {
$app->setBasePath('../');
}
if (!empty($_GET['entryPoint'])) {
$app->runEntryPoint($_GET['entryPoint']);
exit;
}
$app->setBasePath('../');
$app->runEntryPoint('portal');

15
portal/web.config Executable file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rule 1G" stopProcessing="true">
<match url="^" />
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>