Skip to content

Commit

Permalink
Merge pull request #15 from snake14/5.x-dev
Browse files Browse the repository at this point in the history
Update for Matomo 5 compatibility
  • Loading branch information
MichaelRoosz authored Jan 4, 2024
2 parents c2f7125 + a3a1e8d commit 165f4c1
Show file tree
Hide file tree
Showing 15 changed files with 772 additions and 102 deletions.
6 changes: 5 additions & 1 deletion Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
namespace Piwik\Plugins\GroupPermissions;

use Exception;
use Piwik\API\Request;
use Piwik\Common;
use Piwik\Piwik;
Expand Down Expand Up @@ -150,6 +149,11 @@ private function tabGroups(&$view)
else {
$view->groupUsers = array();
}

$allUsers = Request::processRequest('UsersManager.getUsersLogin', ['filter_limit' => '-1']);
// Create a named array using the user login as the key as well as the value
$allUsers = array_combine($allUsers, $allUsers);
$view->users = $allUsers;

$view->selectedIdGroup = $idGroup;
$view->selectedGroupName = isset($groups[$idGroup]) ? $groups[$idGroup] : '';
Expand Down
11 changes: 11 additions & 0 deletions GroupPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function registerEvents()
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'SitesManager.deleteSite.end' => 'deleteSite',
'UsersManager.deleteUser' => 'deleteUser',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
);
}

Expand All @@ -59,6 +60,16 @@ public function getStylesheetFiles(&$stylesheetFiles)
$stylesheetFiles[] = "plugins/GroupPermissions/stylesheets/choices.less";
}

public function getClientSideTranslationKeys(&$translations)
{
$translations[] = 'GroupPermissions_AddUserToGroup';
$translations[] = 'GroupPermissions_AddUserToGroupButton';
$translations[] = 'GroupPermissions_ManageGroupMembers';
$translations[] = 'GroupPermissions_RemoveFromGroup';
$translations[] = 'GroupPermissions_RemoveFromGroupConfirm';
$translations[] = 'GroupPermissions_SelectNewUser';
}

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

## Changelog
- 5.0.0
- Compatibility with Matomo 5

- 4.0.5
- Fix js crash

Expand Down
80 changes: 40 additions & 40 deletions javascripts/groupPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
*/

$(document).ready(function () {

function getSelectedIdSite() {
return $('#groupPermissionsSiteSelect').attr('siteid');
}

function sendUpdateGroupPermissionAccess(name, access, successCallback) {
var parameters = {};
parameters.name = name;
parameters.access = access;
parameters.idSites = getSelectedIdSite();

var ajaxHandler = new ajaxHelper();
ajaxHandler.addParams({
module: 'API',
Expand All @@ -29,15 +29,15 @@ $(document).ready(function () {
ajaxHandler.setErrorElement('#ajaxErrorGroupPermissions');
ajaxHandler.send(true);
}

function callSendUpdateGroupPermissionAccess(self, successCallback) {
sendUpdateGroupPermissionAccess(
$(self).parent().parent().find('#group').html(), //if changed change also the modal
$(self).parent().attr('id'),
successCallback
);
}

function bindUpdateGroupPermissions() {
var self = this;
// callback called when the ajax request Update the group permissions is successful
Expand All @@ -53,7 +53,7 @@ $(document).ready(function () {
.attr('src', "plugins/UsersManager/images/ok.png")
.attr('class', "accessGranted")
;

var UI = require('piwik/UI');
var notification = new UI.Notification();
notification.show(_pk_translate('General_Done'), {
Expand All @@ -65,26 +65,26 @@ $(document).ready(function () {
id: 'groupPermissionsAccessUpdated'
});
}

var idSite = getSelectedIdSite();
if (idSite == 'all') {
var target = this;

//ask confirmation
var group = $(this).parent().parent().find('#group').text();
$('#confirmGroupPermissions').find('#group').text(group);

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

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

function sendAddGroupMember(idGroup, login, successCallback) {
var parameters = {};
parameters.idGroup = idGroup;
Expand All @@ -102,7 +102,7 @@ $(document).ready(function () {
ajaxHandler.setErrorElement('#ajaxErrorManageGroupMember');
ajaxHandler.send(true);
}

function sendRemoveGroupMember(idGroup, login, successCallback) {
var parameters = {};
parameters.idGroup = idGroup;
Expand All @@ -120,7 +120,7 @@ $(document).ready(function () {
ajaxHandler.setErrorElement('#ajaxErrorManageGroupMember');
ajaxHandler.send(true);
}

function bindRemoveGroupMember() {
var idGroup = $('#groupPermissionsCurrentIdGroup').val();
var name = $('#groupPermissionsCurrentGroupName').val();
Expand All @@ -130,15 +130,15 @@ $(document).ready(function () {
function successCallback(response) {
line.remove();
}

$('#confirmRemoveUserFromGroup').find('#login').text(login);
$('#confirmRemoveUserFromGroup').find('#group').text(name);
$('#confirmRemoveUserFromGroup').find('#group').text(name);

piwikHelper.modalConfirm('#confirmRemoveUserFromGroup', {yes: function() {
sendRemoveGroupMember(idGroup, login, successCallback);
}});
}

function sendCreateGroup(groupName, successCallback) {
var parameters = {};
parameters.groupName = groupName;
Expand All @@ -155,15 +155,15 @@ $(document).ready(function () {
ajaxHandler.setErrorElement('#ajaxErrorCreateGroup');
ajaxHandler.send(true);
}

function bindCreateGroup() {
var groupName = $('#groupPermissionsGroupCreateGroup').val();

function successCallback(response) {
location.reload();
}
sendCreateGroup(groupName, successCallback);

sendCreateGroup(groupName, successCallback);
}


Expand All @@ -184,7 +184,7 @@ $(document).ready(function () {
ajaxHandler.setErrorElement('#ajaxErrorManageGroupRename');
ajaxHandler.send(true);
}

function bindRenameGroup() {
var idGroup = $('#groupPermissionsCurrentIdGroup').val();
var name = $('#groupPermissionsCurrentGroupName').val();
Expand All @@ -193,10 +193,10 @@ $(document).ready(function () {
function successCallback(response) {
location.reload();
}

$('#confirmRenameGroup').find('#confirmOldGroupName').text(name);
$('#confirmRenameGroup').find('#confirmNewGroupName').text(newName);
$('#confirmRenameGroup').find('#confirmNewGroupName').text(newName);

piwikHelper.modalConfirm('#confirmRenameGroup', {yes: function() {
sendRenameGroup(idGroup, newName, successCallback);
}});
Expand All @@ -218,24 +218,24 @@ $(document).ready(function () {
ajaxHandler.setErrorElement('#ajaxErrorManageGroupDelete');
ajaxHandler.send(true);
}

function bindDeleteGroup() {
var idGroup = $('#groupPermissionsCurrentIdGroup').val();
var name = $('#groupPermissionsCurrentGroupName').val();

function successCallback(response) {
location.reload();
}

$('#confirmDeleteGroup').find('#confirmDeleteGroupName').text(name);

piwikHelper.modalConfirm('#confirmDeleteGroup', {yes: function() {
sendDeleteGroup(idGroup, successCallback);
}});
}

function initializeUserSelect() {

var userSelect = new Choices('#groupPermissionsGroupAddUserSelect', {
allowHTML: false,
searchPlaceholderValue: 'Search for a user',
Expand Down Expand Up @@ -273,11 +273,11 @@ $(document).ready(function () {
tableBody.append('<tr><td class="login">'+login+'</td><td class="text-center">'
+'<button class="groupPermissionsRemoveUser btn btn-flat" data-login="'+login+'"><span class="icon-delete"></span></button>'
+'</td></tr>');

userSelect.setChoiceByValue('');
}
sendAddGroupMember(idGroup, login, successCallback);

sendAddGroupMember(idGroup, login, successCallback);
}

$('#groupPermissionsGroupAddUserButton').click(bindAddGroupMember);
Expand All @@ -293,19 +293,19 @@ $(document).ready(function () {
// when a group is selected, reload the page w/o showing the ajax loading element
$('#groupPermissionsGroupSelect').bind('change', function (e) {
piwik.broadcast.propagateNewPage('idGroup=' + encodeURIComponent($('#groupPermissionsGroupSelect').val()), false);
});
});

$('#groupPermissions .updateAccess').click(bindUpdateGroupPermissions);
$('#groupPermissionsGroup').on("click", ".groupPermissionsRemoveUser", bindRemoveGroupMember);

// $('#groupPermissionsGroup').on("click", ".groupPermissionsRemoveUser", bindRemoveGroupMember);

$('#groupPermissionsGroupRenameGroupButton').click(bindRenameGroup);

$('#groupPermissionsGroupDeleteGroupButton').click(bindDeleteGroup);

$('#groupPermissionsGroupCreateGroupButton').click(bindCreateGroup);

if ($('#groupPermissionsGroupAddUserSelect').length) {
initializeUserSelect();
// initializeUserSelect();
}
});
3 changes: 2 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"RemoveFromGroupConfirm": "Are you sure you want to remove user '%1$s' from group '%2$s'?",
"RenameGroup": "Rename this group",
"RenameGroupButton": "Rename Group",
"RenameGroupConfirm": "Are you sure you want to rename the group '%1$s' to '%2$s'?"
"RenameGroupConfirm": "Are you sure you want to rename the group '%1$s' to '%2$s'?",
"SelectNewUser": "Select a new user"
}
}
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"email": "[email protected]"
}],
"description": "Manage user permissions with groups.",
"version": "4.0.5",
"version": "5.0.0",
"theme": false,
"require": {
"matomo": ">=4.0.0-b1,<5.0.0-b1"
"matomo": ">=5.0.0-b1,<6.0.0-b1"
},
"keywords": [
"GroupPermissions",
Expand Down
11 changes: 6 additions & 5 deletions stylesheets/groupPermissions.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
font-weight: 700;
}

.groupPermissionsGroupAddUserWrapper .select-wrapper {
.groupPermissionsGroupAddUserWrapper {
.form-group, .row, .input-field {
margin: 0;
}

margin-bottom: 20px;

input.select-dropdown {
display: none;
.input-field {
padding-left: 0;
}
}
Loading

0 comments on commit 165f4c1

Please sign in to comment.