Start loading allowedusers setting from config
--- a/include/git/GitConfig.class.php
+++ b/include/git/GitConfig.class.php
@@ -113,7 +113,7 @@
$values = $this->config[$key];
}
- if ((count($values) == 1) || (!$multiValue)) {
+ if (!$multiValue) {
// single value
return $values[0];
} else {
--- a/include/git/project/Project.class.php
+++ b/include/git/project/Project.class.php
@@ -158,6 +158,13 @@
protected $uniqueAbbreviation = false;
/**
+ * Users allowed access to this project
+ *
+ * @var string[]|null
+ */
+ protected $allowedUsers = null;
+
+ /**
* The git object manager
*
* @var GitPHP_GitObjectManager
@@ -479,6 +486,43 @@
public function SetWebsite($site)
{
$this->website = $site;
+ }
+
+ /**
+ * Gets the allowed users for this project
+ *
+ * @return string[]|null
+ */
+ public function GetAllowedUsers()
+ {
+ return $this->allowedUsers;
+ }
+
+ /**
+ * Sets the allowed users for this project
+ *
+ * @param string[]|null $allowedUsers allowed users
+ */
+ public function SetAllowedUsers($allowedUsers)
+ {
+ $this->allowedUsers = $allowedUsers;
+ }
+
+ /**
+ * Checks if a user has access to this project
+ *
+ * @param string $username username
+ * @return boolean whether user is allowed
+ */
+ public function UserCanAccess($username)
+ {
+ if (empty($this->allowedUsers))
+ return true;
+
+ if (empty($username))
+ return false;
+
+ return in_array($username, $this->allowedUsers);
}
/**
--- a/include/git/projectlist/ProjectListBase.class.php
+++ b/include/git/projectlist/ProjectListBase.class.php
@@ -394,6 +394,10 @@
if ($config->HasValue('core.abbrev')) {
$project->SetAbbreviateLength($config->GetValue('core.abbrev'));
+ }
+
+ if ($config->HasValue('gitphp.allowedusers')) {
+ $project->SetAllowedUsers($config->GetValue('gitphp.allowedusers', true));
}
}
@@ -605,6 +609,9 @@
if (isset($projData['website']) && is_string($projData['website'])) {
$project->SetWebsite($projData['website']);
}
+ if (!empty($projData['allowedusers'])) {
+ $project->SetAllowedUsers($projData['allowedusers']);
+ }
}
/**