Merge pull request #126 from openHPI/insert-only-subscriptions
Better Subscriptions
This commit is contained in:
@ -127,11 +127,11 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
input#subscribe {
|
||||
margin-top: 5px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
input#subscribe {
|
||||
margin-top: 5px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
#myComment {
|
||||
|
@ -121,13 +121,16 @@ class CommentsController < ApplicationController
|
||||
|
||||
def send_mail_to_subscribers(comment, request_for_comment)
|
||||
request_for_comment.commenters.each do |commenter|
|
||||
already_sent_mail = false
|
||||
subscriptions = Subscription.where(
|
||||
:request_for_comment_id => request_for_comment.id,
|
||||
:user_id => commenter.id, :user_type => commenter.class.name)
|
||||
:user_id => commenter.id, :user_type => commenter.class.name,
|
||||
:deleted => false)
|
||||
subscriptions.each do |subscription|
|
||||
if (subscription.subscription_type == 'author' and current_user == request_for_comment.user) or subscription.subscription_type == 'all'
|
||||
if subscription.user != current_user
|
||||
unless subscription.user == current_user or already_sent_mail
|
||||
UserMailer.got_new_comment_for_subscription(comment, subscription, current_user).deliver_now
|
||||
already_sent_mail = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -32,7 +32,8 @@ class SubscriptionsController < ApplicationController
|
||||
else
|
||||
authorize!
|
||||
rfc = @subscription.try(:request_for_comment)
|
||||
if @subscription.destroy
|
||||
@subscription.deleted = true
|
||||
if @subscription.save
|
||||
respond_to do |format|
|
||||
format.html { redirect_to request_for_comment_url(rfc), notice: t('subscriptions.successfully_unsubscribed') }
|
||||
format.json { render json: {message: t('subscriptions.successfully_unsubscribed')}, status: :ok}
|
||||
@ -55,7 +56,7 @@ class SubscriptionsController < ApplicationController
|
||||
def subscription_params
|
||||
current_user_id = current_user.try(:id)
|
||||
current_user_class_name = current_user.try(:class).try(:name)
|
||||
params[:subscription].permit(:request_for_comment_id, :subscription_type).merge(user_id: current_user_id, user_type: current_user_class_name)
|
||||
params[:subscription].permit(:request_for_comment_id, :subscription_type).merge(user_id: current_user_id, user_type: current_user_class_name, deleted: false)
|
||||
end
|
||||
private :subscription_params
|
||||
end
|
||||
|
@ -1,9 +1,10 @@
|
||||
#otherComments
|
||||
h5 =t('exercises.implement.comment.others')
|
||||
.container
|
||||
label
|
||||
input#subscribe type='checkbox' title=t('request_for_comments.subscribe_to_author') data-subscription=Subscription.where(user: current_user, request_for_comment_id: @request_for_comment.id).try(:first).try(:id)
|
||||
= t('request_for_comments.subscribe_to_author')
|
||||
|
||||
label
|
||||
input#subscribe type='checkbox' title=t('request_for_comments.subscribe_to_author') data-subscription=Subscription.where(user: current_user, request_for_comment_id: @request_for_comment.id, subscription_type: 'author', deleted: false).try(:first).try(:id)
|
||||
= t('request_for_comments.subscribe_to_author')
|
||||
|
||||
#myComment
|
||||
h5 =t('exercises.implement.comment.addyours')
|
||||
|
5
db/migrate/20170920145852_add_deleted_to_subscription.rb
Normal file
5
db/migrate/20170920145852_add_deleted_to_subscription.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddDeletedToSubscription < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :subscriptions, :deleted, :boolean
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170913054203) do
|
||||
ActiveRecord::Schema.define(version: 20170920145852) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -288,6 +288,7 @@ ActiveRecord::Schema.define(version: 20170913054203) do
|
||||
t.string "subscription_type"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "deleted"
|
||||
end
|
||||
|
||||
create_table "tags", force: :cascade do |t|
|
||||
|
Reference in New Issue
Block a user