Skip to content

Commit

Permalink
*Added support for 'write' access
Browse files Browse the repository at this point in the history
*Compatibility with Matomo 3.6.0
  • Loading branch information
Michael Heerklotz committed Sep 7, 2018
1 parent 3216d7c commit 6d37c9f
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 43 deletions.
18 changes: 11 additions & 7 deletions API.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Exception;
use Piwik\Access;
use Piwik\Access\RolesProvider;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Site;
Expand All @@ -23,11 +24,17 @@ class API extends \Piwik\Plugin\API
*/
private $model;

/**
* @var Access\RolesProvider
*/
private $roleProvider;

private static $instance = null;

public function __construct(Model $model)
{
$this->model = $model;
$this->roleProvider = $roleProvider ?: StaticContainer::get(RolesProvider::class);
}

public static function getInstance()
Expand Down Expand Up @@ -168,13 +175,10 @@ public function setGroupAccess($name, $access, $idSites)

private function checkAccessType($access)
{
$accessList = Access::getListAccess();

// do not allow to set the superUser access
unset($accessList[array_search("superuser", $accessList)]);

if (!in_array($access, $accessList)) {
throw new Exception(Piwik::translate("UsersManager_ExceptionAccessValues", implode(", ", $accessList)));
$roles = $this->roleProvider->getAllRoleIds();

if (!in_array($access, $roles, true)) {
throw new Exception(Piwik::translate("UsersManager_ExceptionAccessValues", implode(", ", $roles), $access));
}
}

Expand Down
7 changes: 5 additions & 2 deletions Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ public function getRawSitesWithSomeViewAccess($login)
public function getHigherPermission($permission1, $permission2) {

if ($permission1 === 'admin' || $permission2 === 'admin') {
return 'admin';
return 'admin';
}
else if ($permission1 === 'write' || $permission2 === 'write') {
return 'write';
}
else if ($permission1 === 'view' || $permission2 === 'view') {
return 'view';
return 'view';
}
else {
return '';
Expand Down
10 changes: 1 addition & 9 deletions Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function index()
$view = new View('@GroupPermissions/index');

$view->activeTab = Common::getRequestVar('show', 'access');
$validTabs = array('access', 'groups', 'overview');
$validTabs = array('access', 'groups');
if (!in_array($view->activeTab, $validTabs)) {
$view->activeTab = 'access';
}
Expand All @@ -62,9 +62,6 @@ public function index()
if ($view->activeTab === 'groups') {
$this->tabGroups($view);
}
else if ($view->activeTab === 'overview') {
$this->tabOverview($view);
}
}

$this->setBasicVariablesView($view);
Expand Down Expand Up @@ -157,9 +154,4 @@ private function tabGroups(&$view)
$view->selectedIdGroup = $idGroup;
$view->selectedGroupName = isset($groups[$idGroup]) ? $groups[$idGroup] : '';
}

private function tabOverview(&$view)
{

}
}
11 changes: 1 addition & 10 deletions GroupPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function registerEvents()
{
return array(
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'SitesManager.deleteSite.end' => 'deleteSite',
'UsersManager.deleteUser' => 'deleteUser',
);
Expand All @@ -46,15 +45,7 @@ public function getJsFiles(&$jsFiles)
{
$jsFiles[] = "plugins/GroupPermissions/javascripts/groupPermissions.js";
}

/**
* Get CSS files
*/
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "plugins/GroupPermissions/stylesheets/groupPermissions.less";
}


/**
* Delete group preferences associated with a particular site
*/
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Copy it into the plugins folder.
GPL v3 or later

## Changelog

3.6.0: Added support for 'write' access
Compatibility with Matomo 3.6.0

3.0.2: First stable release

## Support
Expand Down
9 changes: 4 additions & 5 deletions javascripts/groupPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

