.issue-comments {
width:475px;
+}
+
+.new-report-form {
+ border:1px solid #ccc;
+ border-radius:4px;
+ display:block-inline;
+}
+
+.new-report-checkbox{
+ float:left;
+ margin-left:10px;
+ margin-top:3px;
+}
+
+.new-report-string {
+ text-align:center;
+ font-size:15px;
}
\ No newline at end of file
end
end
@report = @issue.reports.build(report_params)
- @report.user_id = @user.id
+ 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
+ @report.reporter_user_id = @user.id
+ @report.details = details
if @issue.save!
redirect_to root_path, notice: 'Your report has been registered sucessfully.'
else
end
end
+ def update
+ @issue = Issue.find_by(issue_params)
+ @report = @issue.reports.where(reporter_user_id: @user.id).first
+ 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
+ @report.details = details
+ if @report.save!
+ redirect_to root_path, notice: 'Your report was successfully updated.'
+ else
+ render :edit
+ 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.commenter_user_id = @user.id
@issue_comment.save!
redirect_to @issue
end
end
def issue_comment_params
- params.require(:issue_comment).permit(:body, :user_id)
+ params.require(:issue_comment).permit(:body)
end
end
class IssueComment < ActiveRecord::Base
belongs_to :issue
- belongs_to :user
+ belongs_to :user, :class_name => "User", :foreign_key => :commenter_user_id
validates :body, :presence => true
end
class Report < ActiveRecord::Base
belongs_to :issue
- belongs_to :user
+ belongs_to :user, :class_name => "User", :foreign_key => :reporter_user_id
end
<%= if_administrator(:span) do %>
<%= link_to t('diary_entry.diary_comment.hide_link'), hide_diary_comment_path(:display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id), :method => :post, :data=> { :confirm => t('diary_entry.diary_comment.confirm') } %> |
<% end %>
- <%= link_to 'Report', new_issue_url(reportable_id: diary_comment.id, reportable_type: diary_comment.class.name, reported_user_id: diary_comment.user.id) %>
+ <% if @user and diary_comment.user.id != @user.id %>
+ <%= link_to 'Report', new_issue_url(reportable_id: diary_comment.id, reportable_type: diary_comment.class.name, reported_user_id: diary_comment.user.id) %>
+ <% end %>
</div>
<%= 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, reported_user_id: diary_entry.user.id) %></li>
-
+ <li>
+ <% if @user and diary_entry.user.id != @user.id %>
+ <%= link_to 'Report', new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, reported_user_id: diary_entry.user.id) %>
+ <% end %>
+ </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') } %>
<% end %>
<%= link_to user_thumbnail(report.user), :controller => :user,:action =>:view, :display_name => report.user.display_name %>
</div>
<b><%= link_to report.user.display_name, :controller => :user,:action =>:view, :display_name => report.user.display_name %></b> <br/>
- <%= report.details %>
+ <% details = report.details.split("||") %>
+ <%= details[0] %>
+ <br/>
+ <br/>
+ <label>Tags:</label>
+ <% details[1..(details.size-1)].each do |tags| %>
+ <%= tags %>
+ <% end %>
<br/>
<span class="deemphasize">
On <%= l report.created_at.to_datetime, :format => :long %> </span>
<%= f.hidden_field :reportable_type %>
<%= f.hidden_field :reported_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." %>
+ <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} is/contains spam." %> <br/>
+ </div>
+ </div>
+ <br/>
+
+ <div class="new-report-form">
+ <div class="new-report-checkbox">
+ <%= check_box_tag :offensive, "[OFFENSIVE]" %>
+ </div>
+ <div class="new-report-string">
+ <%= label_tag "This #{@issue.reportable.class.name} is obscene/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} contains a threat." %> <br/>
+ </div>
+ </div>
+ <br/>
+
+ <% if @issue.reportable.class.name == "User" %>
+ <div class="new-report-form">
+ <div class="new-report-checkbox">
+ <%= check_box_tag :vandal, "[VANDAL]" %>
+ </div>
+ <div class="new-report-string">
+ <%= label_tag "This #{@issue.reportable.class.name} is a vandal." %> <br/>
+ </div>
+ </div>
+ <br/>
+ <% end %>
+
+ <div class="new-report-form">
+ <div class="new-report-checkbox">
+ <%= check_box_tag :other, "[OTHER]" %>
+ </div>
+ <div class="new-report-string">
+ <%= label_tag "Other." %> <br/>
+ </div>
+ </div>
+ <br/>
+
+ <label class="standard-label"><b><%= t 'issue.new.message' -%>: </b></label> <br/>
+ <%= text_area :report, :details, :cols => 80, :rows => 20, placeholder: "Please provide some more details into the problem. (This field cannot be left blank!)" %>
</div>
+
<div class='buttons'>
<%= submit_tag %>
</div>
+
</fieldset>
<% end %>
\ No newline at end of file
<% if @related_issues.count > 1 %>
<% @related_issues.each do |issue| %>
<% if issue.id != @issue.id %>
- <%= link_to "#{issue.reportable_type} ##{issue.reportable_id}", issue %>
+ <%= link_to "#{issue.reportable_type} ##{issue.reportable_id}", issue %> <br/>
<% end %>
<% end %>
<% else %>
require "migrate"
-class CreateIssues < ActiveRecord::Migration
+class CreateIssuesAndReports < ActiveRecord::Migration
def change
create_table :issues do |t|
t.string :reportable_type, :null => false
add_index :issues, :reported_user_id
add_index :issues, [:reportable_id, :reportable_type]
+
+ create_table :reports do |t|
+ t.integer :issue_id
+ t.integer :reporter_user_id
+ t.text :details
+ t.datetime :created_at
+ t.datetime :updated_at
+
+ t.timestamps null: false
+ end
+
+ add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey"
+ add_foreign_key :reports, :users,:column => :reporter_user_id, :name => "reports_reporter_user_id_fkey"
+
+ add_index :reports, :reporter_user_id
+ add_index :reports, :issue_id
end
end
+++ /dev/null
-class CreateReports < ActiveRecord::Migration
- def change
- create_table :reports do |t|
- t.integer :issue_id
- t.integer :user_id
- t.text :details
- t.datetime :created_at
- t.datetime :updated_at
-
- t.timestamps null: false
- end
-
- add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey"
- add_foreign_key :reports, :users, :name => "reports_user_id_fkey"
-
- add_index :reports, :issue_id
- add_index :reports, :user_id
-
- end
-end
def change
create_table :issue_comments do |t|
t.integer :issue_id
- t.integer :user_id
+ t.integer :commenter_user_id
t.text :body
t.datetime :created_at
end
add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey"
- add_foreign_key :issue_comments, :users, :name => "issue_comments_user_id"
+ add_foreign_key :issue_comments, :users,:column => :commenter_user_id, :name => "issue_comments_commenter_user_id"
- add_index :issue_comments, :user_id
+ add_index :issue_comments, :commenter_user_id
add_index :issue_comments, :issue_id
end
CREATE TABLE issue_comments (
id integer NOT NULL,
issue_id integer,
- user_id integer,
+ commenter_user_id integer,
body text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
CREATE TABLE reports (
id integer NOT NULL,
issue_id integer,
- user_id integer,
+ reporter_user_id integer,
details text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
--
--- Name: index_issue_comments_on_issue_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+-- Name: index_issue_comments_on_commenter_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
-CREATE INDEX index_issue_comments_on_issue_id ON issue_comments USING btree (issue_id);
+CREATE INDEX index_issue_comments_on_commenter_user_id ON issue_comments USING btree (commenter_user_id);
--
--- Name: index_issue_comments_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+-- Name: index_issue_comments_on_issue_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
-CREATE INDEX index_issue_comments_on_user_id ON issue_comments USING btree (user_id);
+CREATE INDEX index_issue_comments_on_issue_id ON issue_comments USING btree (issue_id);
--
--
--- Name: index_reports_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+-- Name: index_reports_on_reporter_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
-CREATE INDEX index_reports_on_user_id ON reports USING btree (user_id);
+CREATE INDEX index_reports_on_reporter_user_id ON reports USING btree (reporter_user_id);
--
--
--- Name: issue_comments_issue_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
+-- Name: issue_comments_commenter_user_id; 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);
+ ADD CONSTRAINT issue_comments_commenter_user_id FOREIGN KEY (commenter_user_id) REFERENCES users(id);
--
--- Name: issue_comments_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
+-- Name: issue_comments_issue_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY issue_comments
- ADD CONSTRAINT issue_comments_user_id FOREIGN KEY (user_id) REFERENCES users(id);
+ ADD CONSTRAINT issue_comments_issue_id_fkey FOREIGN KEY (issue_id) REFERENCES issues(id);
--
--
--- Name: reports_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
+-- Name: reports_reporter_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);
+ ADD CONSTRAINT reports_reporter_user_id_fkey FOREIGN KEY (reporter_user_id) REFERENCES users(id);
--
INSERT INTO schema_migrations (version) VALUES ('20150516073616');
-INSERT INTO schema_migrations (version) VALUES ('20150516075620');
-
INSERT INTO schema_migrations (version) VALUES ('20150526130032');
INSERT INTO schema_migrations (version) VALUES ('21');
# Create Issue
- get :new, {reportable_id: 1, reportable_type: "DiaryEntry", user: 1}
+ get :new, {reportable_id: 1, reportable_type: "DiaryEntry", reported_user_id: 1}
assert_response :success
assert_difference "Issue.count",1 do
details = "Details of a report"
- post :create, { :report => { :deatils => details},
+ post :create, { :report => { :details => details},
:issue => { reportable_id: 1, reportable_type: "DiaryEntry", reported_user_id: 1} }
end
assert_response :redirect
# Create Issue
- get :new, {reportable_id: 1, reportable_type: "DiaryEntry", user: 1}
+ get :new, {reportable_id: 1, reportable_type: "DiaryEntry", reported_user_id: 1}
assert_response :success
assert_difference "Issue.count",1 do
details = "Details of a report"
- post :create, { :report => { :deatils => details},
+ post :create, { :report => { :details => details},
:issue => { reportable_id: 1, reportable_type: "DiaryEntry", reported_user_id: 1} }
end
assert_response :redirect