Merge pull request #14351 from annando/issue-14349

Issue 14349: Fix profile page for unrelated contacts
This commit is contained in:
Tobias Diekershoff 2024-08-11 12:21:43 +02:00 committed by GitHub
commit 80bd572393
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 440 additions and 476 deletions

View file

@ -281,12 +281,12 @@ class User
*/
public static function setCollapsed(int $cid, int $uid, bool $collapsed)
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
$pcid = Contact::getPublicContactId($cid, $uid);
if (!$pcid) {
return;
}
DBA::update('user-contact', ['collapsed' => $collapsed], ['cid' => $cdata['public'], 'uid' => $uid], true);
DBA::update('user-contact', ['collapsed' => $collapsed], ['cid' => $pcid, 'uid' => $uid], true);
}
/**
@ -300,21 +300,13 @@ class User
*/
public static function isCollapsed(int $cid, int $uid): bool
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
$pcid = Contact::getPublicContactId($cid, $uid);
if (!$pcid) {
return false;
}
$collapsed = false;
if (!empty($cdata['public'])) {
$public_contact = DBA::selectFirst('user-contact', ['collapsed'], ['cid' => $cdata['public'], 'uid' => $uid]);
if (DBA::isResult($public_contact)) {
$collapsed = (bool) $public_contact['collapsed'];
}
}
return $collapsed;
$public_contact = DBA::selectFirst('user-contact', ['collapsed'], ['cid' => $pcid, 'uid' => $uid]);
return $public_contact['collapsed'] ?? false;
}
/**
@ -328,12 +320,12 @@ class User
*/
public static function setChannelFrequency(int $cid, int $uid, int $frequency)
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
$pcid = Contact::getPublicContactId($cid, $uid);
if (!$pcid) {
return;
}
DBA::update('user-contact', ['channel-frequency' => $frequency], ['cid' => $cdata['public'], 'uid' => $uid], true);
DBA::update('user-contact', ['channel-frequency' => $frequency], ['cid' => $pcid, 'uid' => $uid], true);
}
/**
@ -347,21 +339,13 @@ class User
*/
public static function getChannelFrequency(int $cid, int $uid): int
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
$pcid = Contact::getPublicContactId($cid, $uid);
if (!$pcid) {
return false;
}
$frequency = self::FREQUENCY_DEFAULT;
if (!empty($cdata['public'])) {
$public_contact = DBA::selectFirst('user-contact', ['channel-frequency'], ['cid' => $cdata['public'], 'uid' => $uid]);
if (DBA::isResult($public_contact)) {
$frequency = $public_contact['channel-frequency'] ?? self::FREQUENCY_DEFAULT;
}
}
return $frequency;
$public_contact = DBA::selectFirst('user-contact', ['channel-frequency'], ['cid' => $pcid, 'uid' => $uid]);
return $public_contact['channel-frequency'] ?? self::FREQUENCY_DEFAULT;
}
/**
@ -375,12 +359,12 @@ class User
*/
public static function setChannelOnly(int $cid, int $uid, bool $isChannelOnly)
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
$pcid = Contact::getPublicContactId($cid, $uid);
if (!$pcid) {
return;
}
DBA::update('user-contact', ['channel-only' => $isChannelOnly], ['cid' => $cdata['public'], 'uid' => $uid], true);
DBA::update('user-contact', ['channel-only' => $isChannelOnly], ['cid' => $pcid, 'uid' => $uid], true);
}
/**
@ -394,21 +378,13 @@ class User
*/
public static function getChannelOnly(int $cid, int $uid): bool
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
$pcid = Contact::getPublicContactId($cid, $uid);
if (!$pcid) {
return false;
}
$isChannelOnly = false;
if (!empty($cdata['public'])) {
$public_contact = DBA::selectFirst('user-contact', ['channel-only'], ['cid' => $cdata['public'], 'uid' => $uid]);
if (DBA::isResult($public_contact)) {
$isChannelOnly = $public_contact['channel-only'] ?? false;
}
}
return $isChannelOnly;
$public_contact = DBA::selectFirst('user-contact', ['channel-only'], ['cid' => $pcid, 'uid' => $uid]);
return $public_contact['channel-only'] ?? false;
}
/**
@ -422,12 +398,12 @@ class User
*/
public static function setIsBlocked(int $cid, int $uid, bool $blocked)
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
$pcid = Contact::getPublicContactId($cid, $uid);
if (!$pcid) {
return;
}
DBA::update('user-contact', ['is-blocked' => $blocked], ['cid' => $cdata['public'], 'uid' => $uid], true);
DBA::update('user-contact', ['is-blocked' => $blocked], ['cid' => $pcid, 'uid' => $uid], true);
}
/**
@ -440,18 +416,12 @@ class User
*/
public static function isIsBlocked(int $cid, int $uid): bool
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
$pcid = Contact::getPublicContactId($cid, $uid);
if (!$pcid) {
return false;
}
if (!empty($cdata['public'])) {
$public_contact = DBA::selectFirst('user-contact', ['is-blocked'], ['cid' => $cdata['public'], 'uid' => $uid]);
if (DBA::isResult($public_contact)) {
return $public_contact['is-blocked'];
}
}
return false;
$public_contact = DBA::selectFirst('user-contact', ['is-blocked'], ['cid' => $pcid, 'uid' => $uid]);
return $public_contact['is-blocked'] ?? false;
}
}

