Merge remote-tracking branch 'upstream/2023.09-rc' into channel-improvements
This commit is contained in:
commit
fce82deabc
200 changed files with 1215 additions and 1053 deletions
|
|
@ -45,7 +45,7 @@ class Inbox extends BaseApi
|
|||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
$page = $request['page'] ?? null;
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class Outbox extends BaseApi
|
|||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
$postdata = Network::postdata();
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class Whoami extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$owner = User::getOwnerDataById($uid);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class Activity extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Create extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// params
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Delete extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Show extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
$type = $this->getRequestValue($this->parameters, 'extension', 'json');
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Update extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// params
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ class Search extends BaseApi
|
|||
/** @var DirectMessage */
|
||||
private $directMessage;
|
||||
|
||||
public function __construct(DirectMessage $directMessage, Database $dba, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(DirectMessage $directMessage, Database $dba, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->dba = $dba;
|
||||
$this->directMessage = $directMessage;
|
||||
|
|
@ -54,7 +54,7 @@ class Search extends BaseApi
|
|||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class Setseen extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Create extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// params
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Delete extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Index extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Notification extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$Notifies = DI::notify()->selectAllForUser($uid, 50);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Seen extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
if (DI::args()->getArgc() !== 4) {
|
||||
|
|
|
|||
|
|
@ -37,16 +37,16 @@ class Photo extends BaseApi
|
|||
private $friendicaPhoto;
|
||||
|
||||
|
||||
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(FriendicaPhoto $friendicaPhoto, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->friendicaPhoto = $friendicaPhoto;
|
||||
}
|
||||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
$type = $this->getRequestValue($this->parameters, 'extension', 'json');
|
||||
|
||||
|
|
|
|||
|
|
@ -41,16 +41,16 @@ class Create extends BaseApi
|
|||
private $friendicaPhoto;
|
||||
|
||||
|
||||
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(FriendicaPhoto $friendicaPhoto, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->friendicaPhoto = $friendicaPhoto;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
$type = $this->getRequestValue($this->parameters, 'extension', 'json');
|
||||
|
||||
|
|
|
|||
|
|
@ -43,16 +43,16 @@ class Lists extends BaseApi
|
|||
private $friendicaPhoto;
|
||||
|
||||
|
||||
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(FriendicaPhoto $friendicaPhoto, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->friendicaPhoto = $friendicaPhoto;
|
||||
}
|
||||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
$type = $this->getRequestValue($this->parameters, 'extension', 'json');
|
||||
|
||||
|
|
|
|||
|
|
@ -41,16 +41,16 @@ class Update extends BaseApi
|
|||
private $friendicaPhoto;
|
||||
|
||||
|
||||
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(FriendicaPhoto $friendicaPhoto, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->friendicaPhoto = $friendicaPhoto;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
$type = $this->getRequestValue($this->parameters, 'extension', 'json');
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Delete extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Index extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$albums = Photo::getAlbums($uid);
|
||||
|
|
|
|||
|
|
@ -43,16 +43,16 @@ class Show extends BaseApi
|
|||
private $friendicaPhoto;
|
||||
|
||||
|
||||
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(FriendicaPhoto $friendicaPhoto, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->friendicaPhoto = $friendicaPhoto;
|
||||
}
|
||||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
$type = $this->getRequestValue($this->parameters, 'extension', 'json');
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Update extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Show extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
// retrieve general information about profiles for user
|
||||
|
|
|
|||
|
|
@ -35,16 +35,16 @@ class Dislike extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Item::performActivity($item['id'], 'dislike', $uid);
|
||||
|
|
|
|||
|
|
@ -41,12 +41,12 @@ class DislikedBy extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::DISLIKE, 'deleted' => false]);
|
||||
|
|
|
|||
|
|
@ -35,16 +35,16 @@ class Undislike extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Item::performActivity($item['id'], 'undislike', $uid);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Conversation extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// params
|
||||
|
|
|
|||
|
|
@ -40,20 +40,20 @@ class Accounts extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id']) && empty($this->parameters['name'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!empty($this->parameters['id'])) {
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
} else {
|
||||
$contact = Contact::selectFirst(['id'], ['nick' => $this->parameters['name'], 'uid' => 0]);
|
||||
if (!empty($contact['id'])) {
|
||||
$id = $contact['id'];
|
||||
} elseif (!($id = Contact::getIdForURL($this->parameters['name'], 0, false))) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ class Block extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$this->checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Contact\User::setBlocked($this->parameters['id'], $uid, true);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class FeaturedTags extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
|
||||
$this->jsonExit([]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ class Follow extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$this->checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -37,16 +37,16 @@ class Followers extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -37,16 +37,16 @@ class Following extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class IdentityProofs extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
|
||||
$this->jsonExit([]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,16 +37,16 @@ class Lists extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$lists = [];
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ class Mute extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$this->checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Contact\User::setIgnored($this->parameters['id'], $uid, true);
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ class Note extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -47,7 +47,7 @@ class Note extends BaseApi
|
|||
|
||||
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
|
||||
if (empty($cdata['user'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Relationships extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -44,7 +44,7 @@ class Relationships extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($request['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!is_array($request['id'])) {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class Search extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -47,12 +47,12 @@ class Statuses extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ class Unblock extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$this->checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Contact\User::setBlocked($this->parameters['id'], $uid, false);
|
||||
|
|
|
|||
|
|
@ -33,16 +33,16 @@ class Unfollow extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$this->checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
|
||||
if (empty($cdata['user'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$contact = Contact::getById($cdata['user']);
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ class Unmute extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$this->checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Contact\User::setIgnored($this->parameters['id'], $uid, false);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class UpdateCredentials extends BaseApi
|
|||
{
|
||||
protected function patch(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$owner = User::getOwnerDataById($uid);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class VerifyCredentials extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$self = User::getOwnerDataById($uid);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Announcements extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
|
||||
// @todo Possibly use the message from the pageheader addon for this
|
||||
$this->jsonExit([]);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class Apps extends BaseApi
|
|||
}
|
||||
|
||||
if (empty($request['client_name']) || empty($request['redirect_uris'])) {
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Missing parameters'));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters')));
|
||||
}
|
||||
|
||||
$client_id = bin2hex(random_bytes(32));
|
||||
|
|
@ -92,7 +92,7 @@ class Apps extends BaseApi
|
|||
}
|
||||
|
||||
if (!DBA::insert('application', $fields)) {
|
||||
DI::mstdnError()->InternalError();
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray());
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ class VerifyCredentials extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$application = self::getCurrentApplication();
|
||||
|
||||
if (empty($application['id'])) {
|
||||
DI::mstdnError()->Unauthorized();
|
||||
$this->logAndJsonError(401, $this->errorFactory->Unauthorized());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId($application['id']));
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Blocks extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Bookmarks extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/timelines/conversations/
|
||||
|
|
@ -33,11 +34,11 @@ class Conversations extends BaseApi
|
|||
{
|
||||
protected function delete(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (!empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
DBA::delete('conv', ['id' => $this->parameters['id'], 'uid' => $uid]);
|
||||
|
|
@ -51,7 +52,7 @@ class Conversations extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -83,9 +84,13 @@ class Conversations extends BaseApi
|
|||
|
||||
$conversations = [];
|
||||
|
||||
while ($conv = DBA::fetch($convs)) {
|
||||
self::setBoundaries($conv['id']);
|
||||
$conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']);
|
||||
try {
|
||||
while ($conv = DBA::fetch($convs)) {
|
||||
self::setBoundaries($conv['id']);
|
||||
$conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']);
|
||||
}
|
||||
} catch (NotFoundException $e) {
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
DBA::close($convs);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/timelines/conversations/
|
||||
|
|
@ -33,15 +34,19 @@ class Read extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (!empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
DBA::update('mail', ['seen' => true], ['convid' => $this->parameters['id'], 'uid' => $uid]);
|
||||
|
||||
$this->jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray());
|
||||
try {
|
||||
$this->jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray());
|
||||
} catch (NotFoundException $e) {
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Favourited extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Filters extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
$this->response->unsupported(Router::POST, $request);
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ class Filters extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
|
||||
$this->jsonExit([]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class FollowRequests extends BaseApi
|
|||
*/
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$this->checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
|
||||
|
|
@ -89,7 +89,7 @@ class FollowRequests extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class FollowedTags extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ class Instance extends BaseApi
|
|||
/** @var IManageConfigValues */
|
||||
private $config;
|
||||
|
||||
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, Database $database, IManageConfigValues $config, array $server, array $parameters = [])
|
||||
public function __construct(\Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, Database $database, IManageConfigValues $config, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->database = $database;
|
||||
$this->config = $config;
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class InstanceV2 extends BaseApi
|
|||
private $contactHeader;
|
||||
|
||||
public function __construct(
|
||||
\Friendica\Factory\Api\Mastodon\Error $errorFactory,
|
||||
App $app,
|
||||
L10n $l10n,
|
||||
App\BaseURL $baseUrl,
|
||||
|
|
@ -66,7 +67,7 @@ class InstanceV2 extends BaseApi
|
|||
array $server,
|
||||
array $parameters = []
|
||||
) {
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->database = $database;
|
||||
$this->config = $config;
|
||||
|
|
|
|||
|
|
@ -33,19 +33,19 @@ class Lists extends BaseApi
|
|||
{
|
||||
protected function delete(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!Circle::exists($this->parameters['id'], $uid)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if (!Circle::remove($this->parameters['id'])) {
|
||||
DI::mstdnError()->InternalError();
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
|
||||
$this->jsonExit([]);
|
||||
|
|
@ -53,7 +53,7 @@ class Lists extends BaseApi
|
|||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -61,14 +61,14 @@ class Lists extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($request['title'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Circle::create($uid, $request['title']);
|
||||
|
||||
$id = Circle::getIdByName($uid, $request['title']);
|
||||
if (!$id) {
|
||||
DI::mstdnError()->InternalError();
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnList()->createFromCircleId($id));
|
||||
|
|
@ -82,7 +82,7 @@ class Lists extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($request['title']) || empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Circle::update($this->parameters['id'], $request['title']);
|
||||
|
|
@ -93,7 +93,7 @@ class Lists extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
|
|
@ -106,7 +106,7 @@ class Lists extends BaseApi
|
|||
$id = $this->parameters['id'];
|
||||
|
||||
if (!Circle::exists($id, $uid)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
$lists = DI::mstdnList()->createFromCircleId($id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,14 +36,14 @@ class Accounts extends BaseApi
|
|||
{
|
||||
protected function delete(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
$request = $this->getRequest([
|
||||
'account_ids' => [], // Array of account IDs to remove from the list
|
||||
], $request);
|
||||
|
||||
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
return Circle::removeMembers($this->parameters['id'], $request['account_ids']);
|
||||
|
|
@ -51,14 +51,14 @@ class Accounts extends BaseApi
|
|||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
$request = $this->getRequest([
|
||||
'account_ids' => [], // Array of account IDs to add to the list
|
||||
], $request);
|
||||
|
||||
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Circle::addMembers($this->parameters['id'], $request['account_ids']);
|
||||
|
|
@ -69,16 +69,16 @@ class Accounts extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Markers extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
$application = self::getCurrentApplication();
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ class Markers extends BaseApi
|
|||
}
|
||||
|
||||
if (empty($timeline) || empty($last_read_id) || empty($application['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$condition = ['application-id' => $application['id'], 'uid' => $uid, 'timeline' => $timeline];
|
||||
|
|
@ -69,7 +69,7 @@ class Markers extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
$application = self::getCurrentApplication();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Media extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -48,12 +48,12 @@ class Media extends BaseApi
|
|||
Logger::info('Photo post', ['request' => $request, 'files' => $_FILES]);
|
||||
|
||||
if (empty($_FILES['file'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$media = Photo::upload($uid, $_FILES['file'], '', null, null, '', '', $request['description']);
|
||||
if (empty($media)) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Logger::info('Uploaded photo', ['media' => $media]);
|
||||
|
|
@ -63,7 +63,7 @@ class Media extends BaseApi
|
|||
|
||||
public function put(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -74,17 +74,17 @@ class Media extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$photo = Photo::selectFirst(['resource-id'], ['id' => $this->parameters['id'], 'uid' => $uid]);
|
||||
if (empty($photo['resource-id'])) {
|
||||
$media = Post\Media::getById($this->parameters['id']);
|
||||
if (empty($media['uri-id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
if (!Post::exists(['uri-id' => $media['uri-id'], 'uid' => $uid, 'origin' => true])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
Post\Media::updateById(['description' => $request['description']], $this->parameters['id']);
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id']));
|
||||
|
|
@ -100,16 +100,16 @@ class Media extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!Photo::exists(['id' => $id, 'uid' => $uid])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($id));
|
||||
|
|
|
|||
|
|
@ -36,16 +36,16 @@ class Mutes extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Notifications extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (!empty($this->parameters['id'])) {
|
||||
|
|
@ -50,7 +50,7 @@ class Notifications extends BaseApi
|
|||
$notification = DI::notification()->selectOneForUser($uid, ['id' => $id]);
|
||||
$this->jsonExit(DI::mstdnNotification()->createFromNotification($notification, self::appSupportsQuotes()));
|
||||
} catch (\Exception $e) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class Clear extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
DI::notification()->setAllDismissedForUser($uid);
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ class Dismiss extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$condition = ['id' => $this->parameters['id']];
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Polls extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnPoll()->createFromId($this->parameters['id'], $uid));
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Preferences extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$user = User::getById($uid, ['language', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
|
||||
|
|
|
|||
|
|
@ -39,20 +39,17 @@ class PushSubscription extends BaseApi
|
|||
{
|
||||
/** @var SubscriptionFactory */
|
||||
protected $subscriptionFac;
|
||||
/** @var Error */
|
||||
protected $errorFac;
|
||||
|
||||
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, SubscriptionFactory $subscriptionFac, Error $errorFac, array $server, array $parameters = [])
|
||||
public function __construct(\Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, SubscriptionFactory $subscriptionFac, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->subscriptionFac = $subscriptionFac;
|
||||
$this->errorFac = $errorFac;
|
||||
}
|
||||
|
||||
protected function post(array $request = []): void
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_PUSH);
|
||||
$this->checkAllowedScope(self::SCOPE_PUSH);
|
||||
$uid = self::getCurrentUserID();
|
||||
$application = self::getCurrentApplication();
|
||||
|
||||
|
|
@ -86,7 +83,7 @@ class PushSubscription extends BaseApi
|
|||
|
||||
public function put(array $request = []): void
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_PUSH);
|
||||
$this->checkAllowedScope(self::SCOPE_PUSH);
|
||||
$uid = self::getCurrentUserID();
|
||||
$application = self::getCurrentApplication();
|
||||
|
||||
|
|
@ -97,7 +94,7 @@ class PushSubscription extends BaseApi
|
|||
$subscription = Subscription::select($application['id'], $uid, ['id']);
|
||||
if (empty($subscription)) {
|
||||
$this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]);
|
||||
$this->errorFac->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$fields = [
|
||||
|
|
@ -125,7 +122,7 @@ class PushSubscription extends BaseApi
|
|||
|
||||
protected function delete(array $request = []): void
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_PUSH);
|
||||
$this->checkAllowedScope(self::SCOPE_PUSH);
|
||||
$uid = self::getCurrentUserID();
|
||||
$application = self::getCurrentApplication();
|
||||
|
||||
|
|
@ -142,13 +139,13 @@ class PushSubscription extends BaseApi
|
|||
|
||||
protected function rawContent(array $request = []): void
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_PUSH);
|
||||
$this->checkAllowedScope(self::SCOPE_PUSH);
|
||||
$uid = self::getCurrentUserID();
|
||||
$application = self::getCurrentApplication();
|
||||
|
||||
if (!Subscription::exists($application['id'], $uid)) {
|
||||
$this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]);
|
||||
$this->errorFac->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$this->logger->info('Fetch subscription', ['application-id' => $application['id'], 'uid' => $uid]);
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ class Reports extends BaseApi
|
|||
/** @var \Friendica\Moderation\Repository\Report */
|
||||
private $reportRepo;
|
||||
|
||||
public function __construct(\Friendica\Moderation\Repository\Report $reportRepo, \Friendica\Moderation\Factory\Report $reportFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(\Friendica\Moderation\Repository\Report $reportRepo, \Friendica\Moderation\Factory\Report $reportFactory, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->reportFactory = $reportFactory;
|
||||
$this->reportRepo = $reportRepo;
|
||||
|
|
@ -51,7 +51,7 @@ class Reports extends BaseApi
|
|||
|
||||
public function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
$request = $this->getRequest([
|
||||
'account_id' => '', // ID of the account to report
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class ScheduledStatuses extends BaseApi
|
|||
{
|
||||
public function put(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$this->response->unsupported(Router::PUT, $request);
|
||||
|
|
@ -43,15 +43,15 @@ class ScheduledStatuses extends BaseApi
|
|||
|
||||
protected function delete(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!DBA::exists('delayed-post', ['id' => $this->parameters['id'], 'uid' => $uid])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Post\Delayed::deleteById($this->parameters['id']);
|
||||
|
|
@ -64,7 +64,7 @@ class ScheduledStatuses extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (isset($this->parameters['id'])) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class Search extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -60,7 +60,7 @@ class Search extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($request['q'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$limit = min($request['limit'], 40);
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class Statuses extends BaseApi
|
|||
{
|
||||
public function put(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -164,7 +164,7 @@ class Statuses extends BaseApi
|
|||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -297,7 +297,7 @@ class Statuses extends BaseApi
|
|||
$item['uri'] = Item::newURI($item['guid']);
|
||||
$id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, DateTimeFormat::utc($request['scheduled_at']));
|
||||
if (empty($id)) {
|
||||
DI::mstdnError()->InternalError();
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
$this->jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($id, $uid)->toArray());
|
||||
}
|
||||
|
|
@ -310,25 +310,25 @@ class Statuses extends BaseApi
|
|||
}
|
||||
}
|
||||
|
||||
DI::mstdnError()->InternalError();
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
|
||||
protected function delete(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => $uid]);
|
||||
if (empty($item['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if (!Item::markForDeletionById($item['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$this->jsonExit([]);
|
||||
|
|
@ -342,7 +342,7 @@ class Statuses extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), false));
|
||||
|
|
|
|||
|
|
@ -35,20 +35,20 @@ class Bookmark extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['gravity'] != Item::GRAVITY_PARENT) {
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be bookmarked'));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be bookmarked')));
|
||||
}
|
||||
|
||||
if ($item['uid'] == 0) {
|
||||
|
|
@ -56,10 +56,10 @@ class Bookmark extends BaseApi
|
|||
if (!empty($stored)) {
|
||||
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
} else {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Card extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Context extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -116,7 +116,7 @@ class Context extends BaseApi
|
|||
}
|
||||
DBA::close($posts);
|
||||
} else {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,16 +35,16 @@ class Favourite extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Item::performActivity($item['id'], 'like', $uid);
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ class FavouritedBy extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'deleted' => false]);
|
||||
|
|
|
|||
|
|
@ -35,20 +35,20 @@ class Mute extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['gravity'] != Item::GRAVITY_PARENT) {
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be muted'));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be muted')));
|
||||
}
|
||||
|
||||
Post\ThreadUser::setIgnored($item['uri-id'], $uid, true);
|
||||
|
|
|
|||
|
|
@ -34,16 +34,16 @@ class Pin extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], $uid);
|
||||
|
|
|
|||
|
|
@ -38,22 +38,25 @@ class Reblog extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['network'] == Protocol::DIASPORA) {
|
||||
Diaspora::performReshare($this->parameters['id'], $uid);
|
||||
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])));
|
||||
$this->logAndJsonError(
|
||||
422,
|
||||
$this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])))
|
||||
);
|
||||
} else {
|
||||
Item::performActivity($item['id'], 'announce', $uid);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ class RebloggedBy extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]);
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@ class Source extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
|
|
|
|||
|
|
@ -35,20 +35,20 @@ class Unbookmark extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['gravity'] != Item::GRAVITY_PARENT) {
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unbookmarked'));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unbookmarked')));
|
||||
}
|
||||
|
||||
if ($item['uid'] == 0) {
|
||||
|
|
@ -56,10 +56,10 @@ class Unbookmark extends BaseApi
|
|||
if (!empty($stored)) {
|
||||
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
} else {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,16 +35,16 @@ class Unfavourite extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Item::performActivity($item['id'], 'unlike', $uid);
|
||||
|
|
|
|||
|
|
@ -35,20 +35,20 @@ class Unmute extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['gravity'] != Item::GRAVITY_PARENT) {
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unmuted'));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unmuted')));
|
||||
}
|
||||
|
||||
Post\ThreadUser::setIgnored($item['uri-id'], $uid, false);
|
||||
|
|
|
|||
|
|
@ -34,16 +34,16 @@ class Unpin extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, $uid);
|
||||
|
|
|
|||
|
|
@ -37,29 +37,32 @@ class Unreblog extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['network'] == Protocol::DIASPORA) {
|
||||
$item = Post::selectFirstForUser($uid, ['id'], ['quote-uri-id' => $this->parameters['id'], 'body' => '', 'origin' => true, 'uid' => $uid]);
|
||||
if (empty($item['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if (!Item::markForDeletionById($item['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])));
|
||||
$this->logAndJsonError(
|
||||
422,
|
||||
$this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])))
|
||||
);
|
||||
} else {
|
||||
Item::performActivity($item['id'], 'unannounce', $uid);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Suggestions extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@ class Tags extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['hashtag'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$tag = ltrim($this->parameters['hashtag'], '#');
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ class Follow extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['hashtag'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$fields = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ class Unfollow extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['hashtag'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$term = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ use Friendica\Database\DBA;
|
|||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/timelines/
|
||||
|
|
@ -37,7 +38,7 @@ class Direct extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
@ -76,9 +77,13 @@ class Direct extends BaseApi
|
|||
|
||||
$statuses = [];
|
||||
|
||||
while ($mail = DBA::fetch($mails)) {
|
||||
self::setBoundaries($mail['uri-id']);
|
||||
$statuses[] = DI::mstdnStatus()->createFromMailId($mail['id']);
|
||||
try {
|
||||
while ($mail = DBA::fetch($mails)) {
|
||||
self::setBoundaries($mail['uri-id']);
|
||||
$statuses[] = DI::mstdnStatus()->createFromMailId($mail['id']);
|
||||
}
|
||||
} catch (NotFoundException $e) {
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if (!empty($request['min_id'])) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Home extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ class ListTimeline extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ class Tag extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['hashtag'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class UpdateProfile extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$api_user = DI::twitterUser()->createFromUserId($uid, true)->toArray();
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class UpdateProfileImage extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// get mediadata from image or media (Twitter call api/account/update_profile_image provides image)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class VerifyCredentials extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$skip_status = $this->getRequestValue($request, 'skip_status', false);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Ids extends ContactEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// Expected value for user_id parameter: public/user contact id
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Lists extends ContactEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// Expected value for user_id parameter: public/user contact id
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ abstract class ContactEndpoint extends BaseApi
|
|||
const DEFAULT_COUNT = 20;
|
||||
const MAX_COUNT = 200;
|
||||
|
||||
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(\Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class All extends DirectMessagesEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$this->getMessages($request, $uid, []);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class Conversation extends DirectMessagesEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$this->getMessages($request, $uid, ["`parent-uri` = ?", $this->getRequestValue($request, 'uri', '')]);
|
||||
|
|
|
|||
|
|
@ -41,15 +41,15 @@ class Destroy extends BaseApi
|
|||
/** @var Database */
|
||||
private $dba;
|
||||
|
||||
public function __construct(Database $dba, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(Database $dba, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->dba = $dba;
|
||||
}
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$id = $this->getRequestValue($request, 'id', 0);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Inbox extends DirectMessagesEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
$pcid = Contact::getPublicIdByUserId($uid);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ class NewDM extends BaseApi
|
|||
/** @var DirectMessage */
|
||||
private $directMessage;
|
||||
|
||||
public function __construct(DirectMessage $directMessage, Database $dba, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(DirectMessage $directMessage, Database $dba, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->dba = $dba;
|
||||
$this->directMessage = $directMessage;
|
||||
|
|
@ -56,7 +56,7 @@ class NewDM extends BaseApi
|
|||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
if (empty($request['text']) || empty($request['screen_name']) && empty($request['user_id'])) {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Sent extends DirectMessagesEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
$pcid = Contact::getPublicIdByUserId($uid);
|
||||
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ abstract class DirectMessagesEndpoint extends BaseApi
|
|||
/** @var DirectMessage */
|
||||
private $directMessage;
|
||||
|
||||
public function __construct(DirectMessage $directMessage, Database $dba, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(DirectMessage $directMessage, Database $dba, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->dba = $dba;
|
||||
$this->directMessage = $directMessage;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class Favorites extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// in friendica starred item are private
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Create extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$id = $this->getRequestValue($request, 'id', 0);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Destroy extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$id = $this->getRequestValue($request, 'id', 0);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Ids extends ContactEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// Expected value for user_id parameter: public/user contact id
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Lists extends ContactEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// Expected value for user_id parameter: public/user contact id
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Ids extends ContactEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// Expected value for user_id parameter: public/user contact id
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Lists extends ContactEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// Expected value for user_id parameter: public/user contact id
|
||||
|
|
|
|||
|
|
@ -45,16 +45,16 @@ class Destroy extends ContactEndpoint
|
|||
/** @var TwitterUser */
|
||||
private $twitterUser;
|
||||
|
||||
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, TwitterUser $twitterUser, array $server, array $parameters = [])
|
||||
public function __construct(\Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, TwitterUser $twitterUser, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->twitterUser = $twitterUser;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$owner = User::getOwnerDataById($uid);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class Incoming extends ContactEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// Expected value for user_id parameter: public/user contact id
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Show extends ContactEndpoint
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$source_cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'source_screen_name', ''), '', $this->getRequestValue($request, 'source_id', 0), $uid);
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ class Create extends BaseApi
|
|||
/** @var Database */
|
||||
private $dba;
|
||||
|
||||
public function __construct(Database $dba, FriendicaCircle $friendicaCircle, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(Database $dba, FriendicaCircle $friendicaCircle, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->dba = $dba;
|
||||
$this->friendicaCircle = $friendicaCircle;
|
||||
|
|
@ -56,7 +56,7 @@ class Create extends BaseApi
|
|||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// params
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ class Destroy extends BaseApi
|
|||
/** @var Database */
|
||||
private $dba;
|
||||
|
||||
public function __construct(Database $dba, FriendicaCirle $friendicaCircle, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(Database $dba, FriendicaCirle $friendicaCircle, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->dba = $dba;
|
||||
$this->friendicaCircle = $friendicaCircle;
|
||||
|
|
@ -56,7 +56,7 @@ class Destroy extends BaseApi
|
|||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// params
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Lists extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// This is a dummy endpoint
|
||||
|
|
|
|||
|
|
@ -44,16 +44,16 @@ class Ownership extends BaseApi
|
|||
/** @var Database */
|
||||
private $dba;
|
||||
|
||||
public function __construct(Database $dba, FriendicaCircle $friendicaCircle, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(Database $dba, FriendicaCircle $friendicaCircle, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->dba = $dba;
|
||||
$this->friendicaCircle = $friendicaCircle;
|
||||
}
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$circles = $this->dba->select('group', [], ['deleted' => false, 'uid' => $uid, 'cid' => null]);
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@ class Statuses extends BaseApi
|
|||
/** @var Database */
|
||||
private $dba;
|
||||
|
||||
public function __construct(Database $dba, TwitterStatus $twitterStatus, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(Database $dba, TwitterStatus $twitterStatus, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->dba = $dba;
|
||||
$this->twitterStatus = $twitterStatus;
|
||||
|
|
@ -58,7 +58,7 @@ class Statuses extends BaseApi
|
|||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
if (empty($request['list_id'])) {
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ class Update extends BaseApi
|
|||
/** @var Database */
|
||||
private $dba;
|
||||
|
||||
public function __construct(Database $dba, FriendicaCircle $friendicaCircle, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
public function __construct(Database $dba, FriendicaCircle $friendicaCircle, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->dba = $dba;
|
||||
$this->friendicaCircle = $friendicaCircle;
|
||||
|
|
@ -56,7 +56,7 @@ class Update extends BaseApi
|
|||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// params
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Create extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$postdata = Network::postdata();
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Upload extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
if (empty($_FILES['media'])) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class SavedSearches extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$terms = DBA::select('search', ['id', 'term'], ['uid' => $uid]);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class Tweets extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
if (empty($request['q'])) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Destroy extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$id = $this->getRequestValue($request, 'id', 0);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class HomeTimeline extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// get last network messages
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Mentions extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// get last network messages
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class NetworkPublicTimeline extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$count = $this->getRequestValue($request, 'count', 20, 1, 100);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class PublicTimeline extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// get last network messages
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Retweet extends BaseApi
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$id = $this->getRequestValue($request, 'id', 0);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Show extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$id = $this->getRequestValue($request, 'id', 0);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class Update extends BaseApi
|
|||
{
|
||||
public function post(array $request = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$owner = User::getOwnerDataById($uid);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class UserTimeline extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
Logger::info('api_statuses_user_timeline', ['api_user' => $uid, '_REQUEST' => $request]);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Lookup extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$users = [];
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Search extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$userlist = [];
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Show extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ use Friendica\App\Router;
|
|||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
|
|
@ -37,6 +36,7 @@ use Friendica\Model\User;
|
|||
use Friendica\Module\Api\ApiResponse;
|
||||
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Object\Api\Mastodon\Error;
|
||||
use Friendica\Object\Api\Mastodon\Status;
|
||||
use Friendica\Object\Api\Mastodon\TimelineOrderByTypes;
|
||||
use Friendica\Security\BasicAuth;
|
||||
|
|
@ -71,11 +71,15 @@ class BaseApi extends BaseModule
|
|||
/** @var ApiResponse */
|
||||
protected $response;
|
||||
|
||||
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
/** @var \Friendica\Factory\Api\Mastodon\Error */
|
||||
protected $errorFactory;
|
||||
|
||||
public function __construct(\Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->app = $app;
|
||||
$this->app = $app;
|
||||
$this->errorFactory = $errorFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -93,7 +97,7 @@ class BaseApi extends BaseModule
|
|||
case Router::PATCH:
|
||||
case Router::POST:
|
||||
case Router::PUT:
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
if (!self::getCurrentUserID()) {
|
||||
throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
|
||||
|
|
@ -414,23 +418,23 @@ class BaseApi extends BaseModule
|
|||
*
|
||||
* @param string $scope the requested scope (read, write, follow, push)
|
||||
*/
|
||||
public static function checkAllowedScope(string $scope)
|
||||
public function checkAllowedScope(string $scope)
|
||||
{
|
||||
$token = self::getCurrentApplication();
|
||||
|
||||
if (empty($token)) {
|
||||
Logger::notice('Empty application token');
|
||||
DI::mstdnError()->Forbidden();
|
||||
$this->logger->notice('Empty application token');
|
||||
$this->logAndJsonError(403, $this->errorFactory->Forbidden());
|
||||
}
|
||||
|
||||
if (!isset($token[$scope])) {
|
||||
Logger::warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]);
|
||||
DI::mstdnError()->Forbidden();
|
||||
$this->logger->warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]);
|
||||
$this->logAndJsonError(403, $this->errorFactory->Forbidden());
|
||||
}
|
||||
|
||||
if (empty($token[$scope])) {
|
||||
Logger::warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]);
|
||||
DI::mstdnError()->Forbidden();
|
||||
$this->logger->warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]);
|
||||
$this->logAndJsonError(403, $this->errorFactory->Forbidden());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -515,4 +519,16 @@ class BaseApi extends BaseModule
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $errorno
|
||||
* @param Error $error
|
||||
* @return void
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
protected function logAndJsonError(int $errorno, Error $error)
|
||||
{
|
||||
$this->logger->info('API Error', ['no' => $errorno, 'error' => $error->toArray(), 'method' => $this->args->getMethod(), 'command' => $this->args->getQueryString(), 'user-agent' => $this->server['HTTP_USER_AGENT'] ?? '']);
|
||||
$this->jsonError(403, $error->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,17 +23,15 @@ namespace Friendica\Module\Contact;
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Content\Widget;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Profiler;
|
||||
use Friendica\Util\Strings;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -88,35 +86,6 @@ class Hovercard extends BaseModule
|
|||
throw new HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
// Get the photo_menu - the menu if possible contact actions
|
||||
if ($this->userSession->isAuthenticated()) {
|
||||
$actions = Contact::photoMenu($contact, $this->userSession->getLocalUserId());
|
||||
} else {
|
||||
$actions = [];
|
||||
}
|
||||
|
||||
// Move the contact data to the profile array so we can deliver it to
|
||||
$tpl = Renderer::getMarkupTemplate('hovercard.tpl');
|
||||
$o = Renderer::replaceMacros($tpl, [
|
||||
'$profile' => [
|
||||
'name' => $contact['name'],
|
||||
'nick' => $contact['nick'],
|
||||
'addr' => $contact['addr'] ?: $contact['url'],
|
||||
'thumb' => Contact::getThumb($contact),
|
||||
'url' => Contact::magicLinkByContact($contact),
|
||||
'nurl' => $contact['nurl'],
|
||||
'location' => $contact['location'],
|
||||
'about' => $contact['about'],
|
||||
'network_link' => Strings::formatNetworkName($contact['network'], $contact['url']),
|
||||
'tags' => $contact['keywords'],
|
||||
'bd' => $contact['bd'] <= DBA::NULL_DATE ? '' : $contact['bd'],
|
||||
'account_type' => Contact::getAccountType($contact['contact-type']),
|
||||
'contact_type' => $contact['contact-type'],
|
||||
'actions' => $actions,
|
||||
'self' => $contact['self'],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->httpExit($o);
|
||||
$this->httpExit(Widget\Hovercard::getHTML($contact, $this->userSession->getLocalUserId()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,152 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Notification;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\HTTPException\ForbiddenException;
|
||||
use Friendica\Util\Proxy;
|
||||
|
||||
/**
|
||||
* Switches current user between delegates/parent user
|
||||
*/
|
||||
class Delegation extends BaseModule
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uid = DI::userSession()->getLocalUserId();
|
||||
$orig_record = User::getById(DI::app()->getLoggedInUserId());
|
||||
|
||||
if (DI::userSession()->getSubManagedUserId()) {
|
||||
$user = User::getById(DI::userSession()->getSubManagedUserId());
|
||||
if (DBA::isResult($user)) {
|
||||
$uid = intval($user['uid']);
|
||||
$orig_record = $user;
|
||||
}
|
||||
}
|
||||
|
||||
$identity = intval($request['identity'] ?? 0);
|
||||
if (!$identity) {
|
||||
return;
|
||||
}
|
||||
|
||||
$limited_id = 0;
|
||||
$original_id = $uid;
|
||||
|
||||
$manages = DBA::selectToArray('manage', ['mid'], ['uid' => $uid]);
|
||||
foreach ($manages as $manage) {
|
||||
if ($identity == $manage['mid']) {
|
||||
$limited_id = $manage['mid'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($limited_id) {
|
||||
$user = User::getById($limited_id);
|
||||
} else {
|
||||
// Check if the target user is one of our children
|
||||
$user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['uid']]);
|
||||
|
||||
// Check if the target user is one of our siblings
|
||||
if (!DBA::isResult($user) && $orig_record['parent-uid']) {
|
||||
$user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['parent-uid']]);
|
||||
}
|
||||
|
||||
// Check if it's our parent or our own user
|
||||
if (!DBA::isResult($user)
|
||||
&& (
|
||||
$orig_record['parent-uid'] && $orig_record['parent-uid'] === $identity
|
||||
||
|
||||
$orig_record['uid'] && $orig_record['uid'] === $identity
|
||||
)
|
||||
) {
|
||||
$user = User::getById($identity);
|
||||
}
|
||||
}
|
||||
|
||||
if (!DBA::isResult($user)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DI::session()->clear();
|
||||
|
||||
DI::auth()->setForUser(DI::app(), $user, true, true);
|
||||
|
||||
if ($limited_id) {
|
||||
DI::userSession()->setSubManagedUserId($original_id);
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
Hook::callAll('home_init', $ret);
|
||||
|
||||
DI::sysmsg()->addNotice($this->t('You are now logged in as %s', $user['username']));
|
||||
|
||||
DI::baseUrl()->redirect('network');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$identities = User::identities(DI::userSession()->getSubManagedUserId() ?: DI::userSession()->getLocalUserId());
|
||||
|
||||
//getting additional information for each identity
|
||||
foreach ($identities as $key => $identity) {
|
||||
$identities[$key]['thumb'] = User::getAvatarUrl($identity, Proxy::SIZE_THUMB);
|
||||
|
||||
$identities[$key]['selected'] = ($identity['nickname'] === DI::app()->getLoggedInUserNickname());
|
||||
|
||||
$condition = ["`msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", Notification\Type::INTRO, Notification\Type::MAIL];
|
||||
$params = ['distinct' => true, 'expression' => 'parent'];
|
||||
$notifications = DI::notify()->countForUser($identity['uid'], $condition, $params);
|
||||
|
||||
$params = ['distinct' => true, 'expression' => 'convid'];
|
||||
$notifications += DBA::count('mail', ['uid' => $identity['uid'], 'seen' => false], $params);
|
||||
|
||||
$notifications += DI::intro()->countActiveForUser($identity['uid']);
|
||||
|
||||
$identities[$key]['notifications'] = $notifications;
|
||||
}
|
||||
|
||||
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('delegation.tpl'), [
|
||||
'$title' => DI::l10n()->t('Switch between your accounts'),
|
||||
'$settings_label' => DI::l10n()->t('Manage your accounts'),
|
||||
'$desc' => DI::l10n()->t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
|
||||
'$choose' => DI::l10n()->t('Select an identity to manage: '),
|
||||
'$identities' => $identities,
|
||||
'$submit' => DI::l10n()->t('Submit'),
|
||||
]);
|
||||
|
||||
return $o;
|
||||
}
|
||||
}
|
||||
|
|
@ -51,17 +51,17 @@ class Authorize extends BaseApi
|
|||
|
||||
if ($request['response_type'] != 'code') {
|
||||
Logger::warning('Unsupported or missing response type', ['request' => $_REQUEST]);
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Unsupported or missing response type'));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing response type')));
|
||||
}
|
||||
|
||||
if (empty($request['client_id']) || empty($request['redirect_uri'])) {
|
||||
Logger::warning('Incomplete request data', ['request' => $_REQUEST]);
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Incomplete request data'));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data')));
|
||||
}
|
||||
|
||||
$application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']);
|
||||
if (empty($application)) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
// @todo Compare the application scope and requested scope
|
||||
|
|
@ -87,7 +87,7 @@ class Authorize extends BaseApi
|
|||
|
||||
$token = OAuth::createTokenForUser($application, $uid, $request['scope']);
|
||||
if (!$token) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if ($application['redirect_uri'] != 'urn:ietf:wg:oauth:2.0:oob') {
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ class Revoke extends BaseApi
|
|||
$condition = ['client_id' => $request['client_id'], 'client_secret' => $request['client_secret'], 'access_token' => $request['token']];
|
||||
$token = DBA::selectFirst('application-view', ['id'], $condition);
|
||||
if (empty($token['id'])) {
|
||||
Logger::notice('Token not found', $condition);
|
||||
DI::mstdnError()->Unauthorized();
|
||||
$this->logger->notice('Token not found', $condition);
|
||||
$this->logAndJsonError(401, $this->errorFactory->Unauthorized());
|
||||
}
|
||||
|
||||
DBA::delete('application-token', ['application-id' => $token['id']]);
|
||||
|
|
|
|||
|
|
@ -74,13 +74,13 @@ class Token extends BaseApi
|
|||
}
|
||||
|
||||
if (empty($request['client_id']) || empty($request['client_secret'])) {
|
||||
Logger::warning('Incomplete request data', ['request' => $request]);
|
||||
DI::mstdnError()->Unauthorized('invalid_client', DI::l10n()->t('Incomplete request data'));
|
||||
$this->logger->warning('Incomplete request data', ['request' => $request]);
|
||||
$this->logAndJsonError(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Incomplete request data')));;
|
||||
}
|
||||
|
||||
$application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']);
|
||||
if (empty($application)) {
|
||||
DI::mstdnError()->Unauthorized('invalid_client', DI::l10n()->t('Invalid data or unknown client'));
|
||||
$this->logAndJsonError(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Invalid data or unknown client')));
|
||||
}
|
||||
|
||||
if ($request['grant_type'] == 'client_credentials') {
|
||||
|
|
@ -98,14 +98,14 @@ class Token extends BaseApi
|
|||
|
||||
$token = DBA::selectFirst('application-view', ['access_token', 'created_at', 'uid'], $condition);
|
||||
if (!DBA::isResult($token)) {
|
||||
Logger::notice('Token not found or outdated', $condition);
|
||||
DI::mstdnError()->Unauthorized();
|
||||
$this->logger->notice('Token not found or outdated', $condition);
|
||||
$this->logAndJsonError(401, $this->errorFactory->Unauthorized());
|
||||
}
|
||||
$owner = User::getOwnerDataById($token['uid']);
|
||||
$me = $owner['url'];
|
||||
} else {
|
||||
Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]);
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Unsupported or missing grant type'));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing grant type')));
|
||||
}
|
||||
|
||||
$object = new \Friendica\Object\Api\Mastodon\Token($token['access_token'], 'Bearer', $application['scopes'], $token['created_at'], $me);
|
||||
|
|
|
|||
|
|
@ -21,29 +21,48 @@
|
|||
|
||||
namespace Friendica\Module\Settings;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseSettings;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Profiler;
|
||||
use Friendica\Util\Strings;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Account delegation settings module
|
||||
*/
|
||||
class Delegation extends BaseSettings
|
||||
{
|
||||
/** @var SystemMessages */
|
||||
private $systemMessages;
|
||||
/** @var Database */
|
||||
private $db;
|
||||
|
||||
public function __construct(Database $db, SystemMessages $systemMessages, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!DI::app()->isLoggedIn()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
if (!$this->session->isAuthenticated()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BaseModule::checkFormSecurityTokenRedirectOnError('settings/delegation', 'delegate');
|
||||
|
||||
$parent_uid = $request['parent_user'] ?? null;
|
||||
$parent_uid = $request['parent_user'] ?? null;
|
||||
$parent_password = $request['parent_password'] ?? '';
|
||||
|
||||
if ($parent_uid) {
|
||||
|
|
@ -51,66 +70,63 @@ class Delegation extends BaseSettings
|
|||
// An integer value will trigger the direct user query on uid in User::getAuthenticationInfo
|
||||
$parent_uid = (int)$parent_uid;
|
||||
User::getIdFromPasswordAuthentication($parent_uid, $parent_password);
|
||||
DI::sysmsg()->addInfo(DI::l10n()->t('Delegation successfully granted.'));
|
||||
$this->systemMessages->addInfo($this->t('Delegation successfully granted.'));
|
||||
} catch (\Exception $ex) {
|
||||
DI::sysmsg()->addNotice(DI::l10n()->t('Parent user not found, unavailable or password doesn\'t match.'));
|
||||
$this->systemMessages->addNotice($this->t('Parent user not found, unavailable or password doesn\'t match.'));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
DI::sysmsg()->addInfo(DI::l10n()->t('Delegation successfully revoked.'));
|
||||
$this->systemMessages->addInfo($this->t('Delegation successfully revoked.'));
|
||||
}
|
||||
|
||||
DBA::update('user', ['parent-uid' => $parent_uid], ['uid' => DI::userSession()->getLocalUserId()]);
|
||||
$this->db->update('user', ['parent-uid' => $parent_uid], ['uid' => $this->session->getLocalUserId()]);
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
if (!$this->session->isAuthenticated()) {
|
||||
throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$args = DI::args();
|
||||
|
||||
// @TODO Replace with router-provided arguments
|
||||
$action = $args->get(2);
|
||||
$user_id = $args->get(3);
|
||||
$action = $this->parameters['action'] ?? '';
|
||||
$user_id = $this->parameters['user_id'] ?? 0;
|
||||
|
||||
if ($action === 'add' && $user_id) {
|
||||
if (DI::userSession()->getSubManagedUserId()) {
|
||||
DI::sysmsg()->addNotice(DI::l10n()->t('Delegated administrators can view but not change delegation permissions.'));
|
||||
DI::baseUrl()->redirect('settings/delegation');
|
||||
if ($this->session->getSubManagedUserId()) {
|
||||
$this->systemMessages->addNotice($this->t('Delegated administrators can view but not change delegation permissions.'));
|
||||
$this->baseUrl->redirect('settings/delegation');
|
||||
}
|
||||
|
||||
$user = User::getById($user_id, ['nickname']);
|
||||
if (DBA::isResult($user)) {
|
||||
if ($this->db->isResult($user)) {
|
||||
$condition = [
|
||||
'uid' => DI::userSession()->getLocalUserId(),
|
||||
'nurl' => Strings::normaliseLink(DI::baseUrl() . '/profile/' . $user['nickname'])
|
||||
'uid' => $this->session->getLocalUserId(),
|
||||
'nurl' => Strings::normaliseLink($this->baseUrl . '/profile/' . $user['nickname'])
|
||||
];
|
||||
if (DBA::exists('contact', $condition)) {
|
||||
DBA::insert('manage', ['uid' => $user_id, 'mid' => DI::userSession()->getLocalUserId()]);
|
||||
if ($this->db->exists('contact', $condition)) {
|
||||
$this->db->insert('manage', ['uid' => $user_id, 'mid' => $this->session->getLocalUserId()]);
|
||||
}
|
||||
} else {
|
||||
DI::sysmsg()->addNotice(DI::l10n()->t('Delegate user not found.'));
|
||||
$this->systemMessages->addNotice($this->t('Delegate user not found.'));
|
||||
}
|
||||
|
||||
DI::baseUrl()->redirect('settings/delegation');
|
||||
$this->baseUrl->redirect('settings/delegation');
|
||||
}
|
||||
|
||||
if ($action === 'remove' && $user_id) {
|
||||
if (DI::userSession()->getSubManagedUserId()) {
|
||||
DI::sysmsg()->addNotice(DI::l10n()->t('Delegated administrators can view but not change delegation permissions.'));
|
||||
DI::baseUrl()->redirect('settings/delegation');
|
||||
if ($this->session->getSubManagedUserId()) {
|
||||
$this->systemMessages->addNotice($this->t('Delegated administrators can view but not change delegation permissions.'));
|
||||
$this->baseUrl->redirect('settings/delegation');
|
||||
}
|
||||
|
||||
DBA::delete('manage', ['uid' => $user_id, 'mid' => DI::userSession()->getLocalUserId()]);
|
||||
DI::baseUrl()->redirect('settings/delegation');
|
||||
$this->db->delete('manage', ['uid' => $user_id, 'mid' => $this->session->getLocalUserId()]);
|
||||
$this->baseUrl->redirect('settings/delegation');
|
||||
}
|
||||
|
||||
// find everybody that currently has delegated management to this account/page
|
||||
$delegates = DBA::selectToArray('user', [], ['`uid` IN (SELECT `uid` FROM `manage` WHERE `mid` = ?)', DI::userSession()->getLocalUserId()]);
|
||||
$delegates = $this->db->selectToArray('user', [], ['`uid` IN (SELECT `uid` FROM `manage` WHERE `mid` = ?)', $this->session->getLocalUserId()]);
|
||||
|
||||
$uids = [];
|
||||
foreach ($delegates as $user) {
|
||||
|
|
@ -119,69 +135,76 @@ class Delegation extends BaseSettings
|
|||
|
||||
// find every contact who might be a candidate for delegation
|
||||
$potentials = [];
|
||||
$nicknames = [];
|
||||
$nicknames = [];
|
||||
|
||||
$condition = ['baseurl' => DI::baseUrl(), 'self' => false, 'uid' => DI::userSession()->getLocalUserId(), 'blocked' => false];
|
||||
$contacts = DBA::select('contact', ['nick'], $condition);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
$condition = ['baseurl' => $this->baseUrl, 'self' => false, 'uid' => $this->session->getLocalUserId(), 'blocked' => false];
|
||||
$contacts = $this->db->select('contact', ['nick'], $condition);
|
||||
while ($contact = $this->db->fetch($contacts)) {
|
||||
$nicknames[] = $contact['nick'];
|
||||
}
|
||||
DBA::close($contacts);
|
||||
$this->db->close($contacts);
|
||||
|
||||
// get user records for all potential page delegates who are not already delegates or managers
|
||||
$potentialDelegateUsers = DBA::selectToArray('user', ['uid', 'username', 'nickname'], ['nickname' => $nicknames]);
|
||||
$potentialDelegateUsers = $this->db->selectToArray(
|
||||
'user',
|
||||
['uid', 'username', 'nickname'],
|
||||
[
|
||||
'nickname' => $nicknames,
|
||||
'account_removed' => false,
|
||||
'account_expired' => false,
|
||||
'blocked' => false,
|
||||
]
|
||||
);
|
||||
foreach ($potentialDelegateUsers as $user) {
|
||||
if (!in_array($user['uid'], $uids)) {
|
||||
$potentials[] = $user;
|
||||
}
|
||||
}
|
||||
|
||||
$parent_user = null;
|
||||
$parent_user = null;
|
||||
$parent_password = null;
|
||||
$user = User::getById(DI::userSession()->getLocalUserId(), ['parent-uid', 'email']);
|
||||
if (DBA::isResult($user) && !DBA::exists('user', ['parent-uid' => DI::userSession()->getLocalUserId()])) {
|
||||
$user = User::getById($this->session->getLocalUserId(), ['parent-uid', 'email']);
|
||||
if ($this->db->isResult($user) && !$this->db->exists('user', ['parent-uid' => $this->session->getLocalUserId()])) {
|
||||
$parent_uid = $user['parent-uid'];
|
||||
$parents = [0 => DI::l10n()->t('No parent user')];
|
||||
$parents = [0 => $this->t('No parent user')];
|
||||
|
||||
$fields = ['uid', 'username', 'nickname'];
|
||||
$condition = ['email' => $user['email'], 'verified' => true, 'blocked' => false, 'parent-uid' => null];
|
||||
$parent_users = DBA::selectToArray('user', $fields, $condition);
|
||||
foreach($parent_users as $parent) {
|
||||
if ($parent['uid'] != DI::userSession()->getLocalUserId()) {
|
||||
$fields = ['uid', 'username', 'nickname'];
|
||||
$condition = ['email' => $user['email'], 'verified' => true, 'blocked' => false, 'parent-uid' => null];
|
||||
$parent_users = $this->db->selectToArray('user', $fields, $condition);
|
||||
foreach ($parent_users as $parent) {
|
||||
if ($parent['uid'] != $this->session->getLocalUserId()) {
|
||||
$parents[$parent['uid']] = sprintf('%s (%s)', $parent['username'], $parent['nickname']);
|
||||
}
|
||||
}
|
||||
|
||||
$parent_user = ['parent_user', DI::l10n()->t('Parent User'), $parent_uid, '', $parents];
|
||||
$parent_password = ['parent_password', DI::l10n()->t('Parent Password:'), '', DI::l10n()->t('Please enter the password of the parent account to legitimize your request.')];
|
||||
$parent_user = ['parent_user', $this->t('Parent User'), $parent_uid, '', $parents];
|
||||
$parent_password = ['parent_password', $this->t('Parent Password:'), '', $this->t('Please enter the password of the parent account to legitimize your request.')];
|
||||
}
|
||||
|
||||
$is_child_user = !empty($user['parent-uid']);
|
||||
|
||||
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/delegation.tpl'), [
|
||||
'$form_security_token' => BaseModule::getFormSecurityToken('delegate'),
|
||||
'$account_header' => DI::l10n()->t('Additional Accounts'),
|
||||
'$account_desc' => DI::l10n()->t('Register additional accounts that are automatically connected to your existing account so you can manage them from this account.'),
|
||||
'$add_account' => DI::l10n()->t('Register an additional account'),
|
||||
'$parent_header' => DI::l10n()->t('Parent User'),
|
||||
'$parent_user' => $parent_user,
|
||||
'$parent_password' => $parent_password,
|
||||
'$parent_desc' => DI::l10n()->t('Parent users have total control about this account, including the account settings. Please double check whom you give this access.'),
|
||||
'$is_child_user' => $is_child_user,
|
||||
'$submit' => DI::l10n()->t('Save Settings'),
|
||||
'$header' => DI::l10n()->t('Manage Accounts'),
|
||||
'$delegates_header' => DI::l10n()->t('Delegates'),
|
||||
'$base' => DI::baseUrl(),
|
||||
'$desc' => DI::l10n()->t('Delegates are able to manage all aspects of this account/page except for basic account settings. Please do not delegate your personal account to anybody that you do not trust completely.'),
|
||||
'$head_delegates' => DI::l10n()->t('Existing Page Delegates'),
|
||||
'$delegates' => $delegates,
|
||||
'$head_potentials' => DI::l10n()->t('Potential Delegates'),
|
||||
'$potentials' => $potentials,
|
||||
'$remove' => DI::l10n()->t('Remove'),
|
||||
'$add' => DI::l10n()->t('Add'),
|
||||
'$none' => DI::l10n()->t('No entries.')
|
||||
]);
|
||||
return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/delegation.tpl'), [
|
||||
'$l10n' => [
|
||||
'account_header' => $this->t('Additional Accounts'),
|
||||
'account_desc' => $this->t('Register additional accounts that are automatically connected to your existing account so you can manage them from this account.'),
|
||||
'add_account' => $this->t('Register an additional account'),
|
||||
'parent_header' => $this->t('Parent User'),
|
||||
'parent_desc' => $this->t('Parent users have total control about this account, including the account settings. Please double check whom you give this access.'),
|
||||
'submit' => $this->t('Save Settings'),
|
||||
'header' => $this->t('Manage Accounts'),
|
||||
'delegates_header' => $this->t('Delegates'),
|
||||
'desc' => $this->t('Delegates are able to manage all aspects of this account/page except for basic account settings. Please do not delegate your personal account to anybody that you do not trust completely.'),
|
||||
'head_delegates' => $this->t('Existing Page Delegates'),
|
||||
'head_potentials' => $this->t('Potential Delegates'),
|
||||
'none' => $this->t('No entries.'),
|
||||
],
|
||||
|
||||
return $o;
|
||||
'$form_security_token' => BaseModule::getFormSecurityToken('delegate'),
|
||||
'$parent_user' => $parent_user,
|
||||
'$parent_password' => $parent_password,
|
||||
'$is_child_user' => $is_child_user,
|
||||
'$delegates' => $delegates,
|
||||
'$potentials' => $potentials,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,10 @@
|
|||
namespace Friendica\Module\Settings;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Content\Widget;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Model\User\Cookie;
|
||||
|
|
@ -40,10 +39,6 @@ use Psr\Log\LoggerInterface;
|
|||
|
||||
class RemoveMe extends BaseSettings
|
||||
{
|
||||
/** @var IManageConfigValues */
|
||||
private $config;
|
||||
/** @var Database */
|
||||
private $database;
|
||||
/** @var Emailer */
|
||||
private $emailer;
|
||||
/** @var SystemMessages */
|
||||
|
|
@ -51,12 +46,10 @@ class RemoveMe extends BaseSettings
|
|||
/** @var Cookie */
|
||||
private $cookie;
|
||||
|
||||
public function __construct(Cookie $cookie, SystemMessages $systemMessages, Emailer $emailer, Database $database, IManageConfigValues $config, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
public function __construct(Cookie $cookie, SystemMessages $systemMessages, Emailer $emailer, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->config = $config;
|
||||
$this->database = $database;
|
||||
$this->emailer = $emailer;
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->cookie = $cookie;
|
||||
|
|
@ -79,6 +72,9 @@ class RemoveMe extends BaseSettings
|
|||
|
||||
try {
|
||||
$userId = User::getIdFromPasswordAuthentication($this->session->getLocalUserId(), trim($request[$hash]));
|
||||
if ($userId != $this->session->getLocalUserId()) {
|
||||
throw new \RuntimeException($this->t("There was a validation error, please make sure you're logged in with the account you want to remove and try again.") . ' ' . $this->t('If this error persists, please contact your administrator.'));
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$this->systemMessages->addNotice($e->getMessage());
|
||||
return;
|
||||
|
|
@ -100,13 +96,19 @@ class RemoveMe extends BaseSettings
|
|||
$this->emailer->send($email);
|
||||
}
|
||||
|
||||
User::remove($userId);
|
||||
try {
|
||||
User::remove($userId);
|
||||
|
||||
$this->session->clear();
|
||||
$this->cookie->clear();
|
||||
$this->session->clear();
|
||||
$this->cookie->clear();
|
||||
|
||||
$this->systemMessages->addInfo($this->t('Your user account has been successfully removed. Bye bye!'));
|
||||
$this->baseUrl->redirect();
|
||||
$this->systemMessages->addInfo($this->t('Your account has been successfully removed. Bye bye!'));
|
||||
$this->baseUrl->redirect();
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->systemMessages->addNotice($e->getMessage());
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
|
|
@ -128,6 +130,9 @@ class RemoveMe extends BaseSettings
|
|||
'title' => DI::l10n()->t('Remove My Account'),
|
||||
'desc' => DI::l10n()->t('This will completely remove your account. Once this has been done it is not recoverable.'),
|
||||
],
|
||||
|
||||
'$hovercard' => Widget\Hovercard::getHTML(User::getOwnerDataById($this->session->getLocalUserId())),
|
||||
|
||||
'$password' => [$hash, $this->t('Please enter your password for verification:'), null, null, true],
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
195
src/Module/User/Delegation.php
Normal file
195
src/Module/User/Delegation.php
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\User;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Contact\Introduction\Repository\Introduction;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Notification;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\Notifications\Repository\Notify;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Network\HTTPException\ForbiddenException;
|
||||
use Friendica\Security\Authentication;
|
||||
use Friendica\Util;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Switches current user between delegates/parent user
|
||||
*/
|
||||
class Delegation extends BaseModule
|
||||
{
|
||||
/** @var IHandleUserSessions */
|
||||
private $session;
|
||||
/** @var Database */
|
||||
private $db;
|
||||
/** @var Authentication */
|
||||
private $auth;
|
||||
/** @var SystemMessages */
|
||||
private $systemMessages;
|
||||
/** @var Notify */
|
||||
private $notify;
|
||||
/** @var Introduction */
|
||||
private $intro;
|
||||
/** @var App */
|
||||
private $app;
|
||||
|
||||
public function __construct(App $app, Introduction $intro, Notify $notify, SystemMessages $systemMessages, Authentication $auth, Database $db, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->session = $session;
|
||||
$this->db = $db;
|
||||
$this->auth = $auth;
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->notify = $notify;
|
||||
$this->intro = $intro;
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!$this->session->getLocalUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uid = $this->session->getLocalUserId();
|
||||
$orig_record = User::getById($this->session->getLocalUserId());
|
||||
|
||||
if ($this->session->getSubManagedUserId()) {
|
||||
$user = User::getById($this->session->getSubManagedUserId());
|
||||
if ($this->db->isResult($user)) {
|
||||
$uid = intval($user['uid']);
|
||||
$orig_record = $user;
|
||||
}
|
||||
}
|
||||
|
||||
$identity = intval($request['identity'] ?? 0);
|
||||
if (!$identity) {
|
||||
return;
|
||||
}
|
||||
|
||||
$limited_id = 0;
|
||||
$original_id = $uid;
|
||||
|
||||
$manages = $this->db->selectToArray('manage', ['mid'], ['uid' => $uid]);
|
||||
foreach ($manages as $manage) {
|
||||
if ($identity == $manage['mid']) {
|
||||
$limited_id = $manage['mid'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($limited_id) {
|
||||
$user = User::getById($limited_id);
|
||||
} else {
|
||||
// Check if the target user is one of our children
|
||||
$user = $this->db->selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['uid']]);
|
||||
|
||||
// Check if the target user is one of our siblings
|
||||
if (!$this->db->isResult($user) && $orig_record['parent-uid']) {
|
||||
$user = $this->db->selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['parent-uid']]);
|
||||
}
|
||||
|
||||
// Check if it's our parent or our own user
|
||||
if (!$this->db->isResult($user)
|
||||
&& (
|
||||
$orig_record['parent-uid'] && $orig_record['parent-uid'] === $identity
|
||||
||
|
||||
$orig_record['uid'] && $orig_record['uid'] === $identity
|
||||
)
|
||||
) {
|
||||
$user = User::getById($identity);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->db->isResult($user)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->session->clear();
|
||||
|
||||
$this->auth->setForUser($this->app, $user, true, true);
|
||||
|
||||
if ($limited_id) {
|
||||
$this->session->setSubManagedUserId($original_id);
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
Hook::callAll('home_init', $ret);
|
||||
|
||||
$this->systemMessages->addNotice($this->t('You are now logged in as %s', $user['username']));
|
||||
|
||||
$this->baseUrl->redirect('network');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!$this->session->getLocalUserId()) {
|
||||
throw new ForbiddenException($this->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$identities = User::identities($this->session->getSubManagedUserId() ?: $this->session->getLocalUserId());
|
||||
|
||||
//getting additional information for each identity
|
||||
foreach ($identities as $key => $identity) {
|
||||
$identities[$key]['thumb'] = User::getAvatarUrl($identity, Util\Proxy::SIZE_THUMB);
|
||||
|
||||
$identities[$key]['selected'] = ($identity['nickname'] === $this->session->getLocalUserNickname());
|
||||
|
||||
$notifications = $this->notify->countForUser(
|
||||
$identity['uid'],
|
||||
["`msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", Notification\Type::INTRO, Notification\Type::MAIL],
|
||||
['distinct' => true, 'expression' => 'parent']
|
||||
);
|
||||
|
||||
$notifications += $this->db->count(
|
||||
'mail',
|
||||
['uid' => $identity['uid'], 'seen' => false],
|
||||
['distinct' => true, 'expression' => 'convid']
|
||||
);
|
||||
|
||||
$notifications += $this->intro->countActiveForUser($identity['uid']);
|
||||
|
||||
$identities[$key]['notifications'] = $notifications;
|
||||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('delegation.tpl');
|
||||
return Renderer::replaceMacros($tpl, [
|
||||
'$l10n' => [
|
||||
'title' => $this->t('Switch between your accounts'),
|
||||
'settings_label' => $this->t('Manage your accounts'),
|
||||
'desc' => $this->t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
|
||||
'choose' => $this->t('Select an identity to manage: '),
|
||||
'submit' => $this->t('Submit'),
|
||||
],
|
||||
|
||||
'$identities' => $identities,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue