Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api function to get users with given access to ONLY the given site #56

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions plugins/UsersManager/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,30 @@ public function getUsersWithSiteAccess($idSite, $access)
return $this->getUsers($logins);
}

/**
* Returns users that have given access to given site,
* but no access to other sites.
*/
public function getUsersWithDistinctSiteAccess($idSite, $access)
{
Piwik::checkUserIsSuperUser();

$db = Zend_Registry::get('db');
$users = $db->fetchAll("SELECT login
FROM " . Piwik_Common::prefixTable("access")
. " as access1 WHERE idsite = ? AND access = ? AND (SELECT COUNT(login) FROM " . Piwik_Common::prefixTable("access")
. " as access2 WHERE access2.login = access1.login GROUP BY access2.login) = 1 ", array($idSite, $access));
$logins = array();
foreach ($users as $user) {
$logins[] = $user['login'];
}
if (empty($logins)) {
return array();
}
$logins = implode(',', $logins);
return $this->getUsers($logins);
}

/**
* For each website ID, returns the access level of the given $userLogin.
* If the user doesn't have any access to a website ('noaccess'),
Expand Down