You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AppsController.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Tom Needham <tom@owncloud.com>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\Provisioning_API\Controller;
  27. use \OC_App;
  28. use OCP\App\AppPathNotFoundException;
  29. use OCP\App\IAppManager;
  30. use OCP\AppFramework\Http\DataResponse;
  31. use OCP\AppFramework\OCS\OCSException;
  32. use OCP\AppFramework\OCSController;
  33. use OCP\IRequest;
  34. class AppsController extends OCSController {
  35. /** @var \OCP\App\IAppManager */
  36. private $appManager;
  37. /**
  38. * @param string $appName
  39. * @param IRequest $request
  40. * @param IAppManager $appManager
  41. */
  42. public function __construct(
  43. $appName,
  44. IRequest $request,
  45. IAppManager $appManager
  46. ) {
  47. parent::__construct($appName, $request);
  48. $this->appManager = $appManager;
  49. }
  50. /**
  51. * @param string $filter
  52. * @return DataResponse
  53. * @throws OCSException
  54. */
  55. public function getApps($filter = null) {
  56. $apps = (new OC_App())->listAllApps();
  57. $list = [];
  58. foreach($apps as $app) {
  59. $list[] = $app['id'];
  60. }
  61. if($filter){
  62. switch($filter){
  63. case 'enabled':
  64. return new DataResponse(['apps' => \OC_App::getEnabledApps()]);
  65. break;
  66. case 'disabled':
  67. $enabled = OC_App::getEnabledApps();
  68. return new DataResponse(['apps' => array_diff($list, $enabled)]);
  69. break;
  70. default:
  71. // Invalid filter variable
  72. throw new OCSException('', 101);
  73. }
  74. } else {
  75. return new DataResponse(['apps' => $list]);
  76. }
  77. }
  78. /**
  79. * @param string $app
  80. * @return DataResponse
  81. * @throws OCSException
  82. */
  83. public function getAppInfo($app) {
  84. $info = \OCP\App::getAppInfo($app);
  85. if(!is_null($info)) {
  86. return new DataResponse(OC_App::getAppInfo($app));
  87. }
  88. throw new OCSException('The request app was not found', \OCP\API::RESPOND_NOT_FOUND);
  89. }
  90. /**
  91. * @PasswordConfirmationRequired
  92. * @param string $app
  93. * @return DataResponse
  94. * @throws OCSException
  95. */
  96. public function enable($app) {
  97. try {
  98. $this->appManager->enableApp($app);
  99. } catch (AppPathNotFoundException $e) {
  100. throw new OCSException('The request app was not found', \OCP\API::RESPOND_NOT_FOUND);
  101. }
  102. return new DataResponse();
  103. }
  104. /**
  105. * @PasswordConfirmationRequired
  106. * @param string $app
  107. * @return DataResponse
  108. */
  109. public function disable($app) {
  110. $this->appManager->disableApp($app);
  111. return new DataResponse();
  112. }
  113. }