Skip to content

Commit

Permalink
Adding group display name support
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Dec 5, 2016
1 parent 2098afb commit 5c84c53
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 150 deletions.
11 changes: 1 addition & 10 deletions lib/private/Group/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,13 @@ abstract class Backend implements \OCP\GroupInterface {
*/
const NOT_IMPLEMENTED = -501;

/**
* actions that user backends can define
*/
const CREATE_GROUP = 0x00000001;
const DELETE_GROUP = 0x00000010;
const ADD_TO_GROUP = 0x00000100;
const REMOVE_FROM_GOUP = 0x00001000;
//OBSOLETE const GET_DISPLAYNAME = 0x00010000;
const COUNT_USERS = 0x00100000;

protected $possibleActions = [
self::CREATE_GROUP => 'createGroup',
self::DELETE_GROUP => 'deleteGroup',
self::ADD_TO_GROUP => 'addToGroup',
self::REMOVE_FROM_GOUP => 'removeFromGroup',
self::COUNT_USERS => 'countUsersInGroup',
self::GROUP_DETAILS => 'getGroupDetails',
];

/**
Expand Down
11 changes: 10 additions & 1 deletion lib/private/Group/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,27 @@ class Group implements IGroup {
* @param \OC\Group\Backend[] $backends
* @param \OC\User\Manager $userManager
* @param \OC\Hooks\PublicEmitter $emitter
* @param string $displayName
*/
public function __construct($gid, $backends, $userManager, $emitter = null) {
public function __construct($gid, $backends, $userManager, $emitter = null, $displayName = null) {
$this->gid = $gid;
$this->backends = $backends;
$this->userManager = $userManager;
$this->emitter = $emitter;
$this->displayName = $displayName;
}

public function getGID() {
return $this->gid;
}

public function getDisplayName() {
if (is_null($this->displayName)) {
return $this->gid;
}
return $this->displayName;
}

/**
* get all users in the group
*
Expand Down
16 changes: 13 additions & 3 deletions lib/private/Group/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,29 @@ public function get($gid) {

/**
* @param string $gid
* @param string $displayName
* @return \OCP\IGroup
*/
protected function getGroupObject($gid) {
protected function getGroupObject($gid, $displayName = null) {
$backends = [];
foreach ($this->backends as $backend) {
if ($backend->groupExists($gid)) {
if ($backend->implementsActions(\OC\Group\Backend::GROUP_DETAILS)) {
$groupData = $backend->getGroupDetails($gid);
if (is_array($groupData)) {
// take the display name from the first backend that has a non-null one
if (is_null($displayName) && isset($groupData['displayName'])) {
$displayName = $groupData['displayName'];
}
$backends[] = $backend;
}
} else if ($backend->groupExists($gid)) {
$backends[] = $backend;
}
}
if (count($backends) === 0) {
return null;
}
$this->cachedGroups[$gid] = new Group($gid, $backends, $this->userManager, $this);
$this->cachedGroups[$gid] = new Group($gid, $backends, $this->userManager, $this, $displayName);
return $this->cachedGroups[$gid];
}

Expand Down
11 changes: 11 additions & 0 deletions lib/public/GroupInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@
*/
interface GroupInterface {

/**
* actions that user backends can define
*/
const CREATE_GROUP = 0x00000001;
const DELETE_GROUP = 0x00000010;
const ADD_TO_GROUP = 0x00000100;
const REMOVE_FROM_GOUP = 0x00001000;
//OBSOLETE const GET_DISPLAYNAME = 0x00010000;
const COUNT_USERS = 0x00100000;
const GROUP_DETAILS = 0x01000000;

/**
* Check if backend implements actions
* @param int $actions bitwise-or'ed actions
Expand Down
9 changes: 9 additions & 0 deletions lib/public/IGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <icewind@owncloud.com>
* @author Vincent Petry <PVince81@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud GmbH.
* @license AGPL-3.0
Expand Down Expand Up @@ -35,6 +36,14 @@ interface IGroup {
*/
public function getGID();

/**
* Returns the group display name
*
* @return string
* @since 9.2
*/
public function getDisplayName();

/**
* get all users in the group
*
Expand Down
Loading

0 comments on commit 5c84c53

Please sign in to comment.