]> git.openstreetmap.org Git - rails.git/commitdiff
Fixed tests + Altered migration file + Added reporting strings + Added update method
authorShrey <shrey14099@iiitd.ac.in>
Thu, 4 Jun 2015 18:56:24 +0000 (00:26 +0530)
committerMatt Amos <zerebubuth@gmail.com>
Mon, 22 Aug 2016 15:17:54 +0000 (16:17 +0100)
14 files changed:
app/assets/stylesheets/common.scss
app/controllers/issues_controller.rb
app/models/issue_comment.rb
app/models/report.rb
app/views/diary_entry/_diary_comment.html.erb
app/views/diary_entry/_diary_entry.html.erb
app/views/issues/_reports.html.erb
app/views/issues/new.html.erb
app/views/issues/show.html.erb
db/migrate/20150516073616_create_issues_and_reports.rb [moved from db/migrate/20150516073616_create_issues.rb with 53% similarity]
db/migrate/20150516075620_create_reports.rb [deleted file]
db/migrate/20150526130032_create_issue_comments.rb
db/structure.sql
test/controllers/issues_controller_test.rb

index b658e4e325781d18b7d68f7ac610382498e08a77..9a7785678f010e3c35abd3fda4441dc53173f7e7 100644 (file)
@@ -2761,4 +2761,21 @@ input.richtext_title[type="text"] {
 
 .issue-comments {
   width:475px;
 
 .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
 }
\ No newline at end of file
index c1c5dd4f3d41b25dd175144b208c1fa66f1ada81..3cd0ceda09a785bb7348527b731b2025be36c05f 100644 (file)
@@ -33,7 +33,9 @@ class IssuesController < ApplicationController
       end
     end
     @report = @issue.reports.build(report_params)
       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
     if @issue.save!
       redirect_to root_path, notice: 'Your report has been registered sucessfully.'
     else
@@ -41,10 +43,22 @@ class IssuesController < ApplicationController
     end
   end
 
     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)
   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
     @issue_comment.save!
     redirect_to @issue
   end
@@ -103,6 +117,6 @@ class IssuesController < ApplicationController
     end
 
     def issue_comment_params
     end
 
     def issue_comment_params
-      params.require(:issue_comment).permit(:body, :user_id)
+      params.require(:issue_comment).permit(:body)
     end
 end
     end
 end
index 455fb040bc73c7c102de27697fac01cb119b6a3b..866a85b84aaa22278131446bd66f3e9f43e17e16 100644 (file)
@@ -1,6 +1,6 @@
 class IssueComment < ActiveRecord::Base
        belongs_to :issue
 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
 
        validates :body, :presence => true
 end
index 5b238dcaccae0eb5e311c3b30bc961abc99378cc..f997215a8b062b6cf28e037767e98fbe6786ced8 100644 (file)
@@ -1,5 +1,5 @@
 class Report < ActiveRecord::Base
        belongs_to :issue
 class Report < ActiveRecord::Base
        belongs_to :issue
-       belongs_to :user
+       belongs_to :user, :class_name => "User", :foreign_key => :reporter_user_id
        
 end
        
 end
index f53e30f45434b32efdbeb881b864b401ec741127..d74d06b8906daf93b57e5c1265fbb4653958b2bf 100644 (file)
@@ -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 %>
   <%= 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>
 </div>
index 5b608c2d7716c8bd8a6d5e8358b1fd8c2ba11871..a5162ff597a09cfc4009477fec0e903a4afb934d 100644 (file)
       <%= 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 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 %>
     <%= 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 %>
index 29b7e94d1e80138b3de22669e55815f27fa06baa..c5dbcb9b50bdb36019e198ec8d9592fbd6282da7 100644 (file)
@@ -4,7 +4,14 @@
                        <%= 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/>
                        <%= 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>
                <br/>
                <span class="deemphasize">
                On <%= l report.created_at.to_datetime, :format => :long %> </span>
index 476e06be2bfd2f5eb3494718923636c7c0601786..5f9c7ce08abff355bb0e49b1aba9196d0c8d10b1 100644 (file)
                 <%= f.hidden_field :reportable_type %>
                 <%= f.hidden_field :reported_user_id %>
             </div>
                 <%= f.hidden_field :reportable_type %>
                 <%= f.hidden_field :reported_user_id %>
             </div>
+
             <div class='form-row'>
             <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>
+
             <div class='buttons'>
                 <%= submit_tag %>
             </div>
             <div class='buttons'>
                 <%= submit_tag %>
             </div>
+        
         </fieldset>
 <% end %>
\ No newline at end of file
         </fieldset>
 <% end %>
\ No newline at end of file
index 84c52d077e89f2d9f07df87279e8177d397e629a..51498484dd0c3dd0d8b8c57cb65e213232bcc385 100644 (file)
@@ -39,7 +39,7 @@
                                <% if @related_issues.count > 1 %>
                                        <% @related_issues.each do |issue| %>
                                                <% if issue.id != @issue.id %>
                                <% 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 %>
                                                <% end %>
                                        <% end %>
                                <% else %>
similarity index 53%
rename from db/migrate/20150516073616_create_issues.rb
rename to db/migrate/20150516073616_create_issues_and_reports.rb
index e77ea989a3524bdc52f8b84c847995919616312e..153dbd6906cc299c18b00732a2e2558e8e1dde23 100644 (file)
@@ -1,6 +1,6 @@
 require "migrate"
 
 require "migrate"
 
-class CreateIssues < ActiveRecord::Migration
+class CreateIssuesAndReports < ActiveRecord::Migration
   def change
     create_table :issues do |t|
       t.string :reportable_type, :null => false
   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]
 
     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
     
   end
 end
diff --git a/db/migrate/20150516075620_create_reports.rb b/db/migrate/20150516075620_create_reports.rb
deleted file mode 100644 (file)
index abae0f7..0000000
+++ /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
index 63f6283541e7eef88d442a7c7212ad44c01bd093..688fa2b996a66f146d9645c65be685aefc5152fa 100644 (file)
@@ -2,7 +2,7 @@ class CreateIssueComments < ActiveRecord::Migration
   def change
     create_table :issue_comments do |t|
       t.integer :issue_id
   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
 
       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"
     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
        add_index :issue_comments, :issue_id
 
   end
index e73925d329771f2f04d398e0c2b58acacf8ebd0e..6b34868e149a736956809c6dd0f01159f4040f9f 100644 (file)
@@ -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,
 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
     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,
 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
     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
 --
 
 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
 --
 
 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
 --
 
 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 ('20150516073616');
 
-INSERT INTO schema_migrations (version) VALUES ('20150516075620');
-
 INSERT INTO schema_migrations (version) VALUES ('20150526130032');
 
 INSERT INTO schema_migrations (version) VALUES ('21');
 INSERT INTO schema_migrations (version) VALUES ('20150526130032');
 
 INSERT INTO schema_migrations (version) VALUES ('21');
index 980603e20faa72a70f0b98f2800db9ee9d644d32..a8ee6f613c78a66004591be791201a89edabd939 100644 (file)
@@ -58,11 +58,11 @@ class IssuesControllerTest < ActionController::TestCase
     
     # Create Issue
 
     
     # 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"
     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
                       :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
 
 
     # 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"
     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
                       :issue => { reportable_id: 1, reportable_type: "DiaryEntry", reported_user_id: 1} }
     end
     assert_response :redirect