From e911302fe94b45fe76a1c27d00d6a24a010f5e0e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 1 Apr 2019 03:15:41 -0400 Subject: [PATCH 1/4] Add tombstone object for AP response on deleted profile - Responds with 404 status code with all other non-success cases --- src/Module/Profile.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Module/Profile.php b/src/Module/Profile.php index e43554a1ce..a9a1fe6d09 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -54,15 +54,28 @@ class Profile extends BaseModule { if (ActivityPub::isRequest()) { $user = DBA::selectFirst('user', ['uid'], ['nickname' => self::$which]); + $data = []; if (DBA::isResult($user)) { $data = ActivityPub\Transmitter::getProfile($user['uid']); + } + + if (!empty($data)) { System::jsonExit($data, 'application/activity+json'); } elseif (DBA::exists('userd', ['username' => self::$which])) { // Known deleted user - System::httpExit(410); + $data = [ + '@context' => ActivityPub::CONTEXT, + 'id' => System::baseUrl() . '/profile/' . self::$which, + 'type' => 'Tombstone', + 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), + 'updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), + 'deleted' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), + ]; + + System::jsonError(410, $data); } else { - // Unknown user - System::httpExit(404); + // Any other case (unknown, blocked, unverified, expired, no profile, no self contact) + System::jsonError(404, $data); } } } From da710999e032ad01aa91822f1b80de729e15de25 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 1 Apr 2019 03:17:25 -0400 Subject: [PATCH 2/4] Added unavailable local profile AP issue to CHANGELOG --- CHANGELOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 337cca4289..0708576f55 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ Version 2019.06 (UNRELEASED) (2019-06-?) Fixed tag completion painfully slow [AlfredSK] Fixed a regression in notifications [MrPetovan] Fixed an issue with smilies and code blocks [MrPetovan] + Fixed an AP issue with unavailable local profiles [MrPetovan] General Code cleaning and restructuring [nupplaphil] Added frio color scheme sharing [JeroenED] Added syslog and stream Logger [nupplaphil] @@ -14,7 +15,7 @@ Version 2019.06 (UNRELEASED) (2019-06-?) Added collapsible panel for connector permission fields [MrPetovan] Closed Issues: - 6303, 6478, 6319, 6921, 6903 + 6303, 6478, 6319, 6921, 6903, 6943 Version 2019.03 (2019-03-22) Friendica Core: From d51b9226a62817ed589cd5ad4f98e1958511796a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 1 Apr 2019 05:05:52 -0400 Subject: [PATCH 3/4] Replace deprecated System::baseURL with App->getBaseUrl in Module\Profile --- src/Module/Profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Profile.php b/src/Module/Profile.php index a9a1fe6d09..62598400d4 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -65,7 +65,7 @@ class Profile extends BaseModule // Known deleted user $data = [ '@context' => ActivityPub::CONTEXT, - 'id' => System::baseUrl() . '/profile/' . self::$which, + 'id' => self::getApp()->getBaseUrl() . '/profile/' . self::$which, 'type' => 'Tombstone', 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), 'updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), From 5b12bccb457511924686979348104cb447aacd26 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 4 Apr 2019 07:38:40 -0400 Subject: [PATCH 4/4] Move user tombstone activity data to ActivityPub\Transmitter --- src/Module/Profile.php | 9 +-------- src/Protocol/ActivityPub/Transmitter.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Module/Profile.php b/src/Module/Profile.php index 62598400d4..55150a9649 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -63,14 +63,7 @@ class Profile extends BaseModule System::jsonExit($data, 'application/activity+json'); } elseif (DBA::exists('userd', ['username' => self::$which])) { // Known deleted user - $data = [ - '@context' => ActivityPub::CONTEXT, - 'id' => self::getApp()->getBaseUrl() . '/profile/' . self::$which, - 'type' => 'Tombstone', - 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), - 'updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), - 'deleted' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), - ]; + $data = ActivityPub\Transmitter::getDeletedUser(self::$which); System::jsonError(410, $data); } else { diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index eb1da09b3a..6e7bc73a5a 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -247,6 +247,23 @@ class Transmitter return $data; } + /** + * @param string $username + * @return array + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public static function getDeletedUser($username) + { + return [ + '@context' => ActivityPub::CONTEXT, + 'id' => System::baseUrl() . '/profile/' . $username, + 'type' => 'Tombstone', + 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), + 'updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), + 'deleted' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), + ]; + } + /** * Returns an array with permissions of a given item array *