#3349 closed Bug (fixed)

getUsersAccessFromSite has a different behaviour if only one member

Reported by: fser Owned by: capedfuzz
Priority: major Milestone: 1.10 - Piwik 1.10
Component: Core Keywords: usersmanager accessfromsite
Cc: Sensitive: no

Description

As explained on the forum (http://forum.piwik.org/read.php?2,92955), there is a weird behaviour when using getUsersAccessFromSite when there is only on user who has rights on a website.

Expected output, with only one user (named admin):

[{"admin":"view"}]

Actual output:

$ curl 'http://www.myinternaltest.net/?module=API&method=UsersManager.getUsersAccessFromSite&format=JSON&token_auth=b9848776994b4111d8d010f7ed9b3ca5&idSite=1'
[["view"]]

Two users:

$ curl 'http://www.myinternaltest.net/?module=API&method=UsersManager.getUsersAccessFromSite&format=JSON&token_auth=b9848776994b4111d8d010f7ed9b3ca5&idSite=1'
[{"admin":"view","miaou":"view"}]

A test I made was to wrap $return with an array definition, which looks like working for the API, but breaks other features in the core piwik obviously (for instance on the user listing page).
Nevertheless, the patch is

--- API.php.old 2012-08-27 13:25:22.000000000 +0000
+++ API.php     2012-08-27 13:26:14.000000000 +0000
@@ -172,7 +172,7 @@
                {
                        $return[$user['login']][] = $user['idsite'];
                }
-               return $return;
+               return array($return);
 
        }

which produces the output:

$ curl 'http://www.myinternaltest.net/?module=API&method=UsersManager.getUsersAccessFromSite&format=JSON&token_auth=b9848776994b4111d8d010f7ed9b3ca5&idSite=1'
[{"miaou":"view"}]

Change History (4)

comment:1 Changed 18 months ago by matt (mattab)

A related issue was described in: http://forum.piwik.org/read.php?2,89606
"Fatal error: Call to a member function getFirstRow() on widgets "

I think these are both the same root cause, the wrong re-write of the data when there's only one element.


Removing and adding widget solves problem. But only for a short time, until user selects one column(metrics) for graph. For example (avg_time_on_site).

1) Then calling API VisitsSummary.get results in table with single column. avg_time_on_site
2) After that API\ResponseBuilder collapses it according to

$columns = $dataTable->getFirstRow()->getColumns();
				if(count($columns) == 1)
				{
					$values = array_values($columns);
					return $values[0];
				}


3) The result is non-object and have no getFirstRow() function

I solved it adding some extra columns to visits summary to be present all the time:

file: plugins/VisitsSummary/API.php line 62
$columns = array_merge($columns, $tempColumns, array('nb_visits', 'nb_uniq_visitors'));


But it may cause some bugs I believe. So if this bug explanation makes sense - please tell how to fix that correct.


comment:2 Changed 18 months ago by matt (mattab)

  • Milestone changed from 1.9.x - Piwik 1.9.x to 1.9.1 - Piwik 1.9.1

comment:3 Changed 18 months ago by matt (mattab)

  • Owner set to capedfuzz
  • Priority changed from normal to major

This is a bug that will be great to have fixed as it could strike in the most unexpected moments. @capedfuzz let me know what you think about this.

comment:4 Changed 16 months ago by capedfuzz (diosmosis)

  • Resolution set to fixed
  • Status changed from new to closed

(In [7648]) Refs #1253, fixes #3349, fix bugs and regressions in annotations and tweaked the UI a bit.

Note: See TracTickets for help on using tickets.