summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-04-24 15:23:49 +0200
committerJoas Schilling <coding@schilljs.com>2023-04-25 12:12:18 +0200
commitb2b0bdfba9635ffea0e46b689f5a6f417ae23172 (patch)
tree9818d46c48156d0e7f410f8b5fd25daba5ff7a27
parent2d8a0e4d8748e98a58713d9bd015c7057ac77c12 (diff)
feat(middleware): Move RequireCallEnabled annotation to attribute
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--lib/Controller/CallController.php7
-rw-r--r--lib/Middleware/Attribute/RequireCallEnabled.php35
-rw-r--r--lib/Middleware/CanUseTalkMiddleware.php15
3 files changed, 45 insertions, 12 deletions
diff --git a/lib/Controller/CallController.php b/lib/Controller/CallController.php
index c88991973..c214d321a 100644
--- a/lib/Controller/CallController.php
+++ b/lib/Controller/CallController.php
@@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OCA\Talk\Controller;
+use OCA\Talk\Middleware\Attribute\RequireCallEnabled;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\Session;
use OCA\Talk\Participant;
@@ -61,13 +62,13 @@ class CallController extends AEnvironmentAwareController {
/**
* @PublicPage
- * @RequireCallEnabled
* @RequireParticipant
* @RequireReadWriteConversation
* @RequireModeratorOrNoLobby
*
* @return DataResponse
*/
+ #[RequireCallEnabled]
public function getPeersForCall(): DataResponse {
$timeout = $this->timeFactory->getTime() - Session::SESSION_TIMEOUT;
$result = [];
@@ -103,7 +104,6 @@ class CallController extends AEnvironmentAwareController {
/**
* @PublicPage
- * @RequireCallEnabled
* @RequireParticipant
* @RequireReadWriteConversation
* @RequireModeratorOrNoLobby
@@ -112,6 +112,7 @@ class CallController extends AEnvironmentAwareController {
* @param int|null $forcePermissions
* @return DataResponse
*/
+ #[RequireCallEnabled]
public function joinCall(?int $flags = null, ?int $forcePermissions = null, bool $silent = false): DataResponse {
$this->participantService->ensureOneToOneRoomIsFilled($this->room);
@@ -136,13 +137,13 @@ class CallController extends AEnvironmentAwareController {
/**
* @PublicPage
- * @RequireCallEnabled
* @RequireParticipant
* @RequirePermissions(permissions=call-start)
*
* @param int $attendeeId
* @return DataResponse
*/
+ #[RequireCallEnabled]
public function ringAttendee(int $attendeeId): DataResponse {
if ($this->room->getCallFlag() === Participant::FLAG_DISCONNECTED) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
diff --git a/lib/Middleware/Attribute/RequireCallEnabled.php b/lib/Middleware/Attribute/RequireCallEnabled.php
new file mode 100644
index 000000000..1f2b73e9a
--- /dev/null
+++ b/lib/Middleware/Attribute/RequireCallEnabled.php
@@ -0,0 +1,35 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\Talk\Middleware\Attribute;
+
+use Attribute;
+
+/**
+ * Attribute to check limit endpoint access when the app config start_calls is not enabled
+ */
+#[Attribute(Attribute::TARGET_METHOD)]
+class RequireCallEnabled {
+}
diff --git a/lib/Middleware/CanUseTalkMiddleware.php b/lib/Middleware/CanUseTalkMiddleware.php
index 7ee1da4a1..375a40fe4 100644
--- a/lib/Middleware/CanUseTalkMiddleware.php
+++ b/lib/Middleware/CanUseTalkMiddleware.php
@@ -26,6 +26,7 @@ namespace OCA\Talk\Middleware;
use OCA\Talk\Config;
use OCA\Talk\Controller\SignalingController;
use OCA\Talk\Exceptions\ForbiddenException;
+use OCA\Talk\Middleware\Attribute\RequireCallEnabled;
use OCA\Talk\Middleware\Exceptions\CanNotUseTalkException;
use OCA\Talk\Room;
use OCP\AppFramework\Controller;
@@ -35,7 +36,6 @@ use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCSController;
-use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
@@ -44,31 +44,25 @@ use OCP\IUserSession;
class CanUseTalkMiddleware extends Middleware {
private IUserSession $userSession;
private IGroupManager $groupManager;
- private IControllerMethodReflector $reflector;
private Config $talkConfig;
private IConfig $serverConfig;
public function __construct(
IUserSession $userSession,
IGroupManager $groupManager,
- IControllerMethodReflector $reflector,
Config $talkConfig,
IConfig $serverConfig,
) {
$this->userSession = $userSession;
$this->groupManager = $groupManager;
- $this->reflector = $reflector;
$this->talkConfig = $talkConfig;
$this->serverConfig = $serverConfig;
}
/**
- * @param Controller $controller
- * @param string $methodName
- *
* @throws CanNotUseTalkException
*/
- public function beforeController($controller, $methodName): void {
+ public function beforeController(Controller $controller, string $methodName): void {
$user = $this->userSession->getUser();
if ($user instanceof IUser && $this->talkConfig->isDisabledForUser($user)) {
if ($methodName === 'getWelcomeMessage'
@@ -80,7 +74,10 @@ class CanUseTalkMiddleware extends Middleware {
throw new CanNotUseTalkException();
}
- if ($this->reflector->hasAnnotation('RequireCallEnabled')
+ $reflectionMethod = new \ReflectionMethod($controller, $methodName);
+ $hasAttribute = !empty($reflectionMethod->getAttributes(RequireCallEnabled::class));
+
+ if ($hasAttribute
&& ((int) $this->serverConfig->getAppValue('spreed', 'start_calls')) === Room::START_CALL_NOONE) {
throw new CanNotUseTalkException();
}