-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jld3103 <[email protected]>
- Loading branch information
1 parent
7611a80
commit 2b29189
Showing
8 changed files
with
3,796 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* | ||
* @author Joas Schilling <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -24,11 +25,14 @@ | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Provisioning_API\Controller; | ||
|
||
use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\Http\DataResponse200; | ||
use OCP\AppFramework\Http\DataResponse403; | ||
use OCP\AppFramework\OCSController; | ||
use OCP\IAppConfig; | ||
use OCP\IConfig; | ||
|
@@ -67,13 +71,13 @@ class AppConfigController extends OCSController { | |
* @param IAppConfig $appConfig | ||
*/ | ||
public function __construct(string $appName, | ||
IRequest $request, | ||
IConfig $config, | ||
IAppConfig $appConfig, | ||
IUserSession $userSession, | ||
IL10N $l10n, | ||
IGroupManager $groupManager, | ||
IManager $settingManager) { | ||
IRequest $request, | ||
IConfig $config, | ||
IAppConfig $appConfig, | ||
IUserSession $userSession, | ||
IL10N $l10n, | ||
IGroupManager $groupManager, | ||
IManager $settingManager) { | ||
parent::__construct($appName, $request); | ||
$this->config = $config; | ||
$this->appConfig = $appConfig; | ||
|
@@ -84,25 +88,25 @@ public function __construct(string $appName, | |
} | ||
|
||
/** | ||
* @return DataResponse | ||
* @return DataResponse200<array{data: string[]}> | ||
*/ | ||
public function getApps(): DataResponse { | ||
return new DataResponse([ | ||
public function getApps(): DataResponse200 { | ||
return new DataResponse200([ | ||
'data' => $this->appConfig->getApps(), | ||
]); | ||
} | ||
|
||
/** | ||
* @param string $app | ||
* @return DataResponse | ||
* @return DataResponse200<array{data: string[]}>|DataResponse403<array{data: array{message: string}}> | ||
*/ | ||
public function getKeys(string $app): DataResponse { | ||
public function getKeys(string $app): DataResponse200|DataResponse403 { | ||
try { | ||
$this->verifyAppId($app); | ||
} catch (\InvalidArgumentException $e) { | ||
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); | ||
return new DataResponse403(['data' => ['message' => $e->getMessage()]]); | ||
} | ||
return new DataResponse([ | ||
return new DataResponse200([ | ||
'data' => $this->config->getAppKeys($app), | ||
]); | ||
} | ||
|
@@ -111,15 +115,15 @@ public function getKeys(string $app): DataResponse { | |
* @param string $app | ||
* @param string $key | ||
* @param string $defaultValue | ||
* @return DataResponse | ||
* @return DataResponse200<array{data: string}>|DataResponse403<array{data: array{message: string}}> | ||
*/ | ||
public function getValue(string $app, string $key, string $defaultValue = ''): DataResponse { | ||
public function getValue(string $app, string $key, string $defaultValue = ''): DataResponse200|DataResponse403 { | ||
try { | ||
$this->verifyAppId($app); | ||
} catch (\InvalidArgumentException $e) { | ||
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); | ||
return new DataResponse403(['data' => ['message' => $e->getMessage()]]); | ||
} | ||
return new DataResponse([ | ||
return new DataResponse200([ | ||
'data' => $this->config->getAppValue($app, $key, $defaultValue), | ||
]); | ||
} | ||
|
@@ -131,9 +135,9 @@ public function getValue(string $app, string $key, string $defaultValue = ''): D | |
* @param string $app | ||
* @param string $key | ||
* @param string $value | ||
* @return DataResponse | ||
* @return DataResponse200|DataResponse403<array{data: array{message: string}}> | ||
*/ | ||
public function setValue(string $app, string $key, string $value): DataResponse { | ||
public function setValue(string $app, string $key, string $value): DataResponse200|DataResponse403 { | ||
$user = $this->userSession->getUser(); | ||
if ($user === null) { | ||
throw new \Exception("User is not logged in."); // Should not happen, since method is guarded by middleware | ||
|
@@ -147,29 +151,29 @@ public function setValue(string $app, string $key, string $value): DataResponse | |
$this->verifyAppId($app); | ||
$this->verifyConfigKey($app, $key, $value); | ||
} catch (\InvalidArgumentException $e) { | ||
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); | ||
return new DataResponse403(['data' => ['message' => $e->getMessage()]]); | ||
} | ||
|
||
$this->config->setAppValue($app, $key, $value); | ||
return new DataResponse(); | ||
return new DataResponse200(); | ||
} | ||
|
||
/** | ||
* @PasswordConfirmationRequired | ||
* @param string $app | ||
* @param string $key | ||
* @return DataResponse | ||
* @return DataResponse200|DataResponse403<array{data: array{message: string}}> | ||
*/ | ||
public function deleteKey(string $app, string $key): DataResponse { | ||
public function deleteKey(string $app, string $key): DataResponse200|DataResponse403 { | ||
try { | ||
$this->verifyAppId($app); | ||
$this->verifyConfigKey($app, $key, ''); | ||
} catch (\InvalidArgumentException $e) { | ||
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); | ||
return new DataResponse403(['data' => ['message' => $e->getMessage()]]); | ||
} | ||
|
||
$this->config->deleteAppValue($app, $key); | ||
return new DataResponse(); | ||
return new DataResponse200(); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
* @author Lukas Reschke <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Tom Needham <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -26,16 +27,22 @@ | |
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\Provisioning_API\Controller; | ||
|
||
use OC_App; | ||
use OCA\Provisioning_API\ResponseDefinitions; | ||
use OCP\App\AppPathNotFoundException; | ||
use OCP\App\IAppManager; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\Http\DataResponse200; | ||
use OCP\AppFramework\OCS\OCSException; | ||
use OCP\AppFramework\OCSController; | ||
use OCP\IRequest; | ||
|
||
/** | ||
* @psalm-import-type AppInfo from ResponseDefinitions | ||
*/ | ||
class AppsController extends OCSController { | ||
/** @var IAppManager */ | ||
private $appManager; | ||
|
@@ -52,42 +59,43 @@ public function __construct( | |
|
||
/** | ||
* @param string|null $filter | ||
* @return DataResponse | ||
* @return DataResponse200<array{apps: string[]}> | ||
* @throws OCSException | ||
*/ | ||
public function getApps(string $filter = null): DataResponse { | ||
public function getApps(string $filter = null): DataResponse200 { | ||
$apps = (new OC_App())->listAllApps(); | ||
/** @var string[] $list */ | ||
$list = []; | ||
foreach ($apps as $app) { | ||
$list[] = $app['id']; | ||
} | ||
if ($filter) { | ||
switch ($filter) { | ||
case 'enabled': | ||
return new DataResponse(['apps' => \OC_App::getEnabledApps()]); | ||
return new DataResponse200(['apps' => OC_App::getEnabledApps()]); | ||
break; | ||
case 'disabled': | ||
$enabled = OC_App::getEnabledApps(); | ||
return new DataResponse(['apps' => array_diff($list, $enabled)]); | ||
return new DataResponse200(['apps' => array_diff($list, $enabled)]); | ||
break; | ||
default: | ||
// Invalid filter variable | ||
throw new OCSException('', 101); | ||
} | ||
} else { | ||
return new DataResponse(['apps' => $list]); | ||
return new DataResponse200(['apps' => $list]); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $app | ||
* @return DataResponse | ||
* @return DataResponse200<AppInfo> | ||
* @throws OCSException | ||
*/ | ||
public function getAppInfo(string $app): DataResponse { | ||
public function getAppInfo(string $app): DataResponse200 { | ||
$info = $this->appManager->getAppInfo($app); | ||
if (!is_null($info)) { | ||
return new DataResponse($info); | ||
return new DataResponse200($info); | ||
} | ||
|
||
throw new OCSException('The request app was not found', OCSController::RESPOND_NOT_FOUND); | ||
|
@@ -96,25 +104,25 @@ public function getAppInfo(string $app): DataResponse { | |
/** | ||
* @PasswordConfirmationRequired | ||
* @param string $app | ||
* @return DataResponse | ||
* @return DataResponse200 | ||
* @throws OCSException | ||
*/ | ||
public function enable(string $app): DataResponse { | ||
public function enable(string $app): DataResponse200 { | ||
try { | ||
$this->appManager->enableApp($app); | ||
} catch (AppPathNotFoundException $e) { | ||
throw new OCSException('The request app was not found', OCSController::RESPOND_NOT_FOUND); | ||
} | ||
return new DataResponse(); | ||
return new DataResponse200(); | ||
} | ||
|
||
/** | ||
* @PasswordConfirmationRequired | ||
* @param string $app | ||
* @return DataResponse | ||
* @return DataResponse200 | ||
*/ | ||
public function disable(string $app): DataResponse { | ||
public function disable(string $app): DataResponse200 { | ||
$this->appManager->disableApp($app); | ||
return new DataResponse(); | ||
return new DataResponse200(); | ||
} | ||
} |
Oops, something went wrong.