diff --git a/app/assets/stylesheets/request-for-comments.css.scss b/app/assets/stylesheets/request-for-comments.css.scss index e0ff5fa0..8fb7bfea 100644 --- a/app/assets/stylesheets/request-for-comments.css.scss +++ b/app/assets/stylesheets/request-for-comments.css.scss @@ -127,11 +127,11 @@ } } } +} - input#subscribe { - margin-top: 5px; - margin-right: 5px; - } +input#subscribe { + margin-top: 5px; + margin-right: 5px; } #myComment { diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 948f3e5b..d292804e 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 21321caf..232e9f01 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -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 diff --git a/app/views/exercises/_comment_dialogcontent.html.slim b/app/views/exercises/_comment_dialogcontent.html.slim index 29fb8208..ab6dc6b4 100644 --- a/app/views/exercises/_comment_dialogcontent.html.slim +++ b/app/views/exercises/_comment_dialogcontent.html.slim @@ -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') diff --git a/db/migrate/20170920145852_add_deleted_to_subscription.rb b/db/migrate/20170920145852_add_deleted_to_subscription.rb new file mode 100644 index 00000000..eb1d47c4 --- /dev/null +++ b/db/migrate/20170920145852_add_deleted_to_subscription.rb @@ -0,0 +1,5 @@ +class AddDeletedToSubscription < ActiveRecord::Migration + def change + add_column :subscriptions, :deleted, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index c31baf1c..e7e0c6d6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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|