Skip to content

Commit

Permalink
Remove subscribe button from changeset subscription page if restricted
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Jan 28, 2025
1 parent 34cd6ea commit 939da09
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/changeset_subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/views/changeset_subscriptions/restricted.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% content_for :heading do %>
<h1><%= @subscribed ? t("changeset_subscriptions.show.unsubscribe.heading") : t("changeset_subscriptions.show.subscribe.heading") %></h1>
<% end %>

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

<p class="alert alert-warning">
<%= t(".warning") %>
</p>
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 45 additions & 0 deletions test/controllers/changeset_subscriptions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 939da09

Please sign in to comment.