$(document).ready(function () {

// TODO: move back above read() but move into own scope
function getIdSites() {
return $('#groupPermissionsSiteSelect').attr('siteid');
}
Expand All @@ -31,7 +30,7 @@ $(document).ready(function () {
ajaxHandler.send(true);
}

function launchAjaxRequest(self, successCallback) {
function callSendUpdateGroupPermissionAccess(self, successCallback) {
sendUpdateGroupPermissionAccess(
$(self).parent().parent().find('#group').html(), //if changed change also the modal
$(self).parent().attr('id'),
Expand Down Expand Up @@ -73,16 +72,16 @@ $(document).ready(function () {

//ask confirmation
var group = $(this).parent().parent().find('#group').text();
$('#confirmGroupPermissions').find('#group').text(group); // if changed here change also the launchAjaxRequest
$('#confirmGroupPermissions').find('#group').text(group);

function onValidate() {
launchAjaxRequest(target, successCallback);
callSendUpdateGroupPermissionAccess(target, successCallback);
}

piwikHelper.modalConfirm('#confirmGroupPermissions', {yes: onValidate})
}
else {
launchAjaxRequest(this, successCallback);
callSendUpdateGroupPermissionAccess(this, successCallback);
}
}

Expand Down
1 change: 0 additions & 1 deletion lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"ExceptionGroupDoesExist": "Gruppe existiert bereits",
"ManageAccess": "Rechte verwalten",
"ManageGroups": "Gruppen verwalten",
"Overview": "Uebersicht",
"CreateNewGroup": "Neue Gruppe erstellen",
"CreateNewGroupButton": "Gruppe erstellen",
"ManageGroup": "Gruppe verwalten",
Expand Down
1 change: 0 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"ExceptionGroupDoesExist": "Group already exists",
"ManageAccess": "Manage Access",
"ManageGroups": "Manage Groups",
"Overview": "Overview",
"CreateNewGroup": "Create a new group",
"CreateNewGroupButton": "Create Group",
"ManageGroup": "Manage group",
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
}
],
"description": "Manage user permissions with groups.",
"version": "3.0.2",
"version": "3.6.0",
"theme": false,
"require": {
"piwik": ">=3.1.0-rc1,<4.0.0-b1"
"piwik": ">=3.6.0,<4.0.0-b1"
},
"keywords": [
"GroupPermissions",
Expand Down
Empty file removed stylesheets/groupPermissions.less
Empty file.
7 changes: 7 additions & 0 deletions templates/_access.twig
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<th class='first'>{{ 'GroupPermissions_Group'|translate }}</th>
<th>{{ 'UsersManager_PrivNone'|translate }}</th>
<th>{{ 'UsersManager_PrivView'|translate }}</th>
<th>{{ 'UsersManager_PrivWrite'|translate }}</th>
<th>{{ 'UsersManager_PrivAdmin'|translate }}</th>
</tr>
</thead>
Expand All @@ -58,6 +59,12 @@
{% else %}
{{ accesInvalid }}
{% endif %}&nbsp;</td>
<td id='write'>
{% if access == 'write' and idSiteSelected != 'all' %}
{{ accesValid }}
{% else %}
{{ accesInvalid }}
{% endif %}&nbsp;</td>
<td id='admin'>
{% if access == 'admin' and idSiteSelected != 'all' %}
{{ accesValid }}
Expand Down
Empty file removed templates/_overview.twig
Empty file.
5 changes: 0 additions & 5 deletions templates/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@
<li {% if activeTab=='groups' %}class="active"{% endif %}>
<a href="{{ linkTo({'show': 'groups'}) }}">{{ 'GroupPermissions_ManageGroups'|translate }}</a>
</li>
<!-- <li {% if activeTab=='overview' %}class="active"{% endif %}>
<a href="{{ linkTo({'show': 'overview'}) }}">{{ 'GroupPermissions_Overview'|translate }}</a>
</li> -->
</ul>

{% if activeTab=='access' %}
{% include '@GroupPermissions/_access.twig' %}
{% elseif activeTab=='groups' %}
{% include '@GroupPermissions/_groups.twig' %}
{% elseif activeTab=='overview' %}
{% include '@GroupPermissions/_overview.twig' %}
{% endif %}
{% else %}
{% include '@GroupPermissions/_access.twig' %}
Expand Down

0 comments on commit 6d37c9f

Please sign in to comment.