diff --git a/Changelog.md b/Changelog.md index 2a5cb1329..4140e2df7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,6 +14,8 @@ ## 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 diff --git a/Gemfile b/Gemfile index 08b97d94d..a6cf178e3 100644 --- a/Gemfile +++ b/Gemfile @@ -65,7 +65,7 @@ gem "sprockets-rails", "3.2.1" # Database group :mysql, optional: true do - gem "mysql2", "0.4.9" + gem "mysql2", "0.4.10" end group :postgresql, optional: true do gem "pg", "0.21.0" diff --git a/Gemfile.lock b/Gemfile.lock index cb79eb6e3..e99174f04 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -391,7 +391,7 @@ GEM multi_test (0.1.2) multi_xml (0.6.0) multipart-post (2.0.0) - mysql2 (0.4.9) + mysql2 (0.4.10) naught (1.1.0) nenv (0.3.0) nio4r (2.1.0) @@ -831,7 +831,7 @@ DEPENDENCIES mini_magick (= 4.8.0) minitest mobile-fu (= 1.4.0) - mysql2 (= 0.4.9) + mysql2 (= 0.4.10) nokogiri (= 1.8.2) omniauth (= 1.6.1) omniauth-facebook (= 4.0.0) diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index 2347fce18..fc75a31f6 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -6,7 +6,6 @@ //= link bookmarklet.js //= link mobile/bookmarklet.js //= link mobile/mobile.js -//= link templates.js //= link error_pages.css //= link admin.css //= link rtl.css diff --git a/app/assets/javascripts/app/helpers/handlebars-partials.js b/app/assets/javascripts/app/helpers/handlebars-partials.js index 6f1815229..3f9b354eb 100644 --- a/app/assets/javascripts/app/helpers/handlebars-partials.js +++ b/app/assets/javascripts/app/helpers/handlebars-partials.js @@ -1,7 +1,4 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later -/* we need to wrap this in a document ready to ensure JST is accessible */ -$(function(){ - Handlebars.registerPartial('status-message', HandlebarsTemplates['status-message_tpl']); -}); +Handlebars.registerPartial("status-message", HandlebarsTemplates["status-message_tpl"]); // @license-end diff --git a/app/assets/javascripts/jasmine-load-all.js b/app/assets/javascripts/jasmine-load-all.js index b465abdad..fe771027c 100644 --- a/app/assets/javascripts/jasmine-load-all.js +++ b/app/assets/javascripts/jasmine-load-all.js @@ -1,6 +1,5 @@ //= require jquery3 //= require handlebars.runtime -//= require templates //= require main //= require fine-uploader/fine-uploader.core //= require mobile/mobile diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index a47f75d68..c8dfedf78 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -18,6 +18,7 @@ //= require jquery.autoSuggest.custom //= require fine-uploader/fine-uploader.core //= require handlebars.runtime +//= require_tree ../templates //= require posix-bracket-expressions //= require markdown-it //= require markdown-it-diaspora-mention diff --git a/app/assets/javascripts/templates.js b/app/assets/javascripts/templates.js deleted file mode 100644 index b46d3dab2..000000000 --- a/app/assets/javascripts/templates.js +++ /dev/null @@ -1,5 +0,0 @@ -/* Copyright (c) 2010-2011, Diaspora Inc. This file is - * licensed under the Affero General Public License version 3 or later. See - * the COPYRIGHT file. - */ -//= require_tree ../templates diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 20d4c1c97..432f7d7c7 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -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 diff --git a/app/services/status_message_creation_service.rb b/app/services/status_message_creation_service.rb index a0601d07b..5f53c440e 100644 --- a/app/services/status_message_creation_service.rb +++ b/app/services/status_message_creation_service.rb @@ -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 @@ -72,4 +77,7 @@ class StatusMessageCreationService url: short_post_url(status_message.guid, host: AppConfig.environment.url), service_types: receiving_services) end + + class BadAspectsIDs < RuntimeError + end end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index a55a832e6..a50e428aa 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -8,7 +8,7 @@ %meta{name: "viewport", content: "width=device-width, initial-scale=1"}/ - content_for :javascript do - = javascript_include_tag :main, :templates + = javascript_include_tag :main = load_javascript_locales = include_color_theme diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 6c6c3f394..d9e887a91 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -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." diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index c954ce4c6..d38c12289 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -132,6 +132,12 @@ describe StatusMessagesController, :type => :controller do status_message = StatusMessage.find_by_text(text) expect(status_message.aspect_visibilities.map(&:aspect)).to match_array([@aspect1, @aspect2]) end + + it "responses 422 when aspect_ids don't contain any applicable aspect identifiers" do + bad_ids = [Aspect.ids.max.next, bob.aspects.first.id] + post :create, params: status_message_hash.merge(aspect_ids: bad_ids.to_s), format: :json + expect(response.status).to eq(422) + end end it "dispatches the post to the specified services" do diff --git a/spec/services/status_message_creation_service_spec.rb b/spec/services/status_message_creation_service_spec.rb index a7b9f05c3..aaca06da3 100644 --- a/spec/services/status_message_creation_service_spec.rb +++ b/spec/services/status_message_creation_service_spec.rb @@ -29,6 +29,13 @@ describe StatusMessageCreationService do status_message = StatusMessageCreationService.new(alice).create(params.merge(public: true)) expect(status_message.aspect_visibilities).to be_empty end + + it "raises exception if aspects_ids don't contain any applicable aspect identifiers" do + bad_ids = [Aspect.ids.max.next, bob.aspects.first.id].map(&:to_s) + expect { + StatusMessageCreationService.new(alice).create(params.merge(aspect_ids: bad_ids)) + }.to remain(StatusMessage, :count).and raise_error(StatusMessageCreationService::BadAspectsIDs) + end end context "with public" do diff --git a/spec/shared_behaviors/account_deletion.rb b/spec/shared_behaviors/account_deletion.rb index d4019937a..25ce9a6d9 100644 --- a/spec/shared_behaviors/account_deletion.rb +++ b/spec/shared_behaviors/account_deletion.rb @@ -44,8 +44,6 @@ shared_examples_for "it removes the person associations" do end shared_examples_for "it keeps the person conversations" do - RSpec::Matchers.define_negated_matcher :remain, :change - it "remains the person conversations" do expect { account_removal_method diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8cb7fa13b..cb810e975 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,6 +24,8 @@ Dir["#{File.dirname(__FILE__)}/shared_behaviors/**/*.rb"].each do |f| require f end +RSpec::Matchers.define_negated_matcher :remain, :change + ProcessedImage.enable_processing = false UnprocessedImage.enable_processing = false