From 07eff1db455a74d2da29eace0da5101c15171ead Mon Sep 17 00:00:00 2001 From: sualko Date: Tue, 18 Jul 2017 09:53:00 +0200 Subject: [PATCH] add sharedroster operation to external api returns all members of all groups in which the specified user is part of --- ajax/externalApi.php | 46 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/ajax/externalApi.php b/ajax/externalApi.php index 93989c8a..7f625bb4 100644 --- a/ajax/externalApi.php +++ b/ajax/externalApi.php @@ -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; @@ -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.' ); @@ -103,6 +144,9 @@ function isUser() { case 'isuser': isUser(); break; + case 'sharedroster': + sharedRoster(); + break; default: - abort( "Unsupported operation." ); + abort( "Unsupported operation."); }