Proper implementation of report strings + cleaning up
This commit is contained in:
parent
0a3dd82c47
commit
fb78544d05
5 changed files with 135 additions and 66 deletions
|
@ -35,12 +35,13 @@ class IssuesController < ApplicationController
|
||||||
def new
|
def new
|
||||||
unless create_new_issue_params.blank?
|
unless create_new_issue_params.blank?
|
||||||
@issue = Issue.find_or_initialize_by(create_new_issue_params)
|
@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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
|
@issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
|
||||||
|
|
||||||
# Check if Issue alrwady exists
|
# Check if Issue alrwady exists
|
||||||
if !@issue
|
if !@issue
|
||||||
@issue = Issue.find_or_initialize_by(issue_params)
|
@issue = Issue.find_or_initialize_by(issue_params)
|
||||||
|
@ -51,15 +52,15 @@ class IssuesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if details provided are sufficient
|
# Check if details provided are sufficient
|
||||||
if params[:report][:details] and (params[:spam] or params[:offensive] or params[:threat] or params[:vandal] or params[:other])
|
if check_report_params
|
||||||
@report = @issue.reports.build(report_params)
|
@report = @issue.reports.build(report_params)
|
||||||
details = params[:report][:details].to_s + "||" + params[:spam].to_s + "||" + params[:offensive].to_s + "||" + params[:threat].to_s + "||" + params[:vandal].to_s + "||" + params[:other].to_s
|
details = get_report_details
|
||||||
@report.reporter_user_id = @user.id
|
@report.reporter_user_id = @user.id
|
||||||
@report.details = details
|
@report.details = details
|
||||||
|
|
||||||
# Checking if instance has been updated since last report
|
# Checking if instance has been updated since last report
|
||||||
@last_report = @issue.reports.order(updated_at: :desc).last
|
@last_report = @issue.reports.order(updated_at: :desc).last
|
||||||
if @issue.reportable.updated_at.present? and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
|
if check_if_updated
|
||||||
if @issue.reopen
|
if @issue.reopen
|
||||||
@issue.save!
|
@issue.save!
|
||||||
end
|
end
|
||||||
|
@ -75,9 +76,8 @@ class IssuesController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@issue = Issue.find_by(issue_params)
|
@issue = Issue.find_by(issue_params)
|
||||||
|
|
||||||
# Check if details provided are sufficient
|
# Check if details provided are sufficient
|
||||||
if params[:report][:details] and (params[:spam] or params[:offensive] or params[:threat] or params[:vandal] or params[:other])
|
if check_report_params
|
||||||
@report = @issue.reports.where(reporter_user_id: @user.id).first
|
@report = @issue.reports.where(reporter_user_id: @user.id).first
|
||||||
|
|
||||||
if @report == nil
|
if @report == nil
|
||||||
|
@ -86,12 +86,12 @@ class IssuesController < ApplicationController
|
||||||
notice = t('issues.update.new_report')
|
notice = t('issues.update.new_report')
|
||||||
end
|
end
|
||||||
|
|
||||||
details = params[:report][:details].to_s + "||" + params[:spam].to_s + "||" + params[:offensive].to_s + "||" + params[:threat].to_s + "||" + params[:vandal].to_s + "||" + params[:other].to_s
|
details = get_report_details
|
||||||
@report.details = details
|
@report.details = details
|
||||||
|
|
||||||
# Checking if instance has been updated since last report
|
# Checking if instance has been updated since last report
|
||||||
@last_report = @issue.reports.order(updated_at: :desc).last
|
@last_report = @issue.reports.order(updated_at: :desc).last
|
||||||
if @issue.reportable.updated_at.present? and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
|
if check_if_updated
|
||||||
@issue.reopen
|
@issue.reopen
|
||||||
@issue.save!
|
@issue.save!
|
||||||
end
|
end
|
||||||
|
@ -144,15 +144,49 @@ class IssuesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def check_if_updated
|
||||||
|
if @issue.reportable and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_report_details
|
||||||
|
details = params[:report][:details] + "--||--"
|
||||||
|
path = 'issues.report_strings.' + @issue.reportable.class.name.to_s
|
||||||
|
@report_strings_yaml = t( path)
|
||||||
|
@report_strings_yaml.each do |k,v|
|
||||||
|
if params[k.to_sym]
|
||||||
|
details = details + params[k.to_sym] + "--||--"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return details
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_report_params
|
||||||
|
path = 'issues.report_strings.' + @issue.reportable.class.name.to_s
|
||||||
|
@report_strings_yaml = t( path)
|
||||||
|
if params[:report] and params[:report][:details]
|
||||||
|
@report_strings_yaml.each do |k,v|
|
||||||
|
if params[k.to_sym]
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
def find_issue
|
def find_issue
|
||||||
@issue = Issue.find(params[:id])
|
@issue = Issue.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_permission
|
def check_permission
|
||||||
unless @user.administrator?
|
unless @user.administrator?
|
||||||
flash[:error] = t("application.require_admin.not_an_admin")
|
flash[:error] = t('application.require_admin.not_an_admin')
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -172,4 +206,5 @@ class IssuesController < ApplicationController
|
||||||
def issue_comment_params
|
def issue_comment_params
|
||||||
params.require(:issue_comment).permit(:body)
|
params.require(:issue_comment).permit(:body)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<%= link_to user_thumbnail(report.user), :controller => :user,:action =>:view, :display_name => report.user.display_name %>
|
<%= link_to user_thumbnail(report.user), :controller => :user,:action =>:view, :display_name => report.user.display_name %>
|
||||||
</div>
|
</div>
|
||||||
<b><%= link_to report.user.display_name, :controller => :user,:action =>:view, :display_name => report.user.display_name %></b> <br/>
|
<b><%= link_to report.user.display_name, :controller => :user,:action =>:view, :display_name => report.user.display_name %></b> <br/>
|
||||||
<% details = report.details.split("||") %>
|
<% details = report.details.split("--||--") %>
|
||||||
<%= details[0] %>
|
<%= details[0] %>
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<% content_for :heading do %>
|
<% content_for :heading do %>
|
||||||
<h1>Report a new Issue for <%= reportable_url(@issue.reportable) %></h1>
|
<h1>Report <%= reportable_url(@issue.reportable) %></h1>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= form_for(@issue) do |f| %>
|
<%= form_for(@issue) do |f| %>
|
||||||
|
@ -13,59 +13,19 @@
|
||||||
|
|
||||||
<div class='form-row'>
|
<div class='form-row'>
|
||||||
<p>Select one (or more) reasons for your report:</p>
|
<p>Select one (or more) reasons for your report:</p>
|
||||||
|
|
||||||
<div class="new-report-form">
|
|
||||||
<div class="new-report-checkbox">
|
|
||||||
<%= check_box_tag :spam, "[SPAM]" %>
|
|
||||||
</div>
|
|
||||||
<div class="new-report-string">
|
|
||||||
<%= label_tag "This #{@issue.reportable.class.name} " + t('issues.report_strings.spam') %> <br/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<div class="new-report-form">
|
<% @report_strings_yaml.each do |k,v| %>
|
||||||
<div class="new-report-checkbox">
|
|
||||||
<%= check_box_tag :offensive, "[OFFENSIVE]" %>
|
|
||||||
</div>
|
|
||||||
<div class="new-report-string">
|
|
||||||
<%= label_tag "This #{@issue.reportable.class.name} " + t('issues.report_strings.offensive') %> <br/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<div class="new-report-form">
|
|
||||||
<div class="new-report-checkbox">
|
|
||||||
<%= check_box_tag :threat, "[THREAT]" %>
|
|
||||||
</div>
|
|
||||||
<div class="new-report-string">
|
|
||||||
<%= label_tag "This #{@issue.reportable.class.name} " + t('issues.report_strings.threat') %> <br/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<% if @issue.reportable.class.name == "User" %>
|
|
||||||
<div class="new-report-form">
|
<div class="new-report-form">
|
||||||
<div class="new-report-checkbox">
|
<div class="new-report-checkbox">
|
||||||
<%= check_box_tag :vandal, "[VANDAL]" %>
|
<%= check_box_tag k.to_sym, v[:type].to_s %>
|
||||||
</div>
|
</div>
|
||||||
<div class="new-report-string">
|
<div class="new-report-string">
|
||||||
<%= label_tag "This #{@issue.reportable.class.name} " + t('issues.report_strings.vandal') %> <br/>
|
<%= label_tag v[:details].to_s %> <br/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="new-report-form">
|
|
||||||
<div class="new-report-checkbox">
|
|
||||||
<%= check_box_tag :other, "[OTHER]" %>
|
|
||||||
</div>
|
|
||||||
<div class="new-report-string">
|
|
||||||
<%= label_tag t('issues.report_strings.other') %> <br/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<label class="standard-label"><b><%= t 'issue.new.message' -%>: </b></label> <br/>
|
<label class="standard-label"><b><%= t 'issue.new.message' -%>: </b></label> <br/>
|
||||||
<%= text_area :report, :details, :cols => 80, :rows => 20, placeholder: t('issues.new.details'), required: true %>
|
<%= text_area :report, :details, :cols => 80, :rows => 20, placeholder: t('issues.new.details'), required: true %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -957,11 +957,48 @@ en-GB:
|
||||||
ignored: Issue status has been set to 'Ignored'
|
ignored: Issue status has been set to 'Ignored'
|
||||||
reopened: Issue status has been set to 'Open'
|
reopened: Issue status has been set to 'Open'
|
||||||
report_strings:
|
report_strings:
|
||||||
spam: is/contains spam
|
DiaryEntry:
|
||||||
offensive: is obscene/offensive
|
spam:
|
||||||
threat: contains a threat
|
type: "[SPAM]"
|
||||||
vandal: is a vandal
|
details: This Diary Entry is/contains spam
|
||||||
other: Other
|
offensive:
|
||||||
|
type: "[OFFENSIVE]"
|
||||||
|
details: This Diary Entry is obscene/offensive
|
||||||
|
threat:
|
||||||
|
type: "[THREAT]"
|
||||||
|
details: This Diary Entry contains a threat
|
||||||
|
other:
|
||||||
|
type: "[OTHER]"
|
||||||
|
details: Other
|
||||||
|
DiaryComment:
|
||||||
|
spam:
|
||||||
|
type: "[SPAM]"
|
||||||
|
details: This Diary Comment is/contains spam
|
||||||
|
offensive:
|
||||||
|
type: "[OFFENSIVE]"
|
||||||
|
details: This Diary Comment is obscene/offensive
|
||||||
|
threat:
|
||||||
|
type: "[THREAT]"
|
||||||
|
details: This Diary Comment contains a threat
|
||||||
|
other:
|
||||||
|
type: "[OTHER]"
|
||||||
|
details: Other
|
||||||
|
User:
|
||||||
|
spam:
|
||||||
|
type: "[SPAM]"
|
||||||
|
details: This User profile is/contains spam
|
||||||
|
offensive:
|
||||||
|
type: "[OFFENSIVE]"
|
||||||
|
details: This User profile is obscene/offensive
|
||||||
|
threat:
|
||||||
|
type: "[THREAT]"
|
||||||
|
details: This User profile contains a threat
|
||||||
|
vandal:
|
||||||
|
type: "[VANDAL]"
|
||||||
|
details: This User is a vandal
|
||||||
|
other:
|
||||||
|
type: "[OTHER]"
|
||||||
|
details: Other
|
||||||
layouts:
|
layouts:
|
||||||
project_name:
|
project_name:
|
||||||
title: OpenStreetMap
|
title: OpenStreetMap
|
||||||
|
|
|
@ -927,11 +927,48 @@ en:
|
||||||
ignored: Issue status has been set to 'Ignored'
|
ignored: Issue status has been set to 'Ignored'
|
||||||
reopened: Issue status has been set to 'Open'
|
reopened: Issue status has been set to 'Open'
|
||||||
report_strings:
|
report_strings:
|
||||||
spam: is/contains spam
|
DiaryEntry:
|
||||||
offensive: is obscene/offensive
|
spam:
|
||||||
threat: contains a threat
|
type: "[SPAM]"
|
||||||
vandal: is a vandal
|
details: This Diary Entry is/contains spam
|
||||||
other: Other
|
offensive:
|
||||||
|
type: "[OFFENSIVE]"
|
||||||
|
details: This Diary Entry is obscene/offensive
|
||||||
|
threat:
|
||||||
|
type: "[THREAT]"
|
||||||
|
details: This Diary Entry contains a threat
|
||||||
|
other:
|
||||||
|
type: "[OTHER]"
|
||||||
|
details: Other
|
||||||
|
DiaryComment:
|
||||||
|
spam:
|
||||||
|
type: "[SPAM]"
|
||||||
|
details: This Diary Comment is/contains spam
|
||||||
|
offensive:
|
||||||
|
type: "[OFFENSIVE]"
|
||||||
|
details: This Diary Comment is obscene/offensive
|
||||||
|
threat:
|
||||||
|
type: "[THREAT]"
|
||||||
|
details: This Diary Comment contains a threat
|
||||||
|
other:
|
||||||
|
type: "[OTHER]"
|
||||||
|
details: Other
|
||||||
|
User:
|
||||||
|
spam:
|
||||||
|
type: "[SPAM]"
|
||||||
|
details: This User profile is/contains spam
|
||||||
|
offensive:
|
||||||
|
type: "[OFFENSIVE]"
|
||||||
|
details: This User profile is obscene/offensive
|
||||||
|
threat:
|
||||||
|
type: "[THREAT]"
|
||||||
|
details: This User profile contains a threat
|
||||||
|
vandal:
|
||||||
|
type: "[VANDAL]"
|
||||||
|
details: This User is a vandal
|
||||||
|
other:
|
||||||
|
type: "[OTHER]"
|
||||||
|
details: Other
|
||||||
layouts:
|
layouts:
|
||||||
project_name:
|
project_name:
|
||||||
# in <title>
|
# in <title>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue