From 15d307075479cf93ea199be0f25820003ddbe27c Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Thu, 23 May 2024 09:30:48 +0200 Subject: [PATCH] Fix some API calls that should not use an API token (#30401) --- app/javascript/mastodon/api.ts | 4 ++-- app/javascript/mastodon/components/admin/Counter.jsx | 2 +- app/javascript/mastodon/components/admin/Dimension.jsx | 2 +- app/javascript/mastodon/components/admin/ImpactReport.jsx | 2 +- .../mastodon/components/admin/ReportReasonSelector.jsx | 4 ++-- app/javascript/mastodon/components/admin/Retention.jsx | 2 +- app/javascript/mastodon/components/admin/Trends.jsx | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/javascript/mastodon/api.ts b/app/javascript/mastodon/api.ts index ccff68c373..2ccf178f00 100644 --- a/app/javascript/mastodon/api.ts +++ b/app/javascript/mastodon/api.ts @@ -40,11 +40,11 @@ const authorizationTokenFromInitialState = (): RawAxiosRequestHeaders => { }; // eslint-disable-next-line import/no-default-export -export default function api() { +export default function api(withAuthorization = true) { return axios.create({ headers: { ...csrfHeader, - ...authorizationTokenFromInitialState(), + ...(withAuthorization ? authorizationTokenFromInitialState() : {}), }, transformResponse: [ diff --git a/app/javascript/mastodon/components/admin/Counter.jsx b/app/javascript/mastodon/components/admin/Counter.jsx index 6ce23c9f05..e4d21da627 100644 --- a/app/javascript/mastodon/components/admin/Counter.jsx +++ b/app/javascript/mastodon/components/admin/Counter.jsx @@ -48,7 +48,7 @@ export default class Counter extends PureComponent { componentDidMount () { const { measure, start_at, end_at, params } = this.props; - api().post('/api/v1/admin/measures', { keys: [measure], start_at, end_at, [measure]: params }).then(res => { + api(false).post('/api/v1/admin/measures', { keys: [measure], start_at, end_at, [measure]: params }).then(res => { this.setState({ loading: false, data: res.data, diff --git a/app/javascript/mastodon/components/admin/Dimension.jsx b/app/javascript/mastodon/components/admin/Dimension.jsx index bfda6c93d7..56557ad8e8 100644 --- a/app/javascript/mastodon/components/admin/Dimension.jsx +++ b/app/javascript/mastodon/components/admin/Dimension.jsx @@ -26,7 +26,7 @@ export default class Dimension extends PureComponent { componentDidMount () { const { start_at, end_at, dimension, limit, params } = this.props; - api().post('/api/v1/admin/dimensions', { keys: [dimension], start_at, end_at, limit, [dimension]: params }).then(res => { + api(false).post('/api/v1/admin/dimensions', { keys: [dimension], start_at, end_at, limit, [dimension]: params }).then(res => { this.setState({ loading: false, data: res.data, diff --git a/app/javascript/mastodon/components/admin/ImpactReport.jsx b/app/javascript/mastodon/components/admin/ImpactReport.jsx index c27ee0ab08..add54134b6 100644 --- a/app/javascript/mastodon/components/admin/ImpactReport.jsx +++ b/app/javascript/mastodon/components/admin/ImpactReport.jsx @@ -27,7 +27,7 @@ export default class ImpactReport extends PureComponent { include_subdomains: true, }; - api().post('/api/v1/admin/measures', { + api(false).post('/api/v1/admin/measures', { keys: ['instance_accounts', 'instance_follows', 'instance_followers'], start_at: null, end_at: null, diff --git a/app/javascript/mastodon/components/admin/ReportReasonSelector.jsx b/app/javascript/mastodon/components/admin/ReportReasonSelector.jsx index 90f4334a6e..cc05e5c163 100644 --- a/app/javascript/mastodon/components/admin/ReportReasonSelector.jsx +++ b/app/javascript/mastodon/components/admin/ReportReasonSelector.jsx @@ -105,7 +105,7 @@ class ReportReasonSelector extends PureComponent { }; componentDidMount() { - api().get('/api/v1/instance').then(res => { + api(false).get('/api/v1/instance').then(res => { this.setState({ rules: res.data.rules, }); @@ -122,7 +122,7 @@ class ReportReasonSelector extends PureComponent { return; } - api().put(`/api/v1/admin/reports/${id}`, { + api(false).put(`/api/v1/admin/reports/${id}`, { category, rule_ids: category === 'violation' ? rule_ids : [], }).catch(err => { diff --git a/app/javascript/mastodon/components/admin/Retention.jsx b/app/javascript/mastodon/components/admin/Retention.jsx index 1e8ef48b7a..87746e9f49 100644 --- a/app/javascript/mastodon/components/admin/Retention.jsx +++ b/app/javascript/mastodon/components/admin/Retention.jsx @@ -34,7 +34,7 @@ export default class Retention extends PureComponent { componentDidMount () { const { start_at, end_at, frequency } = this.props; - api().post('/api/v1/admin/retention', { start_at, end_at, frequency }).then(res => { + api(false).post('/api/v1/admin/retention', { start_at, end_at, frequency }).then(res => { this.setState({ loading: false, data: res.data, diff --git a/app/javascript/mastodon/components/admin/Trends.jsx b/app/javascript/mastodon/components/admin/Trends.jsx index c69b4a8cba..fd6db106d5 100644 --- a/app/javascript/mastodon/components/admin/Trends.jsx +++ b/app/javascript/mastodon/components/admin/Trends.jsx @@ -22,7 +22,7 @@ export default class Trends extends PureComponent { componentDidMount () { const { limit } = this.props; - api().get('/api/v1/admin/trends/tags', { params: { limit } }).then(res => { + api(false).get('/api/v1/admin/trends/tags', { params: { limit } }).then(res => { this.setState({ loading: false, data: res.data,