From 939da09902b08de2578074ec9bf484e6096385db Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 28 Jan 2025 22:24:38 +0300 Subject: [PATCH] Remove subscribe button from changeset subscription page if restricted --- .../changeset_subscriptions_controller.rb | 1 + .../restricted.html.erb | 9 ++++ config/locales/en.yml | 2 + ...changeset_subscriptions_controller_test.rb | 45 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 app/views/changeset_subscriptions/restricted.html.erb diff --git a/app/controllers/changeset_subscriptions_controller.rb b/app/controllers/changeset_subscriptions_controller.rb index 6e0ad5257e..f976747479 100644 --- a/app/controllers/changeset_subscriptions_controller.rb +++ b/app/controllers/changeset_subscriptions_controller.rb @@ -12,6 +12,7 @@ class ChangesetSubscriptionsController < ApplicationController def show @changeset = Changeset.find(params[:changeset_id]) @subscribed = @changeset.subscribed?(current_user) + render :action => "restricted" unless @subscribed || can?(:show, ChangesetComment) rescue ActiveRecord::RecordNotFound render :action => "no_such_entry", :status => :not_found end diff --git a/app/views/changeset_subscriptions/restricted.html.erb b/app/views/changeset_subscriptions/restricted.html.erb new file mode 100644 index 0000000000..29eedda456 --- /dev/null +++ b/app/views/changeset_subscriptions/restricted.html.erb @@ -0,0 +1,9 @@ +<% content_for :heading do %> +

<%= @subscribed ? t("changeset_subscriptions.show.unsubscribe.heading") : t("changeset_subscriptions.show.subscribe.heading") %>

+<% end %> + +<%= render :partial => "heading", :object => @changeset, :as => "changeset" %> + +

+ <%= t(".warning") %> +

diff --git a/config/locales/en.yml b/config/locales/en.yml index f24f460694..5cc7b53d49 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -531,6 +531,8 @@ en: no_such_entry: heading: "No entry with the id: %{id}" body: "Sorry, there is no changeset with the id %{id}. Please check your spelling, or maybe the link you clicked is wrong." + restricted: + warning: You can't receive changeset comment notifications until you agree to the Terms of Use. dashboards: contact: km away: "%{count}km away" diff --git a/test/controllers/changeset_subscriptions_controller_test.rb b/test/controllers/changeset_subscriptions_controller_test.rb index 7d899ac878..778cdedd88 100644 --- a/test/controllers/changeset_subscriptions_controller_test.rb +++ b/test/controllers/changeset_subscriptions_controller_test.rb @@ -52,6 +52,26 @@ def test_show_when_not_subscribed end end + def test_show_when_not_subscribed_and_restricted + user = create(:user) + other_user = create(:user) + changeset = create(:changeset, :user => user) + + session_for(other_user) + + with_settings(:data_restrictions => [{ :type => :hide_changeset_comments }]) do + get changeset_subscription_path(changeset) + end + + assert_response :success + assert_dom ".content-body" do + assert_dom "a[href='#{changeset_path(changeset)}']", :text => "Changeset #{changeset.id}" + assert_dom "a[href='#{user_path(user)}']", :text => user.display_name + assert_dom "form", :count => 0 + assert_dom ".alert", :text => /Terms of Use/ + end + end + def test_show_when_subscribed user = create(:user) other_user = create(:user) @@ -74,6 +94,31 @@ def test_show_when_subscribed end end + def test_show_when_subscribed_and_restricted + user = create(:user) + other_user = create(:user) + changeset = create(:changeset, :user => user) + changeset.subscribers << other_user + + session_for(other_user) + + with_settings(:data_restrictions => [{ :type => :hide_changeset_comments }]) do + get changeset_subscription_path(changeset) + end + + assert_response :success + assert_dom ".content-body" do + assert_dom "a[href='#{changeset_path(changeset)}']", :text => "Changeset #{changeset.id}" + assert_dom "a[href='#{user_path(user)}']", :text => user.display_name + assert_dom "form" do + assert_dom "> @action", changeset_subscription_path(changeset) + assert_dom "input[type=submit]" do + assert_dom "> @value", "Unsubscribe from discussion" + end + end + end + end + def test_create_success user = create(:user) other_user = create(:user)