Unverified Commit 0080a256 authored by cmrd Senya's avatar cmrd Senya Committed by Benjamin Neff
Browse files

StatusMessageController#create: respond 422 when aspect_ids are wrong

fixes #3862

closes #7742
parent e0e40f73
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
## Bug fixes
* Prefill conversation form on contacts page only with mutual contacts [#7744](https://github.com/diaspora/diaspora/pull/7744)
* Fix profiles sometimes not loading properly in background tabs [#7740](https://github.com/diaspora/diaspora/pull/7740)
* Show error message when creating posts with invalid aspects [#7742](https://github.com/diaspora/diaspora/pull/7742)

## Features

+2 −0
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ class StatusMessagesController < ApplicationController
      format.mobile { redirect_to stream_path }
      format.json { render json: PostPresenter.new(status_message, current_user), status: 201 }
    end
  rescue StatusMessageCreationService::BadAspectsIDs
    render status: 422, plain: I18n.t("status_messages.bad_aspects")
  rescue StandardError => error
    handle_create_error(error)
  end
+11 −6
Original line number Diff line number Diff line
@@ -9,15 +9,16 @@ class StatusMessageCreationService

  def create(params)
    build_status_message(params).tap do |status_message|
      load_aspects(params[:aspect_ids]) unless status_message.public?
      add_attachments(status_message, params)
      status_message.save
      process(status_message, params[:aspect_ids], params[:services])
      process(status_message, params[:services])
    end
  end

  private

  attr_reader :user
  attr_reader :user, :aspects

  def build_status_message(params)
    public = params[:public] || false
@@ -54,13 +55,17 @@ class StatusMessageCreationService
    end
  end

  def process(status_message, aspect_ids, services)
    add_to_streams(status_message, aspect_ids) unless status_message.public
  def load_aspects(aspect_ids)
    @aspects = user.aspects_from_ids(aspect_ids)
    raise BadAspectsIDs if aspects.empty?
  end

  def process(status_message, services)
    add_to_streams(status_message) unless status_message.public?
    dispatch(status_message, services)
  end

  def add_to_streams(status_message, aspect_ids)
    aspects = user.aspects_from_ids(aspect_ids)
  def add_to_streams(status_message)
    user.add_to_streams(status_message, aspects)
    status_message.photos.each {|photo| user.add_to_streams(photo, aspects) }
  end
+1 −0
Original line number Diff line number Diff line
@@ -1122,6 +1122,7 @@ en:
    new:
      mentioning: "Mentioning: %{person}"
    too_long: "Please make your status message fewer than %{count} characters. Right now it is %{current_length} characters"
    bad_aspects: "Provided aspects IDs aren't applicable (non-existent or not owned)"

  stream_helper:
    no_more_posts: "You have reached the end of the stream."