namespace Friendica\Module;
use Friendica\App;
+use Friendica\App\Router;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Security\OAuth;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler;
+use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
class BaseApi extends BaseModule
$this->app = $app;
}
- protected function delete(array $request = [])
- {
- self::checkAllowedScope(self::SCOPE_WRITE);
-
- if (!$this->app->isLoggedIn()) {
- throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
- }
- }
-
- protected function patch(array $request = [])
- {
- self::checkAllowedScope(self::SCOPE_WRITE);
-
- if (!$this->app->isLoggedIn()) {
- throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
- }
- }
-
- protected function post(array $request = [])
+ /**
+ * Additionally checks, if the caller is permitted to do this action
+ *
+ * {@inheritDoc}
+ *
+ * @throws HTTPException\ForbiddenException
+ */
+ public function run(array $request = [], bool $scopecheck = true): ResponseInterface
{
- self::checkAllowedScope(self::SCOPE_WRITE);
-
- if (!$this->app->isLoggedIn()) {
- throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
+ if ($scopecheck) {
+ 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 (!self::getCurrentUserID()) {
+ throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
+ }
+ break;
+ }
}
- }
-
- public function put(array $request = [])
- {
- self::checkAllowedScope(self::SCOPE_WRITE);
- if (!$this->app->isLoggedIn()) {
- throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
- }
+ return parent::run($request);
}
/**