@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
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
@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)
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)
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
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
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
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
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
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