Skip to content

Commit

Permalink
Cast types directly
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Mar 23, 2018
1 parent 2a8356d commit d597478
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions apps/provisioning_api/lib/Controller/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,7 @@ public function __construct(
* @param int $offset
* @return DataResponse
*/
public function getGroups(string $search = '', $limit = null, $offset = null): DataResponse {
if ($limit !== null) {
$limit = (int)$limit;
}
if ($offset !== null) {
$offset = (int)$offset;
}

public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse {
$groups = $this->groupManager->search($search, $limit, $offset);
$groups = array_map(function($group) {
/** @var IGroup $group */
Expand All @@ -113,14 +106,7 @@ public function getGroups(string $search = '', $limit = null, $offset = null): D
* @param int $offset
* @return DataResponse
*/
public function getGroupsDetails(string $search = '', $limit = null, $offset = null): DataResponse {
if ($limit !== null) {
$limit = (int)$limit;
}
if ($offset !== null) {
$offset = (int)$offset;
}

public function getGroupsDetails(string $search = '', int $limit = null, int $offset = null): DataResponse {
$groups = $this->groupManager->search($search, $limit, $offset);
$groups = array_map(function($group) {
/** @var IGroup $group */
Expand Down Expand Up @@ -154,16 +140,14 @@ public function getGroup(string $groupId): DataResponse {
*/
public function getGroupUsers(string $groupId): DataResponse {
$user = $this->userSession->getUser();
$isSubadminOfGroup = false;

// Check the group exists
if(!$this->groupManager->groupExists($groupId)) {
throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
}

$isSubadminOfGroup = false;
$group = $this->groupManager->get($groupId);
if ($group !== null) {
$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
} else {
throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
}

// Check subadmin has access to this group
Expand Down Expand Up @@ -192,18 +176,16 @@ public function getGroupUsers(string $groupId): DataResponse {
* @return DataResponse
* @throws OCSException
*/
public function getGroupUsersDetails(string $groupId, $limit = null, $offset = 0): DataResponse {
public function getGroupUsersDetails(string $groupId, int $limit = null, int $offset = 0): DataResponse {
$user = $this->userSession->getUser();
$isSubadminOfGroup = false;

// Check the group exists
if(!$this->groupManager->groupExists($groupId)) {
throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
}

$isSubadminOfGroup = false;
$group = $this->groupManager->get($groupId);
if ($group !== null) {
$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
} else {
throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
}

// Check subadmin has access to this group
Expand Down

0 comments on commit d597478

Please sign in to comment.