From: Shrey Date: Thu, 4 Jun 2015 18:56:24 +0000 (+0530) Subject: Fixed tests + Altered migration file + Added reporting strings + Added update method X-Git-Tag: live~2953^2~150 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/d5f02968f6f2dd153c74844e818a4d2b2ae24991 Fixed tests + Altered migration file + Added reporting strings + Added update method --- diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index b658e4e32..9a7785678 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -2761,4 +2761,21 @@ input.richtext_title[type="text"] { .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 diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index c1c5dd4f3..3cd0ceda0 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -33,7 +33,9 @@ class IssuesController < ApplicationController 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 @@ -41,10 +43,22 @@ class IssuesController < ApplicationController 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 @@ -103,6 +117,6 @@ class IssuesController < ApplicationController end def issue_comment_params - params.require(:issue_comment).permit(:body, :user_id) + params.require(:issue_comment).permit(:body) end end diff --git a/app/models/issue_comment.rb b/app/models/issue_comment.rb index 455fb040b..866a85b84 100644 --- a/app/models/issue_comment.rb +++ b/app/models/issue_comment.rb @@ -1,6 +1,6 @@ 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 diff --git a/app/models/report.rb b/app/models/report.rb index 5b238dcac..f997215a8 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,5 +1,5 @@ class Report < ActiveRecord::Base belongs_to :issue - belongs_to :user + belongs_to :user, :class_name => "User", :foreign_key => :reporter_user_id end diff --git a/app/views/diary_entry/_diary_comment.html.erb b/app/views/diary_entry/_diary_comment.html.erb index f53e30f45..d74d06b89 100644 --- a/app/views/diary_entry/_diary_comment.html.erb +++ b/app/views/diary_entry/_diary_comment.html.erb @@ -5,5 +5,7 @@ <%= 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 %> diff --git a/app/views/diary_entry/_diary_entry.html.erb b/app/views/diary_entry/_diary_entry.html.erb index 5b608c2d7..a5162ff59 100644 --- a/app/views/diary_entry/_diary_entry.html.erb +++ b/app/views/diary_entry/_diary_entry.html.erb @@ -31,8 +31,11 @@ <%= link_to t('diary_entry.diary_entry.edit_link'), :action => 'edit', :display_name => diary_entry.user.display_name, :id => diary_entry.id %> <% end %> -
  • <%= link_to 'Report', new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, reported_user_id: diary_entry.user.id) %>
  • - +
  • + <% 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 %> +
  • <%= 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 %> diff --git a/app/views/issues/_reports.html.erb b/app/views/issues/_reports.html.erb index 29b7e94d1..c5dbcb9b5 100644 --- a/app/views/issues/_reports.html.erb +++ b/app/views/issues/_reports.html.erb @@ -4,7 +4,14 @@ <%= link_to user_thumbnail(report.user), :controller => :user,:action =>:view, :display_name => report.user.display_name %> <%= link_to report.user.display_name, :controller => :user,:action =>:view, :display_name => report.user.display_name %>
    - <%= report.details %> + <% details = report.details.split("||") %> + <%= details[0] %> +
    +
    + + <% details[1..(details.size-1)].each do |tags| %> + <%= tags %> + <% end %>
    On <%= l report.created_at.to_datetime, :format => :long %> diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb index 476e06be2..5f9c7ce08 100644 --- a/app/views/issues/new.html.erb +++ b/app/views/issues/new.html.erb @@ -10,12 +10,69 @@ <%= f.hidden_field :reportable_type %> <%= f.hidden_field :reported_user_id %> +
    - - <%= 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." %> +

    Select one (or more) reasons for your report:

    + +
    +
    + <%= check_box_tag :spam, "[SPAM]" %> +
    +
    + <%= label_tag "This #{@issue.reportable.class.name} is/contains spam." %>
    +
    +
    +
    + +
    +
    + <%= check_box_tag :offensive, "[OFFENSIVE]" %> +
    +
    + <%= label_tag "This #{@issue.reportable.class.name} is obscene/offensive." %>
    +
    +
    +
    + +
    +
    + <%= check_box_tag :threat, "[THREAT]" %> +
    +
    + <%= label_tag "This #{@issue.reportable.class.name} contains a threat." %>
    +
    +
    +
    + + <% if @issue.reportable.class.name == "User" %> +
    +
    + <%= check_box_tag :vandal, "[VANDAL]" %> +
    +
    + <%= label_tag "This #{@issue.reportable.class.name} is a vandal." %>
    +
    +
    +
    + <% end %> + +
    +
    + <%= check_box_tag :other, "[OTHER]" %> +
    +
    + <%= label_tag "Other." %>
    +
    +
    +
    + +
    + <%= text_area :report, :details, :cols => 80, :rows => 20, placeholder: "Please provide some more details into the problem. (This field cannot be left blank!)" %>
    +
    <%= submit_tag %>
    + <% end %> \ No newline at end of file diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 84c52d077..51498484d 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -39,7 +39,7 @@ <% 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 %>
    <% end %> <% end %> <% else %> diff --git a/db/migrate/20150516073616_create_issues.rb b/db/migrate/20150516073616_create_issues_and_reports.rb similarity index 53% rename from db/migrate/20150516073616_create_issues.rb rename to db/migrate/20150516073616_create_issues_and_reports.rb index e77ea989a..153dbd690 100644 --- a/db/migrate/20150516073616_create_issues.rb +++ b/db/migrate/20150516073616_create_issues_and_reports.rb @@ -1,6 +1,6 @@ require "migrate" -class CreateIssues < ActiveRecord::Migration +class CreateIssuesAndReports < ActiveRecord::Migration def change create_table :issues do |t| t.string :reportable_type, :null => false @@ -19,6 +19,22 @@ class CreateIssues < ActiveRecord::Migration 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 diff --git a/db/migrate/20150516075620_create_reports.rb b/db/migrate/20150516075620_create_reports.rb deleted file mode 100644 index abae0f705..000000000 --- a/db/migrate/20150516075620_create_reports.rb +++ /dev/null @@ -1,20 +0,0 @@ -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 diff --git a/db/migrate/20150526130032_create_issue_comments.rb b/db/migrate/20150526130032_create_issue_comments.rb index 63f628354..688fa2b99 100644 --- a/db/migrate/20150526130032_create_issue_comments.rb +++ b/db/migrate/20150526130032_create_issue_comments.rb @@ -2,7 +2,7 @@ class CreateIssueComments < ActiveRecord::Migration 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 @@ -10,9 +10,9 @@ class CreateIssueComments < ActiveRecord::Migration 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 diff --git a/db/structure.sql b/db/structure.sql index e73925d32..6b34868e1 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -670,7 +670,7 @@ ALTER SEQUENCE gpx_files_id_seq OWNED BY gpx_files.id; 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 @@ -1040,7 +1040,7 @@ CREATE TABLE relations ( 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 @@ -1976,17 +1976,17 @@ CREATE UNIQUE INDEX index_client_applications_on_key ON client_applications USIN -- --- 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); -- @@ -2039,10 +2039,10 @@ 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: +-- 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); -- @@ -2442,19 +2442,19 @@ ALTER TABLE ONLY gpx_files -- --- 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); -- @@ -2586,11 +2586,11 @@ ALTER TABLE ONLY reports -- --- 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); -- @@ -2785,8 +2785,6 @@ INSERT INTO schema_migrations (version) VALUES ('20150222101847'); 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'); diff --git a/test/controllers/issues_controller_test.rb b/test/controllers/issues_controller_test.rb index 980603e20..a8ee6f613 100644 --- a/test/controllers/issues_controller_test.rb +++ b/test/controllers/issues_controller_test.rb @@ -58,11 +58,11 @@ class IssuesControllerTest < ActionController::TestCase # 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 @@ -78,11 +78,11 @@ class IssuesControllerTest < ActionController::TestCase # 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