From 63002cde03a836b4510aca5da564504ecaedb5e9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 10 Feb 2022 00:15:30 +0100 Subject: Add editing for published statuses (#17320) * Add editing for published statuses * Fix change of multiple-choice boolean in poll not resetting votes * Remove the ability to update existing media attachments for now --- app/controllers/api/v1/statuses_controller.rb | 51 +++++++++++++++++++-------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'app/controllers/api/v1/statuses_controller.rb') diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 98b1776ea..2d82a7a99 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -3,8 +3,8 @@ class Api::V1::StatusesController < Api::BaseController include Authorization - before_action -> { authorize_if_got_token! :read, :'read:statuses' }, except: [:create, :destroy] - before_action -> { doorkeeper_authorize! :write, :'write:statuses' }, only: [:create, :destroy] + before_action -> { authorize_if_got_token! :read, :'read:statuses' }, except: [:create, :update, :destroy] + before_action -> { doorkeeper_authorize! :write, :'write:statuses' }, only: [:create, :update, :destroy] before_action :require_user!, except: [:show, :context] before_action :set_status, only: [:show, :context] before_action :set_thread, only: [:create] @@ -35,24 +35,44 @@ class Api::V1::StatusesController < Api::BaseController end def create - @status = PostStatusService.new.call(current_user.account, - text: status_params[:status], - thread: @thread, - media_ids: status_params[:media_ids], - sensitive: status_params[:sensitive], - spoiler_text: status_params[:spoiler_text], - visibility: status_params[:visibility], - scheduled_at: status_params[:scheduled_at], - application: doorkeeper_token.application, - poll: status_params[:poll], - idempotency: request.headers['Idempotency-Key'], - with_rate_limit: true) + @status = PostStatusService.new.call( + current_user.account, + text: status_params[:status], + thread: @thread, + media_ids: status_params[:media_ids], + sensitive: status_params[:sensitive], + spoiler_text: status_params[:spoiler_text], + visibility: status_params[:visibility], + language: status_params[:language], + scheduled_at: status_params[:scheduled_at], + application: doorkeeper_token.application, + poll: status_params[:poll], + idempotency: request.headers['Idempotency-Key'], + with_rate_limit: true + ) render json: @status, serializer: @status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer end + def update + @status = Status.where(account: current_account).find(params[:id]) + authorize @status, :update? + + UpdateStatusService.new.call( + @status, + current_account.id, + text: status_params[:status], + media_ids: status_params[:media_ids], + sensitive: status_params[:sensitive], + spoiler_text: status_params[:spoiler_text], + poll: status_params[:poll] + ) + + render json: @status, serializer: REST::StatusSerializer + end + def destroy - @status = Status.where(account_id: current_user.account).find(params[:id]) + @status = Status.where(account: current_account).find(params[:id]) authorize @status, :destroy? @status.discard @@ -84,6 +104,7 @@ class Api::V1::StatusesController < Api::BaseController :sensitive, :spoiler_text, :visibility, + :language, :scheduled_at, media_ids: [], poll: [ -- cgit From abd113167b4f50d2ca6b938fcb52997ab6080b0b Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 10 Feb 2022 09:13:27 +0100 Subject: Add ability to change content-type when editing a toot Content-type defaults to edited toot's content-type to avoid surprising behaviors when using clients that do not support this feature. --- app/controllers/api/v1/statuses_controller.rb | 3 ++- app/models/status.rb | 1 + app/services/update_status_service.rb | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'app/controllers/api/v1/statuses_controller.rb') diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index c928a24de..eaac8e563 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -66,7 +66,8 @@ class Api::V1::StatusesController < Api::BaseController media_ids: status_params[:media_ids], sensitive: status_params[:sensitive], spoiler_text: status_params[:spoiler_text], - poll: status_params[:poll] + poll: status_params[:poll], + content_type: status_params[:content_type] ) render json: @status, serializer: REST::StatusSerializer diff --git a/app/models/status.rb b/app/models/status.rb index e5a0beab6..236f95c1f 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -221,6 +221,7 @@ class Status < ApplicationRecord spoiler_text: spoiler_text, media_attachments_changed: media_attachments_changed, account_id: account_id || self.account_id, + content_type: content_type, created_at: at_time || edited_at ) end diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index 238ef0755..63bd27989 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -13,6 +13,7 @@ class UpdateStatusService < BaseService # @option options [String] :spoiler_text # @option options [Boolean] :sensitive # @option options [String] :language + # @option options [String] :content_type def call(status, account_id, options = {}) @status = status @options = options @@ -95,6 +96,7 @@ class UpdateStatusService < BaseService @status.spoiler_text = @options[:spoiler_text] || '' @status.sensitive = @options[:sensitive] || @options[:spoiler_text].present? @status.language = valid_locale_or_nil(@options[:language] || @status.language || @status.account.user&.preferred_posting_language || I18n.default_locale) + @status.content_type = @options[:content_type] || @status.content_type @status.edited_at = Time.now.utc @status.save! -- cgit