Added IssueComments + ForeignKeys + Indexes
This commit is contained in:
parent
d49922eb63
commit
683722ed5c
16 changed files with 285 additions and 18 deletions
|
@ -2,7 +2,8 @@ class IssuesController < ApplicationController
|
|||
layout "site"
|
||||
|
||||
before_action :authorize_web
|
||||
before_action :check_permission, only: [:index, :show, :resolve,:open,:ignore]
|
||||
before_action :require_user
|
||||
before_action :check_permission, only: [:index, :show, :resolve,:open,:ignore,:comment]
|
||||
before_action :find_issue, only: [:show, :resolve, :reopen, :ignore]
|
||||
|
||||
def index
|
||||
|
@ -12,11 +13,13 @@ class IssuesController < ApplicationController
|
|||
def show
|
||||
@read_reports = @issue.read_reports
|
||||
@unread_reports = @issue.unread_reports
|
||||
@comments = @issue.comments
|
||||
end
|
||||
|
||||
def new
|
||||
unless create_new_issue_params.blank?
|
||||
@issue = Issue.find_or_initialize_by(create_new_issue_params)
|
||||
puts params[:user_id].to_s + "--------------"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -25,20 +28,27 @@ class IssuesController < ApplicationController
|
|||
if !@issue
|
||||
@issue = Issue.find_or_initialize_by(issue_params)
|
||||
@admins = UserRole.where(role: "administrator")
|
||||
@admins.each do |user|
|
||||
Notifier.new_issue_notification(User.find(user.user_id)).deliver_now
|
||||
@admins.each do |admin|
|
||||
Notifier.new_issue_notification(User.find(admin.user_id)).deliver_now
|
||||
end
|
||||
end
|
||||
|
||||
@report = @issue.reports.build(report_params)
|
||||
|
||||
if @issue.save
|
||||
redirect_to @issue, notice: 'Issue was successfully created.'
|
||||
@report.user_id = @user.id
|
||||
if @issue.save!
|
||||
redirect_to root_path, notice: 'Issue was successfully created.'
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def comment
|
||||
@issue = Issue.find(params[:id])
|
||||
@issue_comment = @issue.comments.build(issue_comment_params)
|
||||
@issue_comment.user_id = @user.id
|
||||
@issue_comment.save!
|
||||
redirect_to @issue
|
||||
end
|
||||
|
||||
# Status Transistions
|
||||
def resolve
|
||||
if @issue.resolve
|
||||
|
@ -85,10 +95,14 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
|
||||
def issue_params
|
||||
params[:issue].permit(:reportable_id, :reportable_type,:user_id)
|
||||
params.permit(:reportable_id, :reportable_type,:user_id)
|
||||
end
|
||||
|
||||
def report_params
|
||||
params[:report].permit(:details, :user_id)
|
||||
params[:report].permit(:details)
|
||||
end
|
||||
|
||||
def issue_comment_params
|
||||
params.require(:issue_comment).permit(:body, :user_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
class Issue < ActiveRecord::Base
|
||||
belongs_to :reportable, :polymorphic => true
|
||||
has_many :reports
|
||||
has_many :comments, :class_name => "IssueComment"
|
||||
validates :reportable_id, :uniqueness => { :scope => [ :reportable_type ] }
|
||||
belongs_to :user
|
||||
validates :user_id, :presence => true
|
||||
|
||||
# Check if more statuses are needed
|
||||
enum status: %w( open ignored resolved )
|
||||
|
|
6
app/models/issue_comment.rb
Normal file
6
app/models/issue_comment.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
class IssueComment < ActiveRecord::Base
|
||||
belongs_to :issue
|
||||
belongs_to :user
|
||||
|
||||
validates :body, :presence => true
|
||||
end
|
|
@ -27,6 +27,8 @@ class User < ActiveRecord::Base
|
|||
has_many :roles, :class_name => "UserRole"
|
||||
|
||||
has_many :issues
|
||||
has_many :issue_comments
|
||||
|
||||
has_many :reports
|
||||
|
||||
scope :visible, -> { where(:status => %w(pending active confirmed)) }
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<%= link_to t('diary_entry.diary_entry.edit_link'), :action => 'edit', :display_name => diary_entry.user.display_name, :id => diary_entry.id %>
|
||||
<% end %>
|
||||
|
||||
<li><%= link_to 'Report', new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, user: diary_entry.user.id) %></li>
|
||||
<li><%= link_to 'Report', new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, user_id: diary_entry.user.id) %></li>
|
||||
|
||||
<%= if_administrator(:li) do %>
|
||||
<%= link_to t('diary_entry.diary_entry.hide_link'), hide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t('diary_entry.diary_entry.confirm') } %>
|
||||
|
|
18
app/views/issues/_comments.html.erb
Normal file
18
app/views/issues/_comments.html.erb
Normal file
|
@ -0,0 +1,18 @@
|
|||
<% comments.each do |comment| %>
|
||||
<div class="comment">
|
||||
<div style="float:left">
|
||||
<%= link_to user_thumbnail(comment.user), :controller => :user,:action =>:view, :display_name => comment.user.display_name %>
|
||||
</div>
|
||||
<b> <%= link_to comment.user.display_name, :controller => :user,:action =>:view, :display_name => comment.user.display_name %> </b> <br/>
|
||||
<%= comment.body %>
|
||||
</div>
|
||||
<span class="deemphasize">
|
||||
On <%= l comment.created_at.to_datetime, :format => :long %> </span>
|
||||
<hr>
|
||||
<% end %>
|
||||
<div class="comment">
|
||||
<%= form_for :issue_comment, :url => { :action => 'comment', :id => @issue.id, :user_id => @user.id } do |f| %>
|
||||
<%= richtext_area :issue_comment, :body, :cols => 80, :rows => 8 %>
|
||||
<%= submit_tag 'Submit' %>
|
||||
<% end %>
|
||||
</div>
|
|
@ -1,11 +1,13 @@
|
|||
<% reports.each do |report| %>
|
||||
<div class="reports">
|
||||
<div class="display:inline">
|
||||
<%= user_thumbnail report.user %>
|
||||
<%= report.details %>
|
||||
<div style="float:left">
|
||||
<%= link_to user_thumbnail(report.user), :controller => :user,:action =>:view, :display_name => report.user.display_name %>
|
||||
</div>
|
||||
<span class="deemphasize"><%= raw(t('Reported by:',:link_user => (link_to h(report.user.display_name), :controller => :user, :action => :view, :display_name => report.user.display_name), :comment_created_at => link_to(l(report.created_at,:format => :friendly)))) %>
|
||||
on <%= l report.created_at.to_datetime, :format => :long %> </span>
|
||||
<b><%= link_to report.user.display_name, :controller => :user,:action =>:view, :display_name => report.user.display_name %></b> <br/>
|
||||
<%= report.details %>
|
||||
<br/>
|
||||
<span class="deemphasize">
|
||||
On <%= l report.created_at.to_datetime, :format => :long %> </span>
|
||||
</div>
|
||||
<hr>
|
||||
<% end %>
|
||||
|
|
|
@ -1,2 +1,21 @@
|
|||
<h1>Issues#new</h1>
|
||||
<p>Find me in app/views/issues/new.html.erb</p>
|
||||
<% content_for :heading do %>
|
||||
<h1>Report a new Issue for <%= reportable_url(@issue.reportable) %></h1>
|
||||
<% end %>
|
||||
|
||||
<%= form_for(@issue) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<fieldset>
|
||||
<div class='form-row'>
|
||||
<%= f.hidden_field :reportable_id, :value => params[:reportable_id] %>
|
||||
<%= f.hidden_field :reportable_type, :value => params[:reportable_type] %>
|
||||
<%= f.hidden_field :user_id, :value => params[:user_id] %>
|
||||
</div>
|
||||
<div class='form-row'>
|
||||
<label class="standard-label"><%= t 'issue.new.message' -%></label>
|
||||
<%= text_area :report, :details, :cols => 80, :rows => 20, placeholder: "Tell us what's wrong! Any information you can give will go on to help moderators a long way." %>
|
||||
</div>
|
||||
<div class='buttons'>
|
||||
<%= submit_tag %>
|
||||
</div>
|
||||
</fieldset>
|
||||
<% end %>
|
|
@ -11,7 +11,6 @@
|
|||
<p><%= link_to "Ignore", ignore_issue_url(@issue), :method => :post if @issue.may_ignore? %></p>
|
||||
<p><%= link_to "Reopen", reopen_issue_url(@issue), :method => :post if @issue.may_reopen? %></p>
|
||||
<% end %>
|
||||
|
||||
<h3>Reports under this issue:</h3>
|
||||
|
||||
<% if @read_reports.present? %>
|
||||
|
@ -27,3 +26,8 @@
|
|||
<%= render 'reports',reports: @unread_reports %>
|
||||
</div>
|
||||
<% end %>
|
||||
<br/>
|
||||
<h3>Comments on this issue:</h3>
|
||||
<div class="unread-reports">
|
||||
<%= render 'comments', comments: @comments %>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue