Commit 3c370b0d authored by Henning Leutz's avatar Henning Leutz 🥋

fix: #300

parent c7967419
This diff is collapsed.
......@@ -209,7 +209,15 @@ define('controls/permissions/Sitemap', [
// sort list
list.sort(function (a, b) {
return a.translation > b.translation;
if (a.translation > b.translation) {
return 1;
}
if (a.translation < b.translation) {
return -1;
}
return 0;
});
for (i = 0, len = list.length; i < len; i++) {
......
This diff is collapsed.
......@@ -279,6 +279,27 @@ class Package extends QUI\QDOM
return '';
}
/**
* Return the permission name for a package permission
* eq:
* - canUse
*
* @param string $permissionName
* @return mixed
*/
public function getPermissionName($permissionName = 'canUse')
{
$nameShortCut = preg_replace("/[^A-Za-z0-9 ]/", '', $this->getName());
switch ($permissionName) {
case 'header':
return 'permission.quiqqer.packages.' . $nameShortCut . '._header';
default:
return 'quiqqer.packages.' . $nameShortCut . '.canUse';
}
}
/**
* Return all preview images
* Not the main image
......@@ -315,7 +336,7 @@ class Package extends QUI\QDOM
}
/**
* Return the package lock date
* Return the package lock data
*
* @return array
*/
......@@ -393,6 +414,30 @@ class Package extends QUI\QDOM
return $file;
}
/**
* Checks the package permisson
*
* @param string $permission - could be canUse
* @param QUI\Interfaces\Users\User|null $User
*
* @return bool
*/
public function hasPermission($permission = 'canUse', $User = null)
{
if ($this->getName() === 'quiqqer/products') {
QUI\System\Log::writeRecursive($this->getPermissionName($permission));
}
switch ($permission) {
default:
case 'canUse':
return QUI\Permissions\Permission::hasPermission(
$this->getPermissionName($permission),
$User
);
}
}
/**
* Execute the package setup
*/
......@@ -404,24 +449,67 @@ class Package extends QUI\QDOM
return;
}
Update::importDatabase($dir . 'database.xml');
Update::importTemplateEngines($dir . 'engines.xml');
Update::importEditors($dir . 'wysiwyg.xml');
// permissions
QUI::getPermissionManager()->addPermission(array(
'name' => $this->getPermissionName(),
'title' => 'quiqqer/quiqqer permission.package.canUse',
'desc' => '',
'area' => '',
'type' => 'bool',
'defaultvalue' => 1
));
$languages = QUI\Translator::getAvailableLanguages();
$data = array(
'datatype' => 'php,js',
'package' => $this->getName()
);
Update::importPermissions($dir . 'permissions.xml', $this->getName());
Update::importMenu($dir . 'menu.xml');
foreach ($languages as $lang) {
$data[$lang] = QUI::getLocale()->getByLang($lang, $this->getName(), 'package.title');
}
try {
QUI\Translator::addUserVar(
'quiqqer/quiqqer',
$this->getPermissionName('header'),
$data
);
} catch (QUI\Exception $Exception) {
try {
QUI\Translator::edit(
'quiqqer/quiqqer',
$this->getPermissionName('header'),
$this->getName(),
$data
);
} catch (QUI\Exception $Exception) {
QUI::getMessagesHandler()->addAttention(
$Exception->getMessage()
);
}
}
// xml
Update::importDatabase($dir . 'database . xml');
Update::importTemplateEngines($dir . 'engines . xml');
Update::importEditors($dir . 'wysiwyg . xml');
Update::importPermissions($dir . 'permissions . xml', $this->getName());
Update::importMenu($dir . 'menu . xml');
// events
QUI\Events\Manager::clear($this->getName());
Update::importEvents($dir . 'events.xml', $this->getName());
Update::importSiteEvents($dir . 'site.xml');
Update::importEvents($dir . 'events . xml', $this->getName());
Update::importSiteEvents($dir . 'site . xml');
// locale
QUI\Translator::importFromPackage($this, true, true);
try {
$groups = XML::getLocaleGroupsFromDom(
XML::getDomFromXml($dir . 'locale.xml')
XML::getDomFromXml($dir . 'locale . xml')
);
$groups = array_map(function ($data) {
......@@ -435,20 +523,21 @@ class Package extends QUI\QDOM
}
QUI\Translator::publish($this->getName());
QUI\Translator::publish('quiqqer/quiqqer');
foreach ($groups as $group) {
QUI\Translator::publish($group);
}
// settings
if (!file_exists($dir . 'settings.xml')) {
if (!file_exists($dir . 'settings . xml')) {
QUI::getEvents()->fireEvent('packageSetup', array($this));
QUI\Cache\Manager::clearAll();
return;
}
// $defaults = XML::getConfigParamsFromXml( $dir .'settings.xml' );
$Config = XML::getConfigFromXml($dir . 'settings.xml');
// $defaults = XML::getConfigParamsFromXml( $dir .'settings . xml' );
$Config = XML::getConfigFromXml($dir . 'settings . xml');
if ($Config) {
$Config->save();
......@@ -497,6 +586,9 @@ class Package extends QUI\QDOM
*/
public function destroy()
{
QUI::getPermissionManager()->removePermission($this->getPermissionName());
QUI::getPermissionManager()->removePermission($this->getPermissionName('header'));
QUI::getEvents()->fireEvent('packageDestroy', array($this->getName()));
}
......
......@@ -280,7 +280,7 @@ class Manager
* area =>
* title => translation.var.var
* type =>
* default =>
* defaultvalue =>
* src =>
* )
*
......@@ -724,6 +724,7 @@ class Manager
unset($this->dataCache[$this->getDataCacheId($Obj)]);
QUI\Cache\Manager::clear('qui/admin/menu/');
QUI::getEvents()->fireEvent('permissionsSet', array($Obj, $permissions));
}
......
......@@ -489,6 +489,13 @@ class Update
continue;
}
$Package = QUI::getPackage($package);
if (!$Package->hasPermission()) {
continue;
}
// @todo in Paket Klasse integrieren
$package_dir = OPT_DIR . '/' . $package;
$list = QUIFile::readDir($package_dir);
......
......@@ -179,48 +179,25 @@ class Menu
}
}
// read the menu.xmls
$dir = VAR_DIR . 'cache/menu/';
// read the menu.xml's
$packages = QUI::getPackageManager()->getInstalled();
if (!is_dir($dir)) {
QUI\Update::importAllMenuXMLs();
}
$files = QUI\Utils\System\File::readDir($dir);
foreach ($files as $file) {
XML::addXMLFileToMenu($Menu, $dir . $file);
}
foreach ($packages as $package) {
$Package = QUI::getPackage($package['name']);
$menuXml = $Package->getXMLFile('menu.xml');
$menu = $Menu->toArray();
// @todo rechte für settings und extras und quiqqer
foreach ($menu as $key => $entry) {
if ($entry['name'] == 'quiqqer') {
if (!Permission::hasPermission('quiqqer.menu.quiqqer')) {
unset($menu[$key]['items']);
}
}
if ($entry['name'] == 'settings') {
if (!Permission::hasPermission('quiqqer.menu.settings')) {
unset($menu[$key]);
}
if (!$menuXml) {
continue;
}
if ($entry['name'] == 'extras') {
if (!Permission::hasPermission('quiqqer.menu.extras')) {
unset($menu[$key]);
}
if (!$Package->hasPermission()) {
continue;
}
if ($entry['name'] == 'apps') {
if (!Permission::hasPermission('quiqqer.menu.apps')) {
unset($menu[$key]);
}
}
XML::addXMLFileToMenu($Menu, $menuXml);
}
$menu = $Menu->toArray();
$menu = array_values($menu);
// sort
......@@ -232,17 +209,7 @@ class Menu
continue;
}
usort($menu[$key]['items'], function ($a, $b) {
if ($a['name'] == 'quiqqer') {
return -1;
}
if ($b['name'] == 'quiqqer') {
return 1;
}
return strcmp($a["text"], $b["text"]);
});
$menu[$key]['items'] = $this->sortItems($menu[$key]['items']);
}
QUI\Cache\Manager::set($this->getCacheName(), $menu);
......@@ -317,4 +284,43 @@ class Menu
return $cache;
}
/**
* Sort the menu items
*
* @param $items
* @return array
*/
protected function sortItems($items)
{
usort($items, array($this, 'sortByTitle'));
foreach ($items as $key => $item) {
if (isset($item['items']) && !empty($item['items'])) {
$items[$key]['items'] = $this->sortItems($item['items']);
}
}
return $items;
}
/**
* usort helper function / method
*
* @param array $a
* @param array $b
* @return int
*/
protected function sortByTitle($a, $b)
{
if ($a['name'] == 'quiqqer') {
return -1;
}
if ($b['name'] == 'quiqqer') {
return 1;
}
return strcmp($a["text"], $b["text"]);
}
}
......@@ -56,6 +56,14 @@
<de><![CDATA[Eine Seite]]></de>
<en><![CDATA[A site]]></en>
</locale>
<locale name="permission.quiqqer.packages._header">
<de><![CDATA[Pakete]]></de>
<en><![CDATA[Packages]]></en>
</locale>
<locale name="permission.package.canUse">
<de><![CDATA[Darf benutzen]]></de>
<en><![CDATA[Is allowed to use it]]></en>
</locale>
<locale name="permission.quiqqer.editors._header">
<de><![CDATA[Editor / WYSIWYG]]></de>
<en><![CDATA[Editor / WYSIWYG]]></en>
......
......@@ -47,23 +47,6 @@
<!-- Darf Benutzer anlegen -->
<permission name="quiqqer.admin.users.create" type="bool"/>
<!-- Menurechte -->
<permission name="quiqqer.menu.quiqqer" type="bool">
<defaultvalue>1</defaultvalue>
</permission>
<permission name="quiqqer.menu.apps" type="bool">
<defaultvalue>1</defaultvalue>
</permission>
<permission name="quiqqer.menu.extras" type="bool">
<defaultvalue>1</defaultvalue>
</permission>
<permission name="quiqqer.menu.settings" type="bool">
<defaultvalue>1</defaultvalue>
</permission>
<!-- Project User / group permissions -->
<!-- Darf Projekte anlegen -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment