before_action :authorize_web
before_action :require_user
+ before_action :set_issues
before_action :check_permission, only: [:index, :show, :resolve,:open,:ignore,:comment]
before_action :find_issue, only: [:show, :resolve, :reopen, :ignore]
before_action :get_user_role, only: [:show, :index]
+ helper_method :sort_column, :sort_direction
+
def index
+ if @user.moderator?
+ @issue_types = @moderator_issues
+ else
+ @issue_types = @admin_issues
+ end
+
+ @issues = Issue.where(issue_type: @user_role).order(sort_column + " " + sort_direction)
+
# If search
- if params[:search_by_user]
+ if params[:search_by_user] and !params[:search_by_user].blank?
@find_user = User.find_by_display_name(params[:search_by_user])
if @find_user
- @issues = Issue.where(reported_user_id: @find_user.id, issue_type: @user_role).order(:status)
+ @issues = @issues.where(reported_user_id: @find_user.id)
else
- @issues = Issue.where(issue_type: @user_role).order(:status)
notice = t('issues.index.search.user_not_found')
end
+ end
- if @find_user !=nil and @issues.first == nil
- @issues = Issue.where(issue_type: @user_role).order(:status)
- notice = t('issues.index.search.issues_not_found')
- end
- if notice
- redirect_to issues_path, notice: notice
- end
-
- else
- @issues = Issue.where(issue_type: @user_role).order(:status)
+ if params[:status] and !params[:status][0].blank?
+ @issues = @issues.where(status: params[:status][0].to_i)
+ end
+
+ if params[:issue_type] and !params[:issue_type][0].blank?
+ @issues = @issues.where(reportable_type: params[:issue_type][0])
+ end
+
+ if @issues.first == nil
+ notice = t('issues.index.search.issues_not_found')
end
+
+ if notice
+ redirect_to issues_path, notice: notice
+ end
end
def show
end
def create
-
- # TODO: Find better place to add these
- admin_issues = [ 'DiaryEntry', 'DiaryComment', 'User']
- moderator_issues = [ 'Changeset' ]
-
-
@issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
- # Check if Issue alrwady exists
+ # Check if Issue already exists
if !@issue
@issue = Issue.find_or_initialize_by(issue_params)
@issue.updated_by = nil
# Reassign to moderators if it is a moderator issue
@issue.issue_type = "administrator"
- if moderator_issues.include? @issue.reportable.class.name
+ if @moderator_issues.include? @issue.reportable.class.name
reassign_issue
end
details = get_report_details
@report.reporter_user_id = @user.id
@report.details = details
-
# Checking if instance has been updated since last report
@last_report = @issue.reports.order(updated_at: :desc).last
if check_if_updated
end
if @issue.save!
+ @issue.report_count = @issue.reports.count
+ @issue.save!
redirect_to root_path, notice: t('issues.create.successful_report')
end
else
notice = t('issues.update.successful_update')
end
+
if @report.save!
+ @issue.report_count = @issue.reports.count
+ @issue.save!
redirect_to root_path, notice: notice
end
else
private
+ def set_issues
+ @admin_issues = [ 'DiaryEntry', 'DiaryComment', 'User']
+ @moderator_issues = [ 'Changeset', 'Note' ]
+ end
+
def get_user_role
# Get user role
if @user.administrator?
end
def check_if_updated
- if @issue.reportable and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
+ if @issue.reportable and (@issue.ignored? or @issue.resolved?) and @issue.reportable.has_attribute?(:updated_by) and @issue.reportable.updated_at > @last_report.updated_at
return true
else
return false
params.require(:issue_comment).permit(:body)
end
+ def sort_column
+ Issue.column_names.include?(params[:sort]) ? params[:sort] : "status"
+ end
+
+ def sort_direction
+ %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
+ end
end
case class_name
when "DiaryEntry"
link_to reportable.title, :controller => reportable.class.name.underscore,
- :action => :view,
- :display_name => reportable.user.display_name,
- :id => reportable.id
+ :action => :view,
+ :display_name => reportable.user.display_name,
+ :id => reportable.id
when "User"
link_to reportable.display_name.to_s, :controller => reportable.class.name.underscore,
- :action => :view,
- :display_name => reportable.display_name
+ :action => :view,
+ :display_name => reportable.display_name
when "DiaryComment"
link_to "#{reportable.diary_entry.title}, Comment id ##{reportable.id}", :controller => reportable.diary_entry.class.name.underscore,
:action => :view,
:comment_id => reportable.id
when "Changeset"
link_to "Changeset ##{reportable.id}", :controller => :browse,
- :action => :changeset,
- :id => reportable.id
+ :action => :changeset,
+ :id => reportable.id
+ when "Note"
+ link_to "Note ##{reportable.id}", :controller => :browse,
+ :action => :note,
+ :id => reportable.id
else
nil
end
end
+
+ def reports_url(issue)
+ class_name = issue.reportable.class.name
+ case class_name
+ when "DiaryEntry"
+ link_to issue.reportable.title, issue
+ when "User"
+ link_to issue.reportable.display_name.to_s, issue
+ when "DiaryComment"
+ link_to "#{issue.reportable.diary_entry.title}, Comment id ##{issue.reportable.id}", issue
+ when "Changeset"
+ link_to "Changeset ##{issue.reportable.id}",issue
+ when "Note"
+ link_to "Note ##{issue.reportable.id}", issue
+ else
+ nil
+ end
+ end
+
+ def instance_url(reportable)
+ class_name = reportable.class.name
+ case class_name
+ when "DiaryEntry"
+ link_to "Show Instance", :controller => reportable.class.name.underscore,
+ :action => :view,
+ :display_name => reportable.user.display_name,
+ :id => reportable.id
+ when "User"
+ link_to "Show Instance", :controller => reportable.class.name.underscore,
+ :action => :view,
+ :display_name => reportable.display_name
+ when "DiaryComment"
+ link_to "Show Instance", :controller => reportable.diary_entry.class.name.underscore,
+ :action => :view,
+ :display_name => reportable.diary_entry.user.display_name,
+ :id => reportable.diary_entry.id,
+ :comment_id => reportable.id
+ when "Changeset"
+ link_to "Show Instance", :controller => :browse,
+ :action => :changeset,
+ :id => reportable.id
+ when "Note"
+ link_to "Show Instance", :controller => :browse,
+ :action => :note,
+ :id => reportable.id
+ else
+ nil
+ end
+ end
+
+ def sortable(column,title=nil)
+ title ||= column.titleize
+ direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
+ if column == sort_column
+ arrow = direction == "desc" ? ["25B2".hex].pack("U") : ["25BC".hex].pack("U")
+ title = title + arrow
+ end
+ link_to title, params.merge(:sort => column, :direction => direction)
+ end
end
class Issue < ActiveRecord::Base
belongs_to :reportable, :polymorphic => true
belongs_to :user, :class_name => "User", :foreign_key => :reported_user_id
+ belongs_to :user_updated, :class_name => "User", :foreign_key => :updated_by
has_many :reports, dependent: :destroy
has_many :comments, :class_name => "IssueComment", dependent: :destroy
has_many :roles, :class_name => "UserRole"
has_many :issues, :class_name => "Issue", :foreign_key => :reported_user_id
+ has_one :issue, :class_name => "Issue", :foreign_key => :updated_by
has_many :issue_comments
has_many :reports
<h2>
<a class="geolink" href="<%= root_path %>"><span class="icon close"></span></a>
+ <% if @user and @user.id!=@note.author.id %>
+ <div class="report-button">
+ <%= link_to new_issue_url(reportable_id: @note.id, reportable_type: @note.class.name, reported_user_id: @note.author.id), :title => t('browse.note.report') do %>
+ <%= image_tag('notice.png', size: '10x10') %>
+ <% end %>
+ </div>
+ <% end %>
<%= t "browse.note.#{@note.status}_title", :note_name => @note.id %>
</h2>
<% end %>
<%= form_tag(issues_path, :method => :get) do %>
- <%= text_field_tag :search_by_user, params[:search_by_user], placeholder: "Search by Reported User" %>
+ Search for a particular issue(s):
+ <%= select :status, nil, [['open', 0],['resolved',2],['ignored',1]],{:include_blank => "Select status"},data: { behavior: 'category_dropdown' } %>
+ <%= select :issue_type, nil, @issue_types,{:include_blank => "Select type"},data: { behavior: 'category_dropdown' } %>
+ <%= text_field_tag :search_by_user, params[:search_by_user], placeholder: "Reported User" %>
<%= submit_tag "Search" %>
<% end %>
<br/>
<thead>
<tr>
<tr>
- <td><b> Status </b></td>
- <td><b> Number of Reports</b></td>
- <td><b> Last updated at</b></td>
- <td><b> Link to instance </b></td>
- <td><b> Reported User </b></td>
- <td></td>
+ <td><b> <%= sortable("status") %></b></td>
+ <td><b> <%= sortable("report_count", "Number of Reports") %></b></td>
+ <td><b> <%= sortable("updated_at","Last updated at") %></b></td>
+ <td><b> <%= sortable("updated_by","Last updated by") %></b></td>
+ <td><b> Link to reports </b></td>
+ <td><b> <%= sortable("reported_user_id","Reported User") %> </b></td>
+ <td><b> Link to reported instance</b></td>
</tr>
</tr>
</thead>
<% @issues.each do |issue| %>
<tr>
<td><span class="count-number"> <strong><%= issue.status %></strong></span> </td>
- <td><%= issue.reports.count %></td>
- <td><%= issue.updated_at.strftime('%H:%M, %m/%d/%y') %></td>
- <td> <%= reportable_url(issue.reportable) %></td>
+ <td><%= issue.report_count %></td>
+ <td><%= issue.updated_at.strftime('%H:%M %m/%d/%y') %></td>
+ <td><% if issue.user_updated %> <%= issue.user_updated.display_name %> <% else %> - <% end %></td>
+ <td> <%= reports_url(issue) %></td>
<td><%= link_to issue.user.display_name , :controller => :user, :action => :view,:display_name => issue.user.display_name %></td>
- <td><b><%= link_to "Show Reports", issue %></b></td>
+ <td><%= instance_url(issue.reportable) %></td>
</tr>
<% end %>
</tbody>
<% if @related_issues.count > 1 %>
<% @related_issues.each do |issue| %>
<% if issue.id != @issue.id %>
- <%= link_to "#{issue.reportable_type} ##{issue.reportable_id}", issue %> <br/>
+ <%= reports_url(issue) %> <br/>
<% end %>
<% end %>
<% else %>
reopened_by_anonymous: Reactivated by anonymous <abbr title='%{exact_time}'>%{when}
ago</abbr>
hidden_by: Hidden by %{user} <abbr title='%{exact_time}'>%{when} ago</abbr>
+ report: Report this note?
query:
title: Query Features
introduction: Click on the map to find nearby features.
resolve: Resolve
ignore: Ignore
reopen: Reopen
- index:
+ index:
search:
user_not_found: User does not exist
- issues_not_found: No Issues against the user
+ issues_not_found: No such issues found
create:
successful_report: Your report has been registered sucessfully
provide_details: Please provide the required details
reopened_by: "Reactivated by %{user} <abbr title='%{exact_time}'>%{when} ago</abbr>"
reopened_by_anonymous: "Reactivated by anonymous <abbr title='%{exact_time}'>%{when} ago</abbr>"
hidden_by: "Hidden by %{user} <abbr title='%{exact_time}'>%{when} ago</abbr>"
+ report: Report this note?
query:
title: "Query Features"
introduction: "Click on the map to find nearby features."
index:
search:
user_not_found: User does not exist
- issues_not_found: No Issues against the user
+ issues_not_found: No such issues found
create:
successful_report: Your report has been registered sucessfully
provide_details: Please provide the required details
--- /dev/null
+class AddReportCountToIssues < ActiveRecord::Migration
+ def change
+ add_column :issues, :report_count, :integer, :default => 0
+ add_foreign_key :issues, :users, :column => :updated_by, :name => "issues_updated_by_fkey", on_delete: :cascade
+ add_index :issues, :updated_by
+ end
+end
resolved_by integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
- updated_by integer
+ updated_by integer,
+ report_count integer DEFAULT 0
);
CREATE INDEX index_issues_on_reported_user_id ON issues USING btree (reported_user_id);
+--
+-- Name: index_issues_on_updated_by; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_issues_on_updated_by ON issues USING btree (updated_by);
+
+
--
-- Name: index_note_comments_on_body; Type: INDEX; Schema: public; Owner: -
--
ADD CONSTRAINT issues_reported_user_id_fkey FOREIGN KEY (reported_user_id) REFERENCES users(id) ON DELETE CASCADE;
+--
+-- Name: issues_updated_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY issues
+ ADD CONSTRAINT issues_updated_by_fkey FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE CASCADE;
+
+
--
-- Name: messages_from_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
INSERT INTO schema_migrations (version) VALUES ('20150526130032');
+INSERT INTO schema_migrations (version) VALUES ('20150719160821');
+
INSERT INTO schema_migrations (version) VALUES ('21');
INSERT INTO schema_migrations (version) VALUES ('22');