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.

AppEnabledPlugin.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\Connector\Sabre;
  26. use OCP\App\IAppManager;
  27. use Sabre\DAV\Exception\Forbidden;
  28. use Sabre\DAV\ServerPlugin;
  29. /**
  30. * Plugin to check if an app is enabled for the current user
  31. */
  32. class AppEnabledPlugin extends ServerPlugin {
  33. /**
  34. * Reference to main server object
  35. *
  36. * @var \Sabre\DAV\Server
  37. */
  38. private $server;
  39. /**
  40. * @var string
  41. */
  42. private $app;
  43. /**
  44. * @var \OCP\App\IAppManager
  45. */
  46. private $appManager;
  47. /**
  48. * @param string $app
  49. * @param \OCP\App\IAppManager $appManager
  50. */
  51. public function __construct($app, IAppManager $appManager) {
  52. $this->app = $app;
  53. $this->appManager = $appManager;
  54. }
  55. /**
  56. * This initializes the plugin.
  57. *
  58. * This function is called by \Sabre\DAV\Server, after
  59. * addPlugin is called.
  60. *
  61. * This method should set up the required event subscriptions.
  62. *
  63. * @param \Sabre\DAV\Server $server
  64. * @return void
  65. */
  66. public function initialize(\Sabre\DAV\Server $server) {
  67. $this->server = $server;
  68. $this->server->on('beforeMethod:*', [$this, 'checkAppEnabled'], 30);
  69. }
  70. /**
  71. * This method is called before any HTTP after auth and checks if the user has access to the app
  72. *
  73. * @throws \Sabre\DAV\Exception\Forbidden
  74. * @return bool
  75. */
  76. public function checkAppEnabled() {
  77. if (!$this->appManager->isEnabledForUser($this->app)) {
  78. throw new Forbidden();
  79. }
  80. }
  81. }