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
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
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
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
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 )
--- /dev/null
+class IssueComment < ActiveRecord::Base
+ belongs_to :issue
+ belongs_to :user
+
+ validates :body, :presence => true
+end
has_many :roles, :class_name => "UserRole"
has_many :issues
+ has_many :issue_comments
+
has_many :reports
scope :visible, -> { where(:status => %w(pending active confirmed)) }
<%= 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') } %>
--- /dev/null
+<% 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>
\ No newline at end of file
<% 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 %>
-<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 %>
\ No newline at end of file
<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? %>
<%= render 'reports',reports: @unread_reports %>
</div>
<% end %>
+<br/>
+<h3>Comments on this issue:</h3>
+ <div class="unread-reports">
+ <%= render 'comments', comments: @comments %>
+ </div>
post "reopen"
end
end
+
+ post '/comment' => 'issues#comment'
# redactions
resources :redactions
--- /dev/null
+class CreateIssueComments < ActiveRecord::Migration
+ def change
+ create_table :issue_comments do |t|
+ t.integer :issue_id
+ t.integer :user_id
+ t.text :body
+ t.datetime :created_at
+
+ t.timestamps null: false
+ end
+ end
+end
--- /dev/null
+require "migrate"
+
+class AddForeignKeysForIssues < ActiveRecord::Migration
+ def change
+ add_foreign_key :issues, :users, :name => "issues_user_id_fkey"
+ add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey"
+ add_foreign_key :reports, :users, :name => "reports_user_id_fkey"
+ add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey"
+ add_foreign_key :issue_comments, :users, :name => "issue_comments_user_id"
+ end
+end
--- /dev/null
+class AddIndexesForIssues < ActiveRecord::Migration
+ def self.up
+ add_index :issues, :user_id
+ add_index :issues, [:reportable_id, :reportable_type]
+ add_index :reports, :issue_id
+ add_index :reports, :user_id
+ add_index :issue_comments, :user_id
+ add_index :issue_comments, :issue_id
+ end
+
+ def self.down
+ remove_index :issues, :user_id
+ remove_index :issues, [:reportable_id, :reportable_type]
+ remove_index :reports, :issue_id
+ remove_index :reports, :user_id
+ remove_index :issue_comments, :user_id
+ remove_index :issue_comments, :issue_id
+ end
+end
ALTER SEQUENCE gpx_files_id_seq OWNED BY gpx_files.id;
+--
+-- Name: issue_comments; Type: TABLE; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE TABLE issue_comments (
+ id integer NOT NULL,
+ issue_id integer,
+ user_id integer,
+ body text,
+ created_at timestamp without time zone NOT NULL,
+ updated_at timestamp without time zone NOT NULL
+);
+
+
+--
+-- Name: issue_comments_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE issue_comments_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+
+--
+-- Name: issue_comments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE issue_comments_id_seq OWNED BY issue_comments.id;
+
+
--
-- Name: issues; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY gpx_files ALTER COLUMN id SET DEFAULT nextval('gpx_files_id_seq'::regclass);
+--
+-- Name: id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY issue_comments ALTER COLUMN id SET DEFAULT nextval('issue_comments_id_seq'::regclass);
+
+
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ADD CONSTRAINT gpx_files_pkey PRIMARY KEY (id);
+--
+-- Name: issue_comments_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
+--
+
+ALTER TABLE ONLY issue_comments
+ ADD CONSTRAINT issue_comments_pkey PRIMARY KEY (id);
+
+
--
-- Name: issues_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX index_client_applications_on_key ON client_applications USING btree (key);
+--
+-- Name: index_issue_comments_on_issue_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_issue_comments_on_issue_id ON issue_comments USING btree (issue_id);
+
+
+--
+-- Name: index_issue_comments_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_issue_comments_on_user_id ON issue_comments USING btree (user_id);
+
+
+--
+-- Name: index_issues_on_reportable_id_and_reportable_type; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_issues_on_reportable_id_and_reportable_type ON issues USING btree (reportable_id, reportable_type);
+
+
+--
+-- Name: index_issues_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_issues_on_user_id ON issues USING btree (user_id);
+
+
--
-- Name: index_note_comments_on_body; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_oauth_tokens_on_token ON oauth_tokens USING btree (token);
+--
+-- Name: index_reports_on_issue_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_reports_on_issue_id ON reports USING btree (issue_id);
+
+
+--
+-- Name: index_reports_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_reports_on_user_id ON reports USING btree (user_id);
+
+
--
-- Name: index_user_blocks_on_user_id; Type: INDEX; Schema: public; Owner: -
--
ADD CONSTRAINT gpx_files_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id);
+--
+-- Name: issue_comments_issue_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY issue_comments
+ ADD CONSTRAINT issue_comments_issue_id_fkey FOREIGN KEY (issue_id) REFERENCES issues(id);
+
+
+--
+-- Name: issue_comments_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY issue_comments
+ ADD CONSTRAINT issue_comments_user_id FOREIGN KEY (user_id) REFERENCES users(id);
+
+
+--
+-- Name: issues_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY issues
+ ADD CONSTRAINT issues_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id);
+
+
--
-- Name: messages_from_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ADD CONSTRAINT relations_redaction_id_fkey FOREIGN KEY (redaction_id) REFERENCES redactions(id);
+--
+-- Name: reports_issue_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY reports
+ ADD CONSTRAINT reports_issue_id_fkey FOREIGN KEY (issue_id) REFERENCES issues(id);
+
+
+--
+-- Name: reports_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY reports
+ ADD CONSTRAINT reports_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id);
+
+
--
-- Name: user_blocks_moderator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
INSERT INTO schema_migrations (version) VALUES ('20150516075620');
+INSERT INTO schema_migrations (version) VALUES ('20150526130032');
+
+INSERT INTO schema_migrations (version) VALUES ('20150528113100');
+
+INSERT INTO schema_migrations (version) VALUES ('20150528114520');
+
INSERT INTO schema_migrations (version) VALUES ('21');
INSERT INTO schema_migrations (version) VALUES ('22');
--- /dev/null
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ issue_id: 1
+ user_id: 1
+ body: MyText
+ created_at: 2015-05-26 18:30:32
+
+two:
+ issue_id: 1
+ user_id: 1
+ body: MyText
+ created_at: 2015-05-26 18:30:32
--- /dev/null
+require 'test_helper'
+
+class IssueCommentTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end