Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add $admin parameter to the countUsersForRepository function.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jul 22, 2015
1 parent 6bb89de commit 75ef4ea
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
5 changes: 3 additions & 2 deletions core/src/core/classes/class.AuthService.php
Expand Up @@ -958,11 +958,12 @@ public static function getRolesForRepository($repositoryId, $rolePrefix = '', $c
* Count the number of users who have either read or write access to a repository
* @param $repositoryId
* @param bool $details
* @param bool $admin True if called in an admin context
* @return Array|int
*/
public static function countUsersForRepository($repositoryId, $details = false)
public static function countUsersForRepository($repositoryId, $details = false, $admin = false)
{
return ConfService::getConfStorageImpl()->countUsersForRepository($repositoryId, $details);
return ConfService::getConfStorageImpl()->countUsersForRepository($repositoryId, $details, $admin);
}

/**
Expand Down
Expand Up @@ -1409,7 +1409,13 @@ public function switchAction($action, $httpVars, $fileVars)
}
$manifest = $plug->getManifestRawContent("server_settings/param");
$manifest = AJXP_XMLWriter::replaceAjxpXmlKeywords($manifest);
print("<ajxpdriver name=\"".$repository->accessType."\" label=\"".AJXP_Utils::xmlEntities($plug->getManifestLabel())."\" description=\"".AJXP_Utils::xmlEntities($plug->getManifestDescription())."\">$manifest</ajxpdriver>");
$clientSettings = $plug->getManifestRawContent("client_settings", "xml");
$iconClass = "";$descriptionTemplate = "";
if($clientSettings->length){
$iconClass = $clientSettings->item(0)->getAttribute("iconClass");
$descriptionTemplate = $clientSettings->item(0)->getAttribute("description_template");
}
print("<ajxpdriver name=\"".$repository->accessType."\" label=\"".AJXP_Utils::xmlEntities($plug->getManifestLabel())."\" iconClass=\"$iconClass\" description_template=\"$descriptionTemplate\" description=\"".AJXP_Utils::xmlEntities($plug->getManifestDescription())."\">$manifest</ajxpdriver>");
print("<metasources>");
$metas = $pServ->getPluginsByType("metastore");
$metas = array_merge($metas, $pServ->getPluginsByType("meta"));
Expand All @@ -1422,6 +1428,14 @@ public function switchAction($action, $httpVars, $fileVars)
print("</meta>");
}
print("</metasources>");
if(!$repository->isTemplate){
print "<additional_info>";
$users = AuthService::countUsersForRepository($repId, false, true);
$shares = ConfService::getConfStorageImpl()->simpleStoreList("share", null, "", "serial", '', $repId);
print('<users total="'.$users.'"/>');
print('<shares total="'.count($shares).'"/>');
print "</additional_info>";
}
AJXP_XMLWriter::close("admin_data");
return ;
break;
Expand Down
6 changes: 4 additions & 2 deletions core/src/plugins/boot.conf/class.BootConfLoader.php
Expand Up @@ -633,12 +633,14 @@ public function getRolesForRepository($repositoryId, $rolePrefix = '', $countOnl
// TODO: Implement getUsersForRepository() method.

}

/**
* @param string $repositoryId
* @param boolean $details
* @return array('internal' => count, 'external' => count)
* @param bool $admin
* @return array
*/
public function countUsersForRepository($repositoryId, $details = false){
public function countUsersForRepository($repositoryId, $details = false, $admin=false){

}

Expand Down
5 changes: 3 additions & 2 deletions core/src/plugins/conf.serial/class.serialConfDriver.php
Expand Up @@ -383,9 +383,10 @@ public function getRolesForRepository($repositoryId, $rolePrefix = '', $countOnl
/**
* @param string $repositoryId
* @param boolean $details
* @return array('internal' => count, 'external' => count)
* @param bool $admin
* @return array
*/
public function countUsersForRepository($repositoryId, $details = false){
public function countUsersForRepository($repositoryId, $details = false, $admin=false){
$c = count($this->getUsersForRepository($repositoryId));
if($details) return array("internal" => $c);
else return $c;
Expand Down
23 changes: 13 additions & 10 deletions core/src/plugins/conf.sql/class.sqlConfDriver.php
Expand Up @@ -572,18 +572,21 @@ public function getUsersForRole($roleId, $countOnly = false){
/**
* @param string $repositoryId
* @param boolean $details
* @return Integer|Array
* @param bool $admin
* @return Array|int
*/
public function countUsersForRepository($repositoryId, $details = false){
public function countUsersForRepository($repositoryId, $details = false, $admin=false){
$object = ConfService::getRepositoryById($repositoryId);
if($object->securityScope() == "USER"){
if($details) return array('internal' => 1);
else return 1;
}else if($object->securityScope() == "GROUP"){
// Count users from current group
$groupUsers = AuthService::authCountUsers(AuthService::getLoggedUser()->getGroupPath());
if($details) return array('internal' => $groupUsers);
else return $groupUsers;
if(!$admin){
if($object->securityScope() == "USER"){
if($details) return array('internal' => 1);
else return 1;
}else if($object->securityScope() == "GROUP"){
// Count users from current group
$groupUsers = AuthService::authCountUsers(AuthService::getLoggedUser()->getGroupPath());
if($details) return array('internal' => $groupUsers);
else return $groupUsers;
}
}
// Users from roles
$internal = 0;
Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/core.conf/class.AbstractConfDriver.php
Expand Up @@ -440,9 +440,10 @@ abstract public function getRolesForRepository($repositoryId, $rolePrefix = '',
* @abstract
* @param string $repositoryId
* @param boolean $details
* @param boolean $admin
* @return Integer|Array
*/
abstract public function countUsersForRepository($repositoryId, $details = false);
abstract public function countUsersForRepository($repositoryId, $details = false, $admin = false);


/**
Expand Down

0 comments on commit 75ef4ea

Please sign in to comment.