From 84d991988eb076a7d83c771b3266f66f1c8a9754 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 28 Apr 2022 20:19:10 +0200 Subject: [PATCH 1/4] Fix temporary network/remote server error prevent from interactions with remote accounts (#18161) * Fix temporary network/remote server error prevent from interactions with remote accounts * Fix and add tests --- app/services/resolve_url_service.rb | 5 +++++ spec/services/resolve_url_service_spec.rb | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/services/resolve_url_service.rb b/app/services/resolve_url_service.rb index 5981e4d98a..e2c745673e 100644 --- a/app/services/resolve_url_service.rb +++ b/app/services/resolve_url_service.rb @@ -30,6 +30,11 @@ class ResolveURLService < BaseService end def process_url_from_db + if [500, 502, 503, 504, nil].include?(fetch_resource_service.response_code) + account = Account.find_by(uri: @url) + return account unless account.nil? + end + return unless @on_behalf_of.present? && [401, 403, 404].include?(fetch_resource_service.response_code) # It may happen that the resource is a private toot, and thus not fetchable, diff --git a/spec/services/resolve_url_service_spec.rb b/spec/services/resolve_url_service_spec.rb index a38b235900..1b639dea98 100644 --- a/spec/services/resolve_url_service_spec.rb +++ b/spec/services/resolve_url_service_spec.rb @@ -7,15 +7,29 @@ describe ResolveURLService, type: :service do describe '#call' do it 'returns nil when there is no resource url' do - url = 'http://example.com/missing-resource' + url = 'http://example.com/missing-resource' + known_account = Fabricate(:account, uri: url) service = double allow(FetchResourceService).to receive(:new).and_return service + allow(service).to receive(:response_code).and_return(404) allow(service).to receive(:call).with(url).and_return(nil) expect(subject.call(url)).to be_nil end + it 'returns known account on temporary error' do + url = 'http://example.com/missing-resource' + known_account = Fabricate(:account, uri: url) + service = double + + allow(FetchResourceService).to receive(:new).and_return service + allow(service).to receive(:response_code).and_return(500) + allow(service).to receive(:call).with(url).and_return(nil) + + expect(subject.call(url)).to eq known_account + end + context 'searching for a remote private status' do let(:account) { Fabricate(:account) } let(:poster) { Fabricate(:account, domain: 'example.com') } From eed5a4bf9c7e41a03ebab92dd45ebc1b899dc768 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 28 Apr 2022 21:29:29 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Fix=20empty=20=E2=80=9CServer=20rules=20vio?= =?UTF-8?q?lation=E2=80=9D=20report=20option=20(#18165)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mastodon/features/report/category.js | 18 +++++++++++++++--- app/javascript/mastodon/features/ui/index.js | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/javascript/mastodon/features/report/category.js b/app/javascript/mastodon/features/report/category.js index a36dc81b12..9215b3f51e 100644 --- a/app/javascript/mastodon/features/report/category.js +++ b/app/javascript/mastodon/features/report/category.js @@ -1,5 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import { connect } from 'react-redux'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import Button from 'mastodon/components/button'; import Option from './components/option'; @@ -17,11 +19,17 @@ const messages = defineMessages({ account: { id: 'report.category.title_account', defaultMessage: 'profile' }, }); -export default @injectIntl +const mapStateToProps = state => ({ + rules: state.get('rules'), +}); + +export default @connect(mapStateToProps) +@injectIntl class Category extends React.PureComponent { static propTypes = { onNextStep: PropTypes.func.isRequired, + rules: ImmutablePropTypes.list, category: PropTypes.string, onChangeCategory: PropTypes.func.isRequired, startedFrom: PropTypes.oneOf(['status', 'account']), @@ -53,13 +61,17 @@ class Category extends React.PureComponent { }; render () { - const { category, startedFrom, intl } = this.props; + const { category, startedFrom, rules, intl } = this.props; - const options = [ + const options = rules.size > 0 ? [ 'dislike', 'spam', 'violation', 'other', + ] : [ + 'dislike', + 'spam', + 'other', ]; return ( diff --git a/app/javascript/mastodon/features/ui/index.js b/app/javascript/mastodon/features/ui/index.js index 2d0136992e..1ee038223c 100644 --- a/app/javascript/mastodon/features/ui/index.js +++ b/app/javascript/mastodon/features/ui/index.js @@ -14,6 +14,7 @@ import { uploadCompose, resetCompose, changeComposeSpoilerness } from '../../act import { expandHomeTimeline } from '../../actions/timelines'; import { expandNotifications } from '../../actions/notifications'; import { fetchFilters } from '../../actions/filters'; +import { fetchRules } from '../../actions/rules'; import { clearHeight } from '../../actions/height_cache'; import { focusApp, unfocusApp, changeLayout } from 'mastodon/actions/app'; import { synchronouslySubmitMarkers, submitMarkers, fetchMarkers } from 'mastodon/actions/markers'; @@ -368,6 +369,7 @@ class UI extends React.PureComponent { this.props.dispatch(expandHomeTimeline()); this.props.dispatch(expandNotifications()); setTimeout(() => this.props.dispatch(fetchFilters()), 500); + setTimeout(() => this.props.dispatch(fetchRules()), 3000); this.hotkeys.__mousetrap__.stopCallback = (e, element) => { return ['TEXTAREA', 'SELECT', 'INPUT'].includes(element.tagName); From 66a63d79ea11641c3e15cf65785be464cf3695bc Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 28 Apr 2022 23:34:58 +0200 Subject: [PATCH 3/4] Fix 500 error when a bookmark or favorite has been reported and deleted (#18174) --- app/controllers/api/v1/bookmarks_controller.rb | 2 +- app/controllers/api/v1/favourites_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/bookmarks_controller.rb b/app/controllers/api/v1/bookmarks_controller.rb index aa3fb88f08..0cc2318409 100644 --- a/app/controllers/api/v1/bookmarks_controller.rb +++ b/app/controllers/api/v1/bookmarks_controller.rb @@ -21,7 +21,7 @@ class Api::V1::BookmarksController < Api::BaseController end def results - @_results ||= account_bookmarks.eager_load(:status).to_a_paginated_by_id( + @_results ||= account_bookmarks.joins(:status).eager_load(:status).to_a_paginated_by_id( limit_param(DEFAULT_STATUSES_LIMIT), params_slice(:max_id, :since_id, :min_id) ) diff --git a/app/controllers/api/v1/favourites_controller.rb b/app/controllers/api/v1/favourites_controller.rb index 21836bc170..2a873696c0 100644 --- a/app/controllers/api/v1/favourites_controller.rb +++ b/app/controllers/api/v1/favourites_controller.rb @@ -21,7 +21,7 @@ class Api::V1::FavouritesController < Api::BaseController end def results - @_results ||= account_favourites.eager_load(:status).to_a_paginated_by_id( + @_results ||= account_favourites.joins(:status).eager_load(:status).to_a_paginated_by_id( limit_param(DEFAULT_STATUSES_LIMIT), params_slice(:max_id, :since_id, :min_id) ) From 01c2f47b7f397af362504a64d850b0eed0b4575f Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 28 Apr 2022 21:29:29 +0200 Subject: [PATCH 4/4] =?UTF-8?q?[Glitch]=20Fix=20empty=20=E2=80=9CServer=20?= =?UTF-8?q?rules=20violation=E2=80=9D=20report=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Port eed5a4bf9c7e41a03ebab92dd45ebc1b899dc768 to glitch-soc Signed-off-by: Claire --- .../glitch/features/report/category.js | 18 +++++++++++++++--- .../flavours/glitch/features/ui/index.js | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/javascript/flavours/glitch/features/report/category.js b/app/javascript/flavours/glitch/features/report/category.js index cf63533d07..4c71ccde70 100644 --- a/app/javascript/flavours/glitch/features/report/category.js +++ b/app/javascript/flavours/glitch/features/report/category.js @@ -1,5 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import { connect } from 'react-redux'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import Button from 'flavours/glitch/components/button'; import Option from './components/option'; @@ -17,11 +19,17 @@ const messages = defineMessages({ account: { id: 'report.category.title_account', defaultMessage: 'profile' }, }); -export default @injectIntl +const mapStateToProps = state => ({ + rules: state.get('rules'), +}); + +export default @connect(mapStateToProps) +@injectIntl class Category extends React.PureComponent { static propTypes = { onNextStep: PropTypes.func.isRequired, + rules: ImmutablePropTypes.list, category: PropTypes.string, onChangeCategory: PropTypes.func.isRequired, startedFrom: PropTypes.oneOf(['status', 'account']), @@ -53,13 +61,17 @@ class Category extends React.PureComponent { }; render () { - const { category, startedFrom, intl } = this.props; + const { category, startedFrom, rules, intl } = this.props; - const options = [ + const options = rules.size > 0 ? [ 'dislike', 'spam', 'violation', 'other', + ] : [ + 'dislike', + 'spam', + 'other', ]; return ( diff --git a/app/javascript/flavours/glitch/features/ui/index.js b/app/javascript/flavours/glitch/features/ui/index.js index 7ca1adf7cc..099ffc69c7 100644 --- a/app/javascript/flavours/glitch/features/ui/index.js +++ b/app/javascript/flavours/glitch/features/ui/index.js @@ -11,6 +11,7 @@ import { uploadCompose, resetCompose, changeComposeSpoilerness } from 'flavours/ import { expandHomeTimeline } from 'flavours/glitch/actions/timelines'; import { expandNotifications, notificationsSetVisibility } from 'flavours/glitch/actions/notifications'; import { fetchFilters } from 'flavours/glitch/actions/filters'; +import { fetchRules } from 'flavours/glitch/actions/rules'; import { clearHeight } from 'flavours/glitch/actions/height_cache'; import { synchronouslySubmitMarkers, submitMarkers, fetchMarkers } from 'flavours/glitch/actions/markers'; import { WrappedSwitch, WrappedRoute } from 'flavours/glitch/util/react_router_helpers'; @@ -402,6 +403,7 @@ class UI extends React.Component { this.props.dispatch(expandHomeTimeline()); this.props.dispatch(expandNotifications()); setTimeout(() => this.props.dispatch(fetchFilters()), 500); + setTimeout(() => this.props.dispatch(fetchRules()), 3000); } componentDidMount () {