Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diary entry comment subscriptions #1309

Merged
merged 15 commits into from
Oct 12, 2016
Merged
2 changes: 1 addition & 1 deletion app/views/diary_entry/view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<%= richtext_area :diary_comment, :body, :cols => 80, :rows => 15 %>
<%= submit_tag t('diary_entry.view.save_button') %>
<% end %>
<% if @user and @entry.subscribers and @entry.subscribers.exists?(@user.id) %>
<% if @user and @entry.subscribers.exists?(@user.id) %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we disallow entry authors to unsubscribe to their entries?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why. I can imagine a situation where a post attracts a lot of trolls and you just want to ignore it and move on for example?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually have no opinion one way or the other, so I'm okay with this.

<div class="diary-subscribe-buttons"><%= link_to t('javascripts.changesets.show.unsubscribe'), diary_entry_unsubscribe_path(:display_name => @entry.user.display_name, :id => @entry.id), :method => :post, :class => :button %></div>
<% elsif @user %>
<div class="diary-subscribe-buttons"><%= link_to t('javascripts.changesets.show.subscribe'), diary_entry_subscribe_path(:display_name => @entry.user.display_name, :id => @entry.id), :method => :post, :class => :button %></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
require "migrate"

class AddJoinTableBetweenUsersAndDiaryEntries < ActiveRecord::Migration
def change
def self.up
create_table :diary_entry_subscriptions, :id => false do |t|
t.column :user_id, :bigint, :null => false
t.column :diary_entry_id, :bigint, :null => false
end

add_index :diary_entry_subscriptions, [:user_id, :diary_entry_id], :unique => true, :name => "index_diary_subscriptions_on_user_id_and_diary_entry_id"
add_primary_key :diary_entry_subscriptions, [:user_id, :diary_entry_id]
add_index :diary_entry_subscriptions, [:diary_entry_id]
add_foreign_key :diary_entry_subscriptions, :diary_entries, :name => "diary_entry_subscriptions_diary_entry_id_fkey"
add_foreign_key :diary_entry_subscriptions, :users, :name => "diary_entry_subscriptions_user_id_fkey"
end

def self.down
drop_table :diary_entry_subscriptions
end
end
2 changes: 1 addition & 1 deletion test/controllers/diary_entry_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def test_subscribe_fail
diary_entry = create(:diary_entry, :user_id => users(:normal_user).id)

# not signed in
assert_no_difference "diary_entry.subscribers.count", 1 do
assert_no_difference "diary_entry.subscribers.count" do
post :subscribe, :id => diary_entry.id, :display_name => diary_entry.user.display_name
end
assert_response :forbidden
Expand Down