Skip to content

Commit

Permalink
Merge pull request #36 from nextcloud/ext-api-sharedroster
Browse files Browse the repository at this point in the history
add sharedroster operation to external api
  • Loading branch information
sualko committed Jul 18, 2017
2 parents f5bb94c + 07eff1d commit 6e55221
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion ajax/externalApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ function stringOrEmpty($s) {
}
}

function getUsername() {
if(!empty($_POST['username'])) {
if(!empty($_POST['domain'])) {
return $_POST['username'] . "@" . $_POST['domain'];
} else {
return $_POST['username'];
}
} else {
abort('No username provided');
}
}

function checkPassword() {
$currentUser = null;

Expand Down Expand Up @@ -78,6 +90,35 @@ function isUser() {
));
}

function sharedRoster() {
$username = getUsername();
$roster = [];

$userGroups = \OC::$server->getGroupManager()->getUserIdGroups($username);

foreach($userGroups as $userGroup) {
foreach($userGroup->getUsers() as $user) {
$uid = $user->getUID();

if(!$roster[$uid]) {
$roster[$uid] = [
'name' => $user->getDisplayName(),
'groups' => []
];
}

$roster[$uid]['groups'][] = $userGroup->getDisplayName();
}
}

echo json_encode(array(
'result' => 'success',
'data' => array(
'sharedRoster' => $roster
)
));
}

// check if we have a signature
if ( ! isset( $_SERVER[ 'HTTP_X_JSXC_SIGNATURE' ] ) )
abort( 'HTTP header "X-JSXC-Signature" is missing.' );
Expand All @@ -103,6 +144,9 @@ function isUser() {
case 'isuser':
isUser();
break;
case 'sharedroster':
sharedRoster();
break;
default:
abort( "Unsupported operation." );
abort( "Unsupported operation.");
}

0 comments on commit 6e55221

Please sign in to comment.