]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/issues_controller.rb
Remove indirection.
[rails.git] / app / controllers / issues_controller.rb
index 763c85ef107edc2ea6542cddea82f4a916584fce..63228c79e5b6f62d989d5938b0ed2f569a12b9fe 100644 (file)
@@ -22,8 +22,8 @@ class IssuesController < ApplicationController
     @issues = Issue.where(:issue_type => @user_role).order(sort_column + " " + sort_direction)
 
     # If search
-    if params[:search_by_user] && !params[:search_by_user].blank?
-      @find_user = User.find_by_display_name(params[:search_by_user])
+    if params[:search_by_user] && params[:search_by_user].present?
+      @find_user = User.find_by(:display_name => params[:search_by_user])
       if @find_user
         @issues = @issues.where(:reported_user_id => @find_user.id)
       else
@@ -31,23 +31,23 @@ class IssuesController < ApplicationController
       end
     end
 
-    if params[:status] && !params[:status][0].blank?
+    if params[:status] && params[:status][0].present?
       @issues = @issues.where(:status => params[:status][0].to_i)
     end
 
-    if params[:issue_type] && !params[:issue_type][0].blank?
+    if params[:issue_type] && params[:issue_type][0].present?
       @issues = @issues.where(:reportable_type => params[:issue_type][0])
     end
 
     # If last_updated_by
-    if params[:last_updated_by] && !params[:last_updated_by][0].blank?
+    if params[:last_updated_by] && params[:last_updated_by][0].present?
       last_updated_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i
       @issues = @issues.where(:updated_by => last_updated_by)
     end
 
     notice = t("issues.index.search.issues_not_found") if @issues.first.nil?
 
-    if params[:last_reported_by] && !params[:last_reported_by][0].blank?
+    if params[:last_reported_by] && params[:last_reported_by][0].present?
       last_reported_by = params[:last_reported_by][0].to_s == "nil" ? nil : params[:last_reported_by][0].to_i
       @issues = @issues.where(:updated_by => last_reported_by)
     end
@@ -59,13 +59,11 @@ class IssuesController < ApplicationController
     @read_reports = @issue.read_reports
     @unread_reports = @issue.unread_reports
     @comments = @issue.comments
-    @related_issues = @issue.user.issues.where(:issue_type => @user_role)
-
-    @updated_by_admin = User.find(@issue.updated_by) if @issue.updated_by
+    @related_issues = @issue.reported_user.issues.where(:issue_type => @user_role)
   end
 
   def new
-    unless create_new_issue_params.blank?
+    if create_new_issue_params.present?
       @issue = Issue.find_or_initialize_by(create_new_issue_params)
       path = "issues.report_strings." + @issue.reportable.class.name.to_s
       @report_strings_yaml = t(path)
@@ -73,7 +71,7 @@ class IssuesController < ApplicationController
   end
 
   def create
-    @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id], params[:reportable_type])
+    @issue = Issue.find_by(:reportable_id => params[:reportable_id], :reportable_type => params[:reportable_type])
     # Check if Issue already exists
     unless @issue
       @issue = Issue.find_or_initialize_by(issue_params)
@@ -108,7 +106,7 @@ class IssuesController < ApplicationController
         redirect_back "/", :notice => t("issues.create.successful_report")
       end
     else
-      redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id, :reported_user_id => @issue.reported_user_id), :notice => t("issues.create.provide_details")
+      redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id), :notice => t("issues.create.provide_details")
     end
   end
 
@@ -142,7 +140,7 @@ class IssuesController < ApplicationController
         redirect_back "/", :notice => notice
       end
     else
-      redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id, :reported_user_id => @issue.reported_user_id), :notice => t("issues.update.provide_details")
+      redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id), :notice => t("issues.update.provide_details")
     end
   end
 
@@ -212,8 +210,8 @@ class IssuesController < ApplicationController
   end
 
   def set_issues
-    @admin_issues = %w(DiaryEntry DiaryComment User)
-    @moderator_issues = %w(Changeset Note)
+    @admin_issues = %w[DiaryEntry DiaryComment User]
+    @moderator_issues = %w[Changeset Note]
   end
 
   def setup_user_role
@@ -223,9 +221,9 @@ class IssuesController < ApplicationController
 
   def check_if_updated
     if @issue.reportable && (@issue.ignored? || @issue.resolved?) && @issue.reportable.has_attribute?(:updated_by) && @issue.reportable.updated_at > @last_report.updated_at
-      return true
+      true
     else
-      return false
+      false
     end
   end
 
@@ -249,11 +247,11 @@ class IssuesController < ApplicationController
   end
 
   def create_new_issue_params
-    params.permit(:reportable_id, :reportable_type, :reported_user_id)
+    params.permit(:reportable_id, :reportable_type)
   end
 
   def issue_params
-    params[:issue].permit(:reportable_id, :reportable_type, :reported_user_id)
+    params[:issue].permit(:reportable_id, :reportable_type)
   end
 
   def report_params
@@ -269,7 +267,7 @@ class IssuesController < ApplicationController
   end
 
   def sort_direction
-    %w(asc desc).include?(params[:direction]) ? params[:direction] : "asc"
+    %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
   end
 
   # back-port of ActionController#redirect_back from rails 5