From c451bbe249475b937906f8f4d85c1f1eb9804343 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 9 Nov 2023 15:50:25 +0100 Subject: [PATCH] Allow viewing and severing relationships with suspended accounts (#27667) --- .../v1/accounts/relationships_controller.rb | 5 +- app/javascript/mastodon/actions/accounts.js | 2 +- .../mastodon/components/account.jsx | 2 +- .../features/account/components/header.jsx | 30 ++-- config/routes/api.rb | 4 + .../accounts/relationships_controller_spec.rb | 102 -------------- .../api/v1/accounts/relationships_spec.rb | 133 ++++++++++++++++++ 7 files changed, 157 insertions(+), 121 deletions(-) delete mode 100644 spec/controllers/api/v1/accounts/relationships_controller_spec.rb create mode 100644 spec/requests/api/v1/accounts/relationships_spec.rb diff --git a/app/controllers/api/v1/accounts/relationships_controller.rb b/app/controllers/api/v1/accounts/relationships_controller.rb index 503f85c97..320084efb 100644 --- a/app/controllers/api/v1/accounts/relationships_controller.rb +++ b/app/controllers/api/v1/accounts/relationships_controller.rb @@ -5,10 +5,11 @@ class Api::V1::Accounts::RelationshipsController < Api::BaseController before_action :require_user! def index - accounts = Account.without_suspended.where(id: account_ids).select('id') + scope = Account.where(id: account_ids).select('id') + scope.merge!(Account.without_suspended) unless truthy_param?(:with_suspended) # .where doesn't guarantee that our results are in the same order # we requested them, so return the "right" order to the requestor. - @accounts = accounts.index_by(&:id).values_at(*account_ids).compact + @accounts = scope.index_by(&:id).values_at(*account_ids).compact render json: @accounts, each_serializer: REST::RelationshipSerializer, relationships: relationships end diff --git a/app/javascript/mastodon/actions/accounts.js b/app/javascript/mastodon/actions/accounts.js index 4a985a41e..e0448f004 100644 --- a/app/javascript/mastodon/actions/accounts.js +++ b/app/javascript/mastodon/actions/accounts.js @@ -460,7 +460,7 @@ export function fetchRelationships(accountIds) { dispatch(fetchRelationshipsRequest(newAccountIds)); - api(getState).get(`/api/v1/accounts/relationships?${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => { + api(getState).get(`/api/v1/accounts/relationships?with_suspended=true&${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => { dispatch(fetchRelationshipsSuccess({ relationships: response.data })); }).catch(error => { dispatch(fetchRelationshipsFail(error)); diff --git a/app/javascript/mastodon/components/account.jsx b/app/javascript/mastodon/components/account.jsx index aa18ce79a..f82dd9153 100644 --- a/app/javascript/mastodon/components/account.jsx +++ b/app/javascript/mastodon/components/account.jsx @@ -119,7 +119,7 @@ class Account extends ImmutablePureComponent { buttons =