diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index fb5e481a0..5461566ee 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -44,11 +44,13 @@ class CommentsController < ApplicationController private def comment_params - params.require(:comment).permit(:commentable_type, :commentable_id, :parent_id, :body, :as_moderator, :as_administrator) + params.require(:comment).permit(:commentable_type, :commentable_id, :parent_id, + :body, :as_moderator, :as_administrator) end def build_comment - @comment = Comment.build(@commentable, current_user, comment_params[:body], comment_params[:parent_id].presence) + @comment = Comment.build(@commentable, current_user, comment_params[:body], + comment_params[:parent_id].presence) check_for_special_comments end @@ -61,30 +63,32 @@ class CommentsController < ApplicationController end def load_commentable - @commentable = Comment.find_commentable(comment_params[:commentable_type], comment_params[:commentable_id]) + @commentable = Comment.find_commentable(comment_params[:commentable_type], + comment_params[:commentable_id]) end def administrator_comment? - ["1", true].include?(comment_params[:as_administrator]) && can?(:comment_as_administrator, @commentable) + ["1", true].include?(comment_params[:as_administrator]) && + can?(:comment_as_administrator, @commentable) end def moderator_comment? - ["1", true].include?(comment_params[:as_moderator]) && can?(:comment_as_moderator, @commentable) + ["1", true].include?(comment_params[:as_moderator]) && + can?(:comment_as_moderator, @commentable) end def add_notification(comment) - if comment.reply? - notifiable = comment.parent - else - notifiable = comment.commentable + notifiable = comment.reply? ? comment.parent : comment.commentable + unless comment.author_id == notifiable.author_id + Notification.add(notifiable.author_id, notifiable) end - Notification.add(notifiable.author_id, notifiable) unless comment.author_id == notifiable.author_id end def verify_resident_for_commentable! return if current_user.administrator? || current_user.moderator? - if @commentable.respond_to?(:comments_for_verified_residents_only?) && @commentable.comments_for_verified_residents_only? + if @commentable.respond_to?(:comments_for_verified_residents_only?) && + @commentable.comments_for_verified_residents_only? verify_resident! end end diff --git a/app/controllers/valuation/budget_investments_controller.rb b/app/controllers/valuation/budget_investments_controller.rb index 135a3e44c..5058b3761 100644 --- a/app/controllers/valuation/budget_investments_controller.rb +++ b/app/controllers/valuation/budget_investments_controller.rb @@ -29,7 +29,8 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController end Activity.log(current_user, :valuate, @investment) - redirect_to valuation_budget_budget_investment_path(@budget, @investment), notice: t('valuation.budget_investments.notice.valuate') + notice = t('valuation.budget_investments.notice.valuate') + redirect_to valuation_budget_budget_investment_path(@budget, @investment), notice: notice else render action: :edit end @@ -46,7 +47,8 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController end def heading_filters - investments = @budget.investments.by_valuator(current_user.valuator.try(:id)).valuation_open.select(:heading_id).all.to_a + investments = @budget.investments.by_valuator(current_user.valuator.try(:id)) + .valuation_open.select(:heading_id).all.to_a [ { name: t('valuation.budget_investments.index.headings_filter_all'), id: nil, @@ -61,17 +63,20 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController end def params_for_current_valuator - Budget::Investment.filter_params(params).merge(valuator_id: current_user.valuator.id, budget_id: @budget.id) + params = { valuator_id: current_user.valuator.id, budget_id: @budget.id } + Budget::Investment.filter_params(params).merge(params) end def valuation_params - params.require(:budget_investment).permit(:price, :price_first_year, :price_explanation, :feasibility, :unfeasibility_explanation, + params.require(:budget_investment).permit(:price, :price_first_year, :price_explanation, + :feasibility, :unfeasibility_explanation, :duration, :valuation_finished, :internal_comments) end def restrict_access_to_assigned_items return if current_user.administrator? || - Budget::ValuatorAssignment.exists?(investment_id: params[:id], valuator_id: current_user.valuator.id) + Budget::ValuatorAssignment.exists?(investment_id: params[:id], + valuator_id: current_user.valuator.id) raise ActionController::RoutingError.new('Not Found') end diff --git a/app/models/comment.rb b/app/models/comment.rb index fc0fb35f8..50f6cef66 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -4,7 +4,8 @@ class Comment < ActiveRecord::Base include Graphqlable include Notifiable - COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll Topic Legislation::Question Legislation::Annotation Legislation::Proposal).freeze + COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll Topic Legislation::Question + Legislation::Annotation Legislation::Proposal).freeze acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases @@ -27,7 +28,9 @@ class Comment < ActiveRecord::Base scope :for_render, -> { with_hidden.includes(user: :organization) } scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") } - scope :not_as_admin_or_moderator, -> { where("administrator_id IS NULL").where("moderator_id IS NULL")} + scope :not_as_admin_or_moderator, -> do + where("administrator_id IS NULL").where("moderator_id IS NULL") + end scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :public_for_api, -> do where(%{(comments.commentable_type = 'Debate' and comments.commentable_id in (?)) or diff --git a/app/views/comments/_comment_tree.html.erb b/app/views/comments/_comment_tree.html.erb index 45b4aea03..eb4b20fe5 100644 --- a/app/views/comments/_comment_tree.html.erb +++ b/app/views/comments/_comment_tree.html.erb @@ -25,7 +25,9 @@ <%= t("comments.verified_only", verify_account: link_to(t("comments.verify_account"), verification_path )).html_safe %> <% else %> - <%= render 'comments/form', {commentable: commentable, parent_id: nil, toggeable: false} %> + <%= render 'comments/form', { commentable: commentable, + parent_id: nil, + toggeable: false } %> <% end %> <% else %>