Make the provisioning api app strict
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
640db3d5fe
commit
24b58a7683
5 changed files with 46 additions and 44 deletions
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
|
@ -45,7 +46,7 @@ class AppConfigController extends OCSController {
|
|||
* @param IConfig $config
|
||||
* @param IAppConfig $appConfig
|
||||
*/
|
||||
public function __construct($appName,
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
IConfig $config,
|
||||
IAppConfig $appConfig) {
|
||||
|
@ -57,7 +58,7 @@ class AppConfigController extends OCSController {
|
|||
/**
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function getApps() {
|
||||
public function getApps(): DataResponse {
|
||||
return new DataResponse([
|
||||
'data' => $this->appConfig->getApps(),
|
||||
]);
|
||||
|
@ -67,7 +68,7 @@ class AppConfigController extends OCSController {
|
|||
* @param string $app
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function getKeys($app) {
|
||||
public function getKeys(string $app): DataResponse {
|
||||
try {
|
||||
$this->verifyAppId($app);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
|
@ -84,7 +85,7 @@ class AppConfigController extends OCSController {
|
|||
* @param string $defaultValue
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function getValue($app, $key, $defaultValue = '') {
|
||||
public function getValue(string $app, string $key, string $defaultValue = ''): DataResponse {
|
||||
try {
|
||||
$this->verifyAppId($app);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
|
@ -102,7 +103,7 @@ class AppConfigController extends OCSController {
|
|||
* @param string $value
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function setValue($app, $key, $value) {
|
||||
public function setValue(string $app, string $key, string $value): DataResponse {
|
||||
try {
|
||||
$this->verifyAppId($app);
|
||||
$this->verifyConfigKey($app, $key);
|
||||
|
@ -120,7 +121,7 @@ class AppConfigController extends OCSController {
|
|||
* @param string $key
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function deleteKey($app, $key) {
|
||||
public function deleteKey(string $app, string $key): DataResponse {
|
||||
try {
|
||||
$this->verifyAppId($app);
|
||||
$this->verifyConfigKey($app, $key);
|
||||
|
@ -136,7 +137,7 @@ class AppConfigController extends OCSController {
|
|||
* @param string $app
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function verifyAppId($app) {
|
||||
protected function verifyAppId(string $app) {
|
||||
if (\OC_App::cleanAppId($app) !== $app) {
|
||||
throw new \InvalidArgumentException('Invalid app id given');
|
||||
}
|
||||
|
@ -147,7 +148,7 @@ class AppConfigController extends OCSController {
|
|||
* @param string $key
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function verifyConfigKey($app, $key) {
|
||||
protected function verifyConfigKey(string $app, string $key) {
|
||||
if (in_array($key, ['installed_version', 'enabled', 'types'])) {
|
||||
throw new \InvalidArgumentException('The given key can not be set');
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
|
@ -44,7 +45,7 @@ class AppsController extends OCSController {
|
|||
* @param IAppManager $appManager
|
||||
*/
|
||||
public function __construct(
|
||||
$appName,
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
IAppManager $appManager
|
||||
) {
|
||||
|
@ -58,7 +59,7 @@ class AppsController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function getApps($filter = null) {
|
||||
public function getApps(string $filter = null): DataResponse {
|
||||
$apps = (new OC_App())->listAllApps();
|
||||
$list = [];
|
||||
foreach($apps as $app) {
|
||||
|
@ -88,7 +89,7 @@ class AppsController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function getAppInfo($app) {
|
||||
public function getAppInfo(string $app): DataResponse {
|
||||
$info = \OCP\App::getAppInfo($app);
|
||||
if(!is_null($info)) {
|
||||
return new DataResponse(OC_App::getAppInfo($app));
|
||||
|
@ -103,7 +104,7 @@ class AppsController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function enable($app) {
|
||||
public function enable(string $app): DataResponse {
|
||||
try {
|
||||
$this->appManager->enableApp($app);
|
||||
} catch (AppPathNotFoundException $e) {
|
||||
|
@ -117,7 +118,7 @@ class AppsController extends OCSController {
|
|||
* @param string $app
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function disable($app) {
|
||||
public function disable(string $app): DataResponse {
|
||||
$this->appManager->disableApp($app);
|
||||
return new DataResponse();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
|
@ -56,7 +57,7 @@ class GroupsController extends OCSController {
|
|||
* @param ILogger $logger
|
||||
*/
|
||||
public function __construct(
|
||||
$appName,
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
IGroupManager $groupManager,
|
||||
IUserSession $userSession,
|
||||
|
@ -78,7 +79,7 @@ class GroupsController extends OCSController {
|
|||
* @param int $offset
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function getGroups($search = '', $limit = null, $offset = null) {
|
||||
public function getGroups(string $search = '', $limit = null, $offset = null): DataResponse {
|
||||
if ($limit !== null) {
|
||||
$limit = (int)$limit;
|
||||
}
|
||||
|
@ -104,7 +105,7 @@ class GroupsController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function getGroup($groupId) {
|
||||
public function getGroup(string $groupId): DataResponse {
|
||||
$user = $this->userSession->getUser();
|
||||
|
||||
// Check the group exists
|
||||
|
@ -142,7 +143,7 @@ class GroupsController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function addGroup($groupid) {
|
||||
public function addGroup(string $groupid): DataResponse {
|
||||
// Validate name
|
||||
if(empty($groupid)) {
|
||||
$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
|
||||
|
@ -163,7 +164,7 @@ class GroupsController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function deleteGroup($groupId) {
|
||||
public function deleteGroup(string $groupId): DataResponse {
|
||||
// Check it exists
|
||||
if(!$this->groupManager->groupExists($groupId)){
|
||||
throw new OCSException('', 101);
|
||||
|
@ -180,7 +181,7 @@ class GroupsController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function getSubAdminsOfGroup($groupId) {
|
||||
public function getSubAdminsOfGroup(string $groupId): DataResponse {
|
||||
// Check group exists
|
||||
$targetGroup = $this->groupManager->get($groupId);
|
||||
if($targetGroup === null) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
|
@ -87,7 +88,7 @@ class UsersController extends OCSController {
|
|||
* @param NewUserMailHelper $newUserMailHelper
|
||||
* @param FederatedFileSharingFactory $federatedFileSharingFactory
|
||||
*/
|
||||
public function __construct($appName,
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
IUserManager $userManager,
|
||||
IConfig $config,
|
||||
|
@ -123,7 +124,7 @@ class UsersController extends OCSController {
|
|||
* @param int $offset
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function getUsers($search = '', $limit = null, $offset = null) {
|
||||
public function getUsers(string $search = '', $limit = null, $offset = null): DataResponse {
|
||||
$user = $this->userSession->getUser();
|
||||
$users = [];
|
||||
|
||||
|
@ -167,7 +168,7 @@ class UsersController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function addUser($userid, $password, $groups = null) {
|
||||
public function addUser(string $userid, string $password, $groups = null): DataResponse {
|
||||
$user = $this->userSession->getUser();
|
||||
$isAdmin = $this->groupManager->isAdmin($user->getUID());
|
||||
$subAdminManager = $this->groupManager->getSubAdmin();
|
||||
|
@ -230,7 +231,7 @@ class UsersController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function getUser($userId) {
|
||||
public function getUser(string $userId): DataResponse {
|
||||
$data = $this->getUserData($userId);
|
||||
return new DataResponse($data);
|
||||
}
|
||||
|
@ -244,7 +245,7 @@ class UsersController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function getCurrentUser() {
|
||||
public function getCurrentUser(): DataResponse {
|
||||
$user = $this->userSession->getUser();
|
||||
if ($user) {
|
||||
$data = $this->getUserData($user->getUID());
|
||||
|
@ -266,7 +267,7 @@ class UsersController extends OCSController {
|
|||
* @return array
|
||||
* @throws OCSException
|
||||
*/
|
||||
protected function getUserData($userId) {
|
||||
protected function getUserData(string $userId): array {
|
||||
$currentLoggedInUser = $this->userSession->getUser();
|
||||
|
||||
$data = [];
|
||||
|
@ -314,7 +315,7 @@ class UsersController extends OCSController {
|
|||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
*/
|
||||
public function getEditableFields() {
|
||||
public function getEditableFields(): DataResponse {
|
||||
$permittedFields = [];
|
||||
|
||||
// Editing self (display, email)
|
||||
|
@ -349,9 +350,8 @@ class UsersController extends OCSController {
|
|||
* @param string $value
|
||||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
* @throws OCSForbiddenException
|
||||
*/
|
||||
public function editUser($userId, $key, $value) {
|
||||
public function editUser(string $userId, string $key, string $value): DataResponse {
|
||||
$currentLoggedInUser = $this->userSession->getUser();
|
||||
|
||||
$targetUser = $this->userManager->get($userId);
|
||||
|
@ -481,9 +481,8 @@ class UsersController extends OCSController {
|
|||
* @param string $userId
|
||||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
* @throws OCSForbiddenException
|
||||
*/
|
||||
public function deleteUser($userId) {
|
||||
public function deleteUser(string $userId): DataResponse {
|
||||
$currentLoggedInUser = $this->userSession->getUser();
|
||||
|
||||
$targetUser = $this->userManager->get($userId);
|
||||
|
@ -515,7 +514,7 @@ class UsersController extends OCSController {
|
|||
* @throws OCSException
|
||||
* @throws OCSForbiddenException
|
||||
*/
|
||||
public function disableUser($userId) {
|
||||
public function disableUser(string $userId): DataResponse {
|
||||
return $this->setEnabled($userId, false);
|
||||
}
|
||||
|
||||
|
@ -528,7 +527,7 @@ class UsersController extends OCSController {
|
|||
* @throws OCSException
|
||||
* @throws OCSForbiddenException
|
||||
*/
|
||||
public function enableUser($userId) {
|
||||
public function enableUser(string $userId): DataResponse {
|
||||
return $this->setEnabled($userId, true);
|
||||
}
|
||||
|
||||
|
@ -537,9 +536,8 @@ class UsersController extends OCSController {
|
|||
* @param bool $value
|
||||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
* @throws OCSForbiddenException
|
||||
*/
|
||||
private function setEnabled($userId, $value) {
|
||||
private function setEnabled(string $userId, bool $value): DataResponse {
|
||||
$currentLoggedInUser = $this->userSession->getUser();
|
||||
|
||||
$targetUser = $this->userManager->get($userId);
|
||||
|
@ -566,7 +564,7 @@ class UsersController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function getUsersGroups($userId) {
|
||||
public function getUsersGroups(string $userId): DataResponse {
|
||||
$loggedInUser = $this->userSession->getUser();
|
||||
|
||||
$targetUser = $this->userManager->get($userId);
|
||||
|
@ -612,7 +610,7 @@ class UsersController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function addToGroup($userId, $groupid = '') {
|
||||
public function addToGroup(string $userId, string $groupid = ''): DataResponse {
|
||||
if($groupid === '') {
|
||||
throw new OCSException('', 101);
|
||||
}
|
||||
|
@ -647,7 +645,7 @@ class UsersController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function removeFromGroup($userId, $groupid) {
|
||||
public function removeFromGroup(string $userId, string $groupid): DataResponse {
|
||||
$loggedInUser = $this->userSession->getUser();
|
||||
|
||||
if($groupid === null || trim($groupid) === '') {
|
||||
|
@ -711,7 +709,7 @@ class UsersController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function addSubAdmin($userId, $groupid) {
|
||||
public function addSubAdmin(string $userId, string $groupid): DataResponse {
|
||||
$group = $this->groupManager->get($groupid);
|
||||
$user = $this->userManager->get($userId);
|
||||
|
||||
|
@ -752,7 +750,7 @@ class UsersController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function removeSubAdmin($userId, $groupid) {
|
||||
public function removeSubAdmin(string $userId, string $groupid): DataResponse {
|
||||
$group = $this->groupManager->get($groupid);
|
||||
$user = $this->userManager->get($userId);
|
||||
$subAdminManager = $this->groupManager->getSubAdmin();
|
||||
|
@ -785,7 +783,7 @@ class UsersController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function getUserSubAdminGroups($userId) {
|
||||
public function getUserSubAdminGroups(string $userId): DataResponse {
|
||||
$user = $this->userManager->get($userId);
|
||||
// Check if the user exists
|
||||
if($user === null) {
|
||||
|
@ -810,7 +808,7 @@ class UsersController extends OCSController {
|
|||
* @return array
|
||||
* @throws \OCP\Files\NotFoundException
|
||||
*/
|
||||
protected function fillStorageInfo($userId) {
|
||||
protected function fillStorageInfo(string $userId): array {
|
||||
try {
|
||||
\OC_Util::tearDownFS();
|
||||
\OC_Util::setupFS($userId);
|
||||
|
@ -838,7 +836,7 @@ class UsersController extends OCSController {
|
|||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function resendWelcomeMessage($userId) {
|
||||
public function resendWelcomeMessage(string $userId): DataResponse {
|
||||
$currentLoggedInUser = $this->userSession->getUser();
|
||||
|
||||
$targetUser = $this->userManager->get($userId);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -51,8 +52,8 @@ class ProvisioningApiMiddleware extends Middleware {
|
|||
*/
|
||||
public function __construct(
|
||||
IControllerMethodReflector $reflector,
|
||||
$isAdmin,
|
||||
$isSubAdmin) {
|
||||
bool $isAdmin,
|
||||
bool $isSubAdmin) {
|
||||
$this->reflector = $reflector;
|
||||
$this->isAdmin = $isAdmin;
|
||||
$this->isSubAdmin = $isSubAdmin;
|
||||
|
|
Loading…
Reference in a new issue