Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function readDBConfig() {
$userMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID());
$globalMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
$groups = $this->groupManager->getUserGroupIds($this->getUser());
if (is_array($groups) && count($groups) !== 0) {
if (count($groups) !== 0) {
$groupMounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, $groups);
} else {
$groupMounts = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ public function __construct($appName, $urlParams = [], ServerContainer $server =
)
);



$securityMiddleware = new SecurityMiddleware(
$c->get(IRequest::class),
$c->get(IControllerMethodReflector::class),
Expand All @@ -242,7 +244,7 @@ public function __construct($appName, $urlParams = [], ServerContainer $server =
$server->query(ILogger::class),
$c->get('AppName'),
$server->getUserSession()->isLoggedIn(),
$server->getGroupManager()->isAdmin($this->getUserId()),
$this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()),
$server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()),
$server->getAppManager(),
$server->getL10N('lib')
Expand Down
10 changes: 5 additions & 5 deletions lib/private/Group/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function getUserGroups(IUser $user = null) {
* @param string $uid the user id
* @return \OC\Group\Group[]
*/
public function getUserIdGroups($uid) {
public function getUserIdGroups(string $uid): array {
$groups = [];

foreach ($this->getUserIdGroupIds($uid) as $groupId) {
Expand Down Expand Up @@ -321,17 +321,17 @@ public function isInGroup($userId, $group) {
* get a list of group ids for a user
*
* @param IUser $user
* @return array with group ids
* @return string[] with group ids
*/
public function getUserGroupIds(IUser $user) {
public function getUserGroupIds(IUser $user): array {
return $this->getUserIdGroupIds($user->getUID());
}

/**
* @param string $uid the user id
* @return GroupInterface[]
* @return string[]
*/
private function getUserIdGroupIds($uid) {
private function getUserIdGroupIds(string $uid): array {
if (!isset($this->cachedUserGroups[$uid])) {
$groups = [];
foreach ($this->backends as $backend) {
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Template/JSConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function getConfig() {

$countOfDataLocation = 0;
$dataLocation = str_replace(\OC::$SERVERROOT . '/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation);
if ($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) {
if ($countOfDataLocation !== 1 || $uid === null || !$this->groupManager->isAdmin($uid)) {
$dataLocation = false;
}

Expand Down Expand Up @@ -198,7 +198,7 @@ public function getConfig() {

$array = [
"_oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
"_oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false',
"_oc_isadmin" => $uid !== null && $this->groupManager->isAdmin($uid) ? 'true' : 'false',
"backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false',
"oc_dataURL" => is_string($dataLocation) ? "\"" . $dataLocation . "\"" : 'false',
"_oc_webroot" => "\"" . \OC::$WEBROOT . "\"",
Expand Down
4 changes: 2 additions & 2 deletions lib/public/IGroupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public function getUserGroups(IUser $user = null);

/**
* @param \OCP\IUser $user
* @return array with group names
* @return string[] with group names
* @since 8.0.0
*/
public function getUserGroupIds(IUser $user);
public function getUserGroupIds(IUser $user): array;

/**
* get a list of all display names in a group
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/Group/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,16 @@ public function testGetUserGroupIds() {
*/
$backend = $this->getTestBackend();
$backend->method('getUserGroups')
->with('myUID')
->willReturn(['123', 'abc']);

$manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
$manager->addBackend($backend);

/** @var \OC\User\User|\PHPUnit\Framework\MockObject\MockObject $user */
$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn('myUID');

$groups = $manager->getUserGroupIds($user);
$this->assertCount(2, $groups);
Expand Down