Controllers + a few tests + new notification added. Work pending on the notification...
authorShrey <shrey14099@iiitd.ac.in>
Wed, 20 May 2015 14:59:20 +0000 (20:29 +0530)
committerMatt Amos <zerebubuth@gmail.com>
Mon, 22 Aug 2016 15:13:31 +0000 (16:13 +0100)
14 files changed:
app/assets/javascripts/issues.coffee [new file with mode: 0644]
app/assets/stylesheets/issues.scss [new file with mode: 0644]
app/controllers/issues_controller.rb [new file with mode: 0644]
app/helpers/issues_helper.rb [new file with mode: 0644]
app/models/issue.rb
app/models/notifier.rb
app/views/issues/index.html.erb [new file with mode: 0644]
app/views/issues/new.html.erb [new file with mode: 0644]
app/views/issues/show.html.erb [new file with mode: 0644]
app/views/notifier/new_issue_notification.html.erb [new file with mode: 0644]
config/locales/en-GB.yml
config/locales/en.yml
config/routes.rb
test/controllers/issues_controller_test.rb [new file with mode: 0644]

diff --git a/app/assets/javascripts/issues.coffee b/app/assets/javascripts/issues.coffee
new file mode 100644 (file)
index 0000000..24f83d1
--- /dev/null
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/stylesheets/issues.scss b/app/assets/stylesheets/issues.scss
new file mode 100644 (file)
index 0000000..391c8ce
--- /dev/null
@@ -0,0 +1,3 @@
+// Place all the styles related to the issues controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
new file mode 100644 (file)
index 0000000..0479e66
--- /dev/null
@@ -0,0 +1,85 @@
+class IssuesController < ApplicationController
+  layout "site"
+
+  before_action :find_issue, only: [:show, :resolve, :reopen, :ignore]
+
+  def index
+    @issues = Issue.all
+  end
+
+  def show
+    @read_reports = @issue.read_reports
+    @unread_reports = @issue.unread_reports
+  end
+
+  def new
+    unless create_new_issue_params.blank?
+      @issue = Issue.find_or_initialize_by(create_new_issue_params)
+    end
+  end
+
+  def create
+    @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
+    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
+      end
+    end
+
+    @report = @issue.reports.build(report_params)
+
+    if @issue.save
+      redirect_to @issue, notice: 'Issue was successfully created.'
+    else
+      render :new
+    end
+  end
+
+  # Status Transistions
+  def resolve
+    if @issue.resolve
+      @issue.save!
+      redirect_to @issue, notice: "Issue status has been set to: 'Resolved'"
+    else
+      render :show
+    end
+  end
+
+  def ignore
+    if @issue.ignore
+      @issue.save!
+      redirect_to @issue, notice: "Issue status has been set to: 'Ignored'"
+    else
+      render :show
+    end
+  end
+
+  def reopen
+    if @issue.reopen
+      @issue.save!
+      redirect_to @issue, notice: "Issue status has been set to: 'Open'"
+    else
+      render :show
+    end
+  end
+
+  private
+
+    def find_issue
+      @issue = Issue.find(params[:id])
+    end
+
+    def create_new_issue_params
+      params.permit(:reportable_id, :reportable_type, :user_id)
+    end
+
+    def issue_params
+      params[:issue].permit(:reportable_id, :reportable_type,:user_id)
+    end
+
+    def report_params
+      params[:report].permit(:details)
+    end
+end
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
new file mode 100644 (file)
index 0000000..bfb9d25
--- /dev/null
@@ -0,0 +1,2 @@
+module IssuesHelper
+end
index f678e94e13ec67d7461e2e9c7e4d34e572951bac..1726e690fe2d3c33f14560bffb07dfe79bc6507a 100644 (file)
@@ -2,6 +2,7 @@ class Issue < ActiveRecord::Base
        belongs_to :reportable, :polymorphic => true
        has_many :reports
        validates :reportable_id, :uniqueness => { :scope => [ :reportable_type ] }
+       belongs_to :user_id
 
        # Check if more statuses are needed
        enum status: %w( open ignored resolved )
index 23f7b990781049948036d08842bcec877b0250ad..13751560fbc7af6a12002b7b9ab4d26ab637a1a7 100644 (file)
@@ -172,6 +172,13 @@ class Notifier < ActionMailer::Base
     end
   end
 
+  def new_issue_notification(recipient)
+    with_recipient_locale recipient do
+      subject = I18n.t("notifier.new_issue_notification.subject")
+      mail :to => recipient.email, :subject => subject
+    end
+  end
+
   private
 
   def with_recipient_locale(recipient)
@@ -187,4 +194,5 @@ class Notifier < ActionMailer::Base
       EMAIL_FROM
     end
   end
+
 end
diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb
new file mode 100644 (file)
index 0000000..83fe41b
--- /dev/null
@@ -0,0 +1,2 @@
+<h1>Issues#index</h1>
+<p>Find me in app/views/issues/index.html.erb</p>
diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb
new file mode 100644 (file)
index 0000000..83c5d01
--- /dev/null
@@ -0,0 +1,2 @@
+<h1>Issues#new</h1>
+<p>Find me in app/views/issues/new.html.erb</p>
diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb
new file mode 100644 (file)
index 0000000..1c3b8bb
--- /dev/null
@@ -0,0 +1,2 @@
+<h1>Issues#show</h1>
+<p>Find me in app/views/issues/show.html.erb</p>
diff --git a/app/views/notifier/new_issue_notification.html.erb b/app/views/notifier/new_issue_notification.html.erb
new file mode 100644 (file)
index 0000000..f57b7c6
--- /dev/null
@@ -0,0 +1,5 @@
+<p><%= t("notifier.new_issue_notification.greeting") %></p>
+
+<p><%= t("notifier.new_issue_notification.new_issue") %></p>
+
+
index c4ea03585badb6bef6bfe2b93125827373bd46f0..101b71e2e7ab3ce119abadaff4f8c95273fa5272 100644 (file)
@@ -1349,6 +1349,10 @@ en-GB:
         partial_changeset_with_comment: with comment '%{changeset_comment}'
         partial_changeset_without_comment: without comment
       details: More details about the changeset can be found at %{url}.
+    new_issue_notification:
+      subject: "[OpenStreetMap] New Issue"
+      greeting: "Hi,"
+      new_issue: "A new issue has been created:"
   message:
     inbox:
       title: Inbox
index 96a35284fb5a66b799f6d2a9f1d105a597175507..3c9ec7131a68f5b03416de2ca5bb1fdd8becd838 100644 (file)
@@ -1317,6 +1317,10 @@ en:
         partial_changeset_with_comment: "with comment '%{changeset_comment}'"
         partial_changeset_without_comment: "without comment"
       details: "More details about the changeset can be found at %{url}."
+    new_issue_notification:
+      subject: "[OpenStreetMap] New Issue"
+      greeting: "Hi,"
+      new_issue: "A new issue has been created:"
   message:
     inbox:
       title: "Inbox"
index 085d67417570dc2564c065fe0c5a6bd783ac3a5d..a1d73985dd1d0bbb5fc4a30f41753db80d8c3d10 100644 (file)
@@ -288,6 +288,16 @@ OpenStreetMap::Application.routes.draw do
   resources :user_blocks
   match "/blocks/:id/revoke" => "user_blocks#revoke", :via => [:get, :post], :as => "revoke_user_block"
 
+  # issues and reports
+  resources :issues do
+    member do
+      post "resolve"
+      post "assign"
+      post "ignore"
+      post "reopen"
+    end
+  end
+
   # redactions
   resources :redactions
 end
diff --git a/test/controllers/issues_controller_test.rb b/test/controllers/issues_controller_test.rb
new file mode 100644 (file)
index 0000000..325e0c2
--- /dev/null
@@ -0,0 +1,70 @@
+require 'test_helper'
+
+class IssuesControllerTest < ActionController::TestCase
+  test "should get index" do
+    get :index
+    assert_response :success
+  end
+
+  def test_new_issue
+    # Test creation of a new issue and a new report
+    get :new, {reportable_id: 1, reportable_type: "IssueOne", user: 1}
+    assert_response :success
+    assert_difference "Issue.count",1 do 
+      details = "Details of a report"
+      post :create, { :report => { :deatils => details},
+                      :issue => { reportable_id: 1, reportable_type: "IssueOne", user: 1} }
+    end
+    assert_response :redirect
+  end
+
+  def test_new_report
+    # Test creation of a new report for an existing issue
+    get :new, {reportable_id: 1, reportable_type: "IssueOne", user: 1}
+    assert_response :success
+    assert_difference "Issue.count",1 do 
+      details = "Details of a report"
+      post :create, { :report => { :details => details},
+                      :issue => { reportable_id: 1, reportable_type: "IssueOne", user: 1} }
+    end
+    assert_response :redirect
+    
+    get :new, {reportable_id: 1, reportable_type: "IssueOne", user: 1}
+    assert_response :success
+    assert_no_difference "Issue.count" do
+      details = "Details of another report under the same issue"
+      post :create, { :report => { :details => details},
+                      :issue => { reportable_id: 1, reportable_type: "IssueOne", user: 1} }
+    end
+    assert_response :redirect
+    assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").reports.count,2
+  end
+
+  def test_change_status
+    # Create Issue
+    get :new, {reportable_id: 1, reportable_type: "IssueOne", user: 1}
+    assert_response :success
+    assert_difference "Issue.count",1 do 
+      details = "Details of a report"
+      post :create, { :report => { :deatils => details},
+                      :issue => { reportable_id: 1, reportable_type: "IssueOne", user: 1} }
+    end
+    assert_response :redirect
+
+    # Test 'Resolved'
+    get :resolve, id: Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").id
+    assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").resolved?, true
+    assert_response :redirect
+
+    # Test 'Reopen'
+    get :reopen, id: Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").id
+    assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").open?, true
+    assert_response :redirect
+
+    # Test 'Ignored'
+    get :ignore, id: Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").id
+    assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").ignored?, true
+    assert_response :redirect
+  end
+
+end