fser
August 27, 2012, 12:10am
1
Hello,
I’ve recently been working with piwik’s API, and reach an issue with the UsersManager.getUsersAccessFromSite function.
I’m querying the API for siteId = 1, which has only one user. The result is :
$ curl 'http://www.myinternaltest.net/?module=API&method=UsersManager.getUsersAccessFromSite&format=JSON&token_auth=b9848776994b4111d8d010f7ed9b3ca5&idSite=1'
[["view"]]
Now if I add an other user to that site, I get:
$ curl 'http://www.myinternaltest.net/?module=API&method=UsersManager.getUsersAccessFromSite&format=JSON&token_auth=b9848776994b4111d8d010f7ed9b3ca5&idSite=1'
[{"admin":"view","miaou":"view"}]
Why is the output in case of only one member different that with two?
In the first case, I would have expected
[{"admin":"view"}]
If I change (in /plugins/UsersManager/API.php):
// return $return;
// into
return array($return);
and set only one user for that site, the output looks as expected:
$ curl 'http://www.myinternaltest.net/?module=API&method=UsersManager.getUsersAccessFromSite&format=JSON&token_auth=b9848776994b4111d8d010f7ed9b3ca5&idSite=1'
[{"miaou":"view"}]
But turns on some errors in the classical piwik.
Can someone explain me if I’m wrong? I just don’t get this behavior!
Thanks in advance.
matthieu
(Matthieu Aubry)
August 27, 2012, 5:35am
2
Thanks for the report that’s indeed a bug in piwik, that when 1 item is returned we simplify the output. In this case though, it shouldn’t be simplified. Can you please create a ticket at dev.piwik.org with the expected VS output and the proposed patch to fix hte issue, and link to this post, we will fix it thanks for your report!
fser
August 27, 2012, 1:30pm
3
The ticket is open, I hope I set it at the right place.
opened 03:29PM - 27 Aug 12 UTC
closed 03:53AM - 18 Dec 12 UTC
Bug
Major
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"}]
```
Keywords: usersmanager accessfromsite
Feel free ton contact me for further information.
fser
January 3, 2013, 12:24am
5
Hey, incredible!
I’ll have a look on the diff.
Thanks!