Add proper PHPDoc

Makes my IDE happier when going through that file.
This commit is contained in:
Lukas Reschke 2015-09-08 14:02:30 +02:00
parent 75f939b8fe
commit a7f132a964
3 changed files with 100 additions and 24 deletions

View File

@ -31,13 +31,20 @@ class Apps {
/** @var \OCP\App\IAppManager */ /** @var \OCP\App\IAppManager */
private $appManager; private $appManager;
/**
* @param \OCP\App\IAppManager $appManager
*/
public function __construct(\OCP\App\IAppManager $appManager) { public function __construct(\OCP\App\IAppManager $appManager) {
$this->appManager = $appManager; $this->appManager = $appManager;
} }
public function getApps($parameters){ /**
* @param array $parameters
* @return OC_OCS_Result
*/
public function getApps($parameters) {
$apps = OC_App::listAllApps(); $apps = OC_App::listAllApps();
$list = array(); $list = [];
foreach($apps as $app) { foreach($apps as $app) {
$list[] = $app['id']; $list[] = $app['id'];
} }
@ -62,7 +69,11 @@ class Apps {
} }
} }
public function getAppInfo($parameters){ /**
* @param array $parameters
* @return OC_OCS_Result
*/
public function getAppInfo($parameters) {
$app = $parameters['appid']; $app = $parameters['appid'];
$info = \OCP\App::getAppInfo($app); $info = \OCP\App::getAppInfo($app);
if(!is_null($info)) { if(!is_null($info)) {
@ -72,13 +83,21 @@ class Apps {
} }
} }
public function enable($parameters){ /**
* @param array $parameters
* @return OC_OCS_Result
*/
public function enable($parameters) {
$app = $parameters['appid']; $app = $parameters['appid'];
$this->appManager->enableApp($app); $this->appManager->enableApp($app);
return new OC_OCS_Result(null, 100); return new OC_OCS_Result(null, 100);
} }
public function disable($parameters){ /**
* @param array $parameters
* @return OC_OCS_Result
*/
public function disable($parameters) {
$app = $parameters['appid']; $app = $parameters['appid'];
$this->appManager->disableApp($app); $this->appManager->disableApp($app);
return new OC_OCS_Result(null, 100); return new OC_OCS_Result(null, 100);

View File

@ -25,6 +25,8 @@ namespace OCA\Provisioning_API;
use \OC_OCS_Result; use \OC_OCS_Result;
use \OC_SubAdmin; use \OC_SubAdmin;
use OCP\IGroup;
use OCP\IUser;
class Groups{ class Groups{
@ -39,21 +41,25 @@ class Groups{
* @param \OCP\IUserSession $userSession * @param \OCP\IUserSession $userSession
*/ */
public function __construct(\OCP\IGroupManager $groupManager, public function __construct(\OCP\IGroupManager $groupManager,
\OCP\IUserSession $userSession) { \OCP\IUserSession $userSession) {
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->userSession = $userSession; $this->userSession = $userSession;
} }
/** /**
* returns a list of groups * returns a list of groups
*
* @param array $parameters
* @return OC_OCS_Result
*/ */
public function getGroups($parameters){ public function getGroups($parameters) {
$search = !empty($_GET['search']) ? $_GET['search'] : ''; $search = !empty($_GET['search']) ? $_GET['search'] : '';
$limit = !empty($_GET['limit']) ? $_GET['limit'] : null; $limit = !empty($_GET['limit']) ? $_GET['limit'] : null;
$offset = !empty($_GET['offset']) ? $_GET['offset'] : null; $offset = !empty($_GET['offset']) ? $_GET['offset'] : null;
$groups = $this->groupManager->search($search, $limit, $offset); $groups = $this->groupManager->search($search, $limit, $offset);
$groups = array_map(function($group) { $groups = array_map(function($group) {
/** @var IGroup $group */
return $group->getGID(); return $group->getGID();
}, $groups); }, $groups);
@ -62,6 +68,9 @@ class Groups{
/** /**
* returns an array of users in the group specified * returns an array of users in the group specified
*
* @param array $parameters
* @return OC_OCS_Result
*/ */
public function getGroup($parameters) { public function getGroup($parameters) {
// Check if user is logged in // Check if user is logged in
@ -71,7 +80,7 @@ class Groups{
} }
// Check the group exists // Check the group exists
if(!$this->groupManager->groupExists($parameters['groupid'])){ if(!$this->groupManager->groupExists($parameters['groupid'])) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested group could not be found'); return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested group could not be found');
} }
// Check subadmin has access to this group // Check subadmin has access to this group
@ -79,6 +88,7 @@ class Groups{
|| in_array($parameters['groupid'], \OC_SubAdmin::getSubAdminsGroups($user->getUID()))){ || in_array($parameters['groupid'], \OC_SubAdmin::getSubAdminsGroups($user->getUID()))){
$users = $this->groupManager->get($parameters['groupid'])->getUsers(); $users = $this->groupManager->get($parameters['groupid'])->getUsers();
$users = array_map(function($user) { $users = array_map(function($user) {
/** @var IUser $user */
return $user->getUID(); return $user->getUID();
}, $users); }, $users);
$users = array_values($users); $users = array_values($users);
@ -90,23 +100,30 @@ class Groups{
/** /**
* creates a new group * creates a new group
*
* @param array $parameters
* @return OC_OCS_Result
*/ */
public function addGroup($parameters){ public function addGroup($parameters) {
// Validate name // Validate name
$groupid = isset($_POST['groupid']) ? $_POST['groupid'] : ''; $groupId = isset($_POST['groupid']) ? $_POST['groupid'] : '';
if( preg_match( '/[^a-zA-Z0-9 _\.@\-]/', $groupid ) || empty($groupid)){ if( preg_match( '/[^a-zA-Z0-9 _\.@\-]/', $groupId ) || empty($groupId)){
\OCP\Util::writeLog('provisioning_api', 'Attempt made to create group using invalid characters.', \OCP\Util::ERROR); \OCP\Util::writeLog('provisioning_api', 'Attempt made to create group using invalid characters.', \OCP\Util::ERROR);
return new OC_OCS_Result(null, 101, 'Invalid group name'); return new OC_OCS_Result(null, 101, 'Invalid group name');
} }
// Check if it exists // Check if it exists
if($this->groupManager->groupExists($groupid)){ if($this->groupManager->groupExists($groupId)){
return new OC_OCS_Result(null, 102); return new OC_OCS_Result(null, 102);
} }
$this->groupManager->createGroup($groupid); $this->groupManager->createGroup($groupId);
return new OC_OCS_Result(null, 100); return new OC_OCS_Result(null, 100);
} }
public function deleteGroup($parameters){ /**
* @param array $parameters
* @return OC_OCS_Result
*/
public function deleteGroup($parameters) {
// Check it exists // Check it exists
if(!$this->groupManager->groupExists($parameters['groupid'])){ if(!$this->groupManager->groupExists($parameters['groupid'])){
return new OC_OCS_Result(null, 101); return new OC_OCS_Result(null, 101);
@ -118,6 +135,10 @@ class Groups{
} }
} }
/**
* @param array $parameters
* @return OC_OCS_Result
*/
public function getSubAdminsOfGroup($parameters) { public function getSubAdminsOfGroup($parameters) {
$group = $parameters['groupid']; $group = $parameters['groupid'];
// Check group exists // Check group exists

View File

@ -48,10 +48,10 @@ class Users {
* @param \OCP\IUserManager $userManager * @param \OCP\IUserManager $userManager
* @param \OCP\IConfig $config * @param \OCP\IConfig $config
* @param \OCP\IGroupManager $groupManager * @param \OCP\IGroupManager $groupManager
* @param \OCP\IUserSession $user * @param \OCP\IUserSession $userSession
*/ */
public function __construct(\OCP\IUserManager $userManager, public function __construct(\OCP\IUserManager $userManager,
\OCP\IConfig $config, \OCP\IConfig $config,
\OCP\IGroupManager $groupManager, \OCP\IGroupManager $groupManager,
\OCP\IUserSession $userSession) { \OCP\IUserSession $userSession) {
$this->userManager = $userManager; $this->userManager = $userManager;
@ -62,8 +62,10 @@ class Users {
/** /**
* returns a list of users * returns a list of users
*
* @return OC_OCS_Result
*/ */
public function getUsers(){ public function getUsers() {
$search = !empty($_GET['search']) ? $_GET['search'] : ''; $search = !empty($_GET['search']) ? $_GET['search'] : '';
$limit = !empty($_GET['limit']) ? $_GET['limit'] : null; $limit = !empty($_GET['limit']) ? $_GET['limit'] : null;
$offset = !empty($_GET['offset']) ? $_GET['offset'] : null; $offset = !empty($_GET['offset']) ? $_GET['offset'] : null;
@ -76,7 +78,10 @@ class Users {
]); ]);
} }
public function addUser(){ /**
* @return OC_OCS_Result
*/
public function addUser() {
$userId = isset($_POST['userid']) ? $_POST['userid'] : null; $userId = isset($_POST['userid']) ? $_POST['userid'] : null;
$password = isset($_POST['password']) ? $_POST['password'] : null; $password = isset($_POST['password']) ? $_POST['password'] : null;
if($this->userManager->userExists($userId)) { if($this->userManager->userExists($userId)) {
@ -96,6 +101,9 @@ class Users {
/** /**
* gets user info * gets user info
*
* @param array $parameters
* @return OC_OCS_Result
*/ */
public function getUser($parameters){ public function getUser($parameters){
$userId = $parameters['userid']; $userId = $parameters['userid'];
@ -150,8 +158,11 @@ class Users {
/** /**
* edit users * edit users
*
* @param array $parameters
* @return OC_OCS_Result
*/ */
public function editUser($parameters){ public function editUser($parameters) {
$userId = $parameters['userid']; $userId = $parameters['userid'];
// Check if user is logged in // Check if user is logged in
@ -230,7 +241,11 @@ class Users {
return new OC_OCS_Result(null, 100); return new OC_OCS_Result(null, 100);
} }
public function deleteUser($parameters){ /**
* @param array $parameters
* @return OC_OCS_Result
*/
public function deleteUser($parameters) {
// Check if user is logged in // Check if user is logged in
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
if ($user === null) { if ($user === null) {
@ -253,6 +268,10 @@ class Users {
} }
} }
/**
* @param array $parameters
* @return OC_OCS_Result
*/
public function getUsersGroups($parameters) { public function getUsersGroups($parameters) {
// Check if user is logged in // Check if user is logged in
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
@ -286,7 +305,11 @@ class Users {
} }
public function addToGroup($parameters){ /**
* @param array $parameters
* @return OC_OCS_Result
*/
public function addToGroup($parameters) {
// Check if user is logged in // Check if user is logged in
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
if ($user === null) { if ($user === null) {
@ -317,6 +340,10 @@ class Users {
return new OC_OCS_Result(null, 100); return new OC_OCS_Result(null, 100);
} }
/**
* @param array $parameters
* @return OC_OCS_Result
*/
public function removeFromGroup($parameters) { public function removeFromGroup($parameters) {
// Check if user is logged in // Check if user is logged in
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
@ -362,6 +389,9 @@ class Users {
/** /**
* Creates a subadmin * Creates a subadmin
*
* @param array $parameters
* @return OC_OCS_Result
*/ */
public function addSubAdmin($parameters) { public function addSubAdmin($parameters) {
$group = $_POST['groupid']; $group = $_POST['groupid'];
@ -393,6 +423,9 @@ class Users {
/** /**
* Removes a subadmin from a group * Removes a subadmin from a group
*
* @param array $parameters
* @return OC_OCS_Result
*/ */
public function removeSubAdmin($parameters) { public function removeSubAdmin($parameters) {
$group = $parameters['_delete']['groupid']; $group = $parameters['_delete']['groupid'];
@ -414,7 +447,10 @@ class Users {
} }
/** /**
* @Get the groups a user is a subadmin of * Get the groups a user is a subadmin of
*
* @param array $parameters
* @return OC_OCS_Result
*/ */
public function getUserSubAdminGroups($parameters) { public function getUserSubAdminGroups($parameters) {
$user = $parameters['userid']; $user = $parameters['userid'];
@ -431,8 +467,8 @@ class Users {
} }
/** /**
* @param $userId * @param string $userId
* @param $data * @param array $data
* @return mixed * @return mixed
* @throws \OCP\Files\NotFoundException * @throws \OCP\Files\NotFoundException
*/ */