]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/BaseApi.php
Merge pull request #11872 from annando/warnings
[friendica.git] / src / Module / BaseApi.php
index db5f191cf1d0bd6b63c421f82ab4598544afc667..f39a40cded75a52464d96637d59a87956fc46a35 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -79,19 +79,21 @@ class BaseApi extends BaseModule
         *
         * @throws HTTPException\ForbiddenException
         */
-       public function run(array $request = []): ResponseInterface
+       public function run(array $request = [], bool $scopecheck = true): ResponseInterface
        {
-               switch ($this->server['REQUEST_METHOD'] ?? Router::GET) {
-                       case Router::DELETE:
-                       case Router::PATCH:
-                       case Router::POST:
-                       case Router::PUT:
-                               self::checkAllowedScope(self::SCOPE_WRITE);
-
-                               if (!$this->app->isLoggedIn()) {
-                                       throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
-                               }
-                               break;
+               if ($scopecheck) {
+                       switch ($this->args->getMethod()) {
+                               case Router::DELETE:
+                               case Router::PATCH:
+                               case Router::POST:
+                               case Router::PUT:
+                                       self::checkAllowedScope(self::SCOPE_WRITE);
+       
+                                       if (!self::getCurrentUserID()) {
+                                               throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
+                                       }
+                                       break;
+                       }       
                }
 
                return parent::run($request);
@@ -269,7 +271,7 @@ class BaseApi extends BaseModule
                        if ($posts_month > $throttle_month) {
                                Logger::info('Monthly posting limit reached', ['uid' => $uid, 'posts' => $posts_month, 'limit' => $throttle_month]);
                                $error = DI::l10n()->t('Too Many Requests');
-                               $error_description = DI::l10n()->t("Monthly posting limit of %d post reached. The post was rejected.", "Monthly posting limit of %d posts reached. The post was rejected.", $throttle_month);
+                               $error_description = DI::l10n()->tt('Monthly posting limit of %d post reached. The post was rejected.', 'Monthly posting limit of %d posts reached. The post was rejected.', $throttle_month);
                                $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
                                System::jsonError(429, $errorobj->toArray());
                        }