View file

@ -100,12 +100,12 @@ class UpdateCredentials extends BaseApi
User::update($user, $uid);
Profile::update($profile, $uid);
$cdata = Contact::getPublicAndUserContactID($owner['id'], $uid);
if (empty($cdata)) {
$ucid = Contact::getUserContactId($owner['id'], $uid);
if (!$ucid) {
DI::mstdnError()->InternalError();
}
$account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid);
$account = DI::mstdnAccount()->createFromContactId($ucid, $uid);
$this->response->addJsonContent($account->toArray());
}
}

View file

@ -45,13 +45,13 @@ class VerifyCredentials extends BaseApi
DI::mstdnError()->InternalError();
}
$cdata = Contact::getPublicAndUserContactID($self['id'], $uid);
if (empty($cdata)) {
$ucid = Contact::getUserContactId($self['id'], $uid);
if (!$ucid) {
DI::mstdnError()->InternalError();
}
// @todo Support the source property,
$account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid);
$account = DI::mstdnAccount()->createFromContactId($ucid, $uid);
$this->response->addJsonContent($account->toArray());
}
}

View file

@ -81,18 +81,18 @@ class Conversations extends BaseModule
// Backward compatibility: Ensure to use the public contact when the user contact is provided
// Remove by version 2022.03
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), $this->userSession->getLocalUserId());
if (empty($data)) {
$pcid = Model\Contact::getPublicContactId(intval($this->parameters['id']), $this->userSession->getLocalUserId());
if (!$pcid) {
throw new NotFoundException($this->t('Contact not found.'));
}
$contact = Model\Contact::getById($data['public']);
$contact = Model\Contact::getById($pcid);
if (empty($contact)) {
throw new NotFoundException($this->t('Contact not found.'));
}
// Don't display contacts that are about to be deleted
if (!empty($contact['deleted']) || !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM) {
if ($contact['deleted'] || $contact['network'] == Protocol::PHANTOM) {
throw new NotFoundException($this->t('Contact not found.'));
}

View file

@ -73,18 +73,18 @@ class Posts extends BaseModule
// Backward compatibility: Ensure to use the public contact when the user contact is provided
// Remove by version 2022.03
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), $this->userSession->getLocalUserId());
if (empty($data)) {
$pcid = Model\Contact::getPublicContactId(intval($this->parameters['id']), $this->userSession->getLocalUserId());
if (!$pcid) {
throw new NotFoundException($this->t('Contact not found.'));
}
$contact = Model\Contact::getById($data['public']);
$contact = Model\Contact::getById($pcid);
if (!DBA::isResult($contact)) {
throw new NotFoundException($this->t('Contact not found.'));
}
// Don't display contacts that are about to be deleted
if (DBA::isResult($contact) && (!empty($contact['deleted']) || !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM)) {
if ($contact['deleted'] || $contact['network'] == Protocol::PHANTOM) {
throw new NotFoundException($this->t('Contact not found.'));
}

View file

@ -165,10 +165,12 @@ class Profile extends BaseModule
}
// Fetch the protocol from the user's contact.
$usercontact = Contact::getById($data['user'], ['network', 'protocol']);
if ($this->db->isResult($usercontact)) {
$contact['network'] = $usercontact['network'];
$contact['protocol'] = $usercontact['protocol'];
if ($data['user']) {
$usercontact = Contact::getById($data['user'], ['network', 'protocol']);
if ($this->db->isResult($usercontact)) {
$contact['network'] = $usercontact['network'];
$contact['protocol'] = $usercontact['protocol'];
}
}
if (empty($contact['network']) && Contact::isLocal($contact['url']) ) {
@ -177,7 +179,7 @@ class Profile extends BaseModule
}
// Don't display contacts that are about to be deleted
if ($this->db->isResult($contact) && (!empty($contact['deleted']) || !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM)) {
if ($contact['deleted'] || $contact['network'] == Protocol::PHANTOM) {
throw new HTTPException\NotFoundException($this->t('Contact not found.'));
}

View file

@ -59,16 +59,12 @@ class Revoke extends BaseModule
return;
}
$data = Model\Contact::getPublicAndUserContactID($this->parameters['id'], DI::userSession()->getLocalUserId());
if (!$this->dba->isResult($data)) {
throw new HTTPException\NotFoundException($this->t('Unknown contact.'));
}
if (empty($data['user'])) {
$ucid = Model\Contact::getUserContactId($this->parameters['id'], DI::userSession()->getLocalUserId());
if (!$ucid) {
throw new HTTPException\ForbiddenException();
}
$this->contact = Model\Contact::getById($data['user']);
$this->contact = Model\Contact::getById($ucid);
if ($this->contact['deleted']) {
throw new HTTPException\NotFoundException($this->t('Contact is deleted.'));

File diff suppressed because it is too large Load diff