]> git.openstreetmap.org Git - rails.git/commitdiff
Added Issue Type + Issue Reassigning + Last updated_by
authorShrey <shrey14099@iiitd.ac.in>
Sat, 13 Jun 2015 18:27:36 +0000 (23:57 +0530)
committerMatt Amos <zerebubuth@gmail.com>
Mon, 22 Aug 2016 15:17:54 +0000 (16:17 +0100)
app/controllers/issues_controller.rb
app/models/issue.rb
app/views/diary_entry/_diary_entry.html.erb
app/views/issues/_comments.html.erb
app/views/issues/index.html.erb
app/views/issues/show.html.erb
config/locales/en-GB.yml
config/locales/en.yml
db/migrate/20150516073616_create_issues_and_reports.rb
db/migrate/20150526130032_create_issue_comments.rb
db/structure.sql

index 7cd21d5124185e39f827c8856388e5f136536260..24ac932d6974edec6236ce310e2148a5a6f3366d 100644 (file)
@@ -7,21 +7,34 @@ class IssuesController < ApplicationController
   before_action :find_issue, only: [:show, :resolve, :reopen, :ignore]
 
   def index
-    if params[:search_by_user].present?
-      @user = User.find_by_display_name(params[:search_by_user])
-      if @user.present?
-        @issues = Issue.where(reported_user_id: @user.id).order(:status)
+    # Get user role
+    if @user.administrator?
+      @user_role = "administrator"
+    else
+      @user_role = "moderator"
+    end
+
+    # If search
+    if params[:search_by_user]
+      @find_user = User.find_by_display_name(params[:search_by_user])
+      if @find_user
+        @issues = Issue.where(reported_user_id: @find_user.id, issue_type: @user_role).order(:status)
       else 
-        @issues = Issue.all.order(:status)
-        redirect_to issues_path, notice: t('issues.index.search.user_not_found') 
+        @issues = Issue.where(issue_type: @user_role).order(:status)
+        notice = t('issues.index.search.user_not_found') 
       end
-      
-      if @user.present? and not @issues.present?
-        @issues = Issue.all.order(:status)
-        redirect_to issues_path, notice: t('issues.index.search.issues_not_found')
+
+      if @find_user !=nil and @issues.first == nil
+        @issues = Issue.where(issue_type: @user_role).order(:status)
+        notice = t('issues.index.search.issues_not_found')
       end
+
+      if notice
+        redirect_to issues_path, notice: notice
+      end 
+    
     else
-      @issues = Issue.all.order(:status)
+      @issues = Issue.where(issue_type: @user_role).order(:status)
     end
   end
 
@@ -30,6 +43,9 @@ class IssuesController < ApplicationController
     @unread_reports = @issue.unread_reports
     @comments = @issue.comments
     @related_issues = @issue.user.issues
+    if @issue.updated_by
+      @updated_by_admin = User.find(@issue.updated_by)
+    end
   end
 
   def new
@@ -41,14 +57,23 @@ class IssuesController < ApplicationController
   end
 
   def create
+    admin_issues = [ 'DiaryEntry', 'DiaryComment', 'User']
+    moderator_issues = []
     @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
     # Check if Issue alrwady exists
     if !@issue 
       @issue = Issue.find_or_initialize_by(issue_params)
+      @issue.updated_by = nil
       @admins = UserRole.where(role: "administrator")
       @admins.each do |admin|
         Notifier.new_issue_notification(User.find(admin.user_id)).deliver_now
       end
+
+      # Reassign to moderators if it is a moderator issue
+      @issue.issue_type = "administrator"
+      if moderator_issues.include? @issue.reportable.class.name
+        reassign_issue
+      end
     end
 
     # Check if details provided are sufficient
@@ -112,7 +137,13 @@ class IssuesController < ApplicationController
     @issue = Issue.find(params[:id])
     @issue_comment = @issue.comments.build(issue_comment_params)
     @issue_comment.commenter_user_id = @user.id
+    if params[:reassign]
+      reassign_issue
+      @issue_comment.reassign = true
+    end
     @issue_comment.save!
+    @issue.updated_by = @user.id
+    @issue.save!
     redirect_to @issue
   end
 
@@ -128,6 +159,7 @@ class IssuesController < ApplicationController
 
   def ignore
     if @issue.ignore
+      @issue.updated_by = @user.id
       @issue.save!
       redirect_to @issue, notice: t('issues.ignored')
     else
@@ -137,6 +169,7 @@ class IssuesController < ApplicationController
 
   def reopen
     if @issue.reopen
+      @issue.updated_by = @user.id      
       @issue.save!
       redirect_to @issue, notice: t('issues.reopened')
     else
@@ -144,6 +177,15 @@ class IssuesController < ApplicationController
     end
   end
 
+  # Reassign Issues between Administrators and Moderators
+  def reassign_issue
+    if @issue.issue_type == "moderator"
+      @issue.issue_type = "administrator"
+    else
+      @issue.issue_type = "moderator"
+    end
+    @issue.save!
+  end
 
   private
 
index 604b73d986ef69b9bda2e5897c0a7e3d0fcb282e..6de535e819b7a0fb147f7770827a5b7319de91eb 100644 (file)
@@ -10,6 +10,7 @@ class Issue < ActiveRecord::Base
 
        # Check if more statuses are needed
        enum status: %w( open ignored resolved )
+       enum type: %w( administrator moderator )
 
        scope :with_status, -> (issue_status) { where(:status => statuses[issue_status])}
 
@@ -44,5 +45,4 @@ class Issue < ActiveRecord::Base
                end
 
        end
-
 end
index 76a6666f31d9e973bec39852a02157168ce3c969..5a34bad5e6c331ef007dcb6737e9a3e660bfaaa3 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 %>
 
+    <% if @user and diary_entry.user.id != @user.id %>
       <li>
-        <% if @user and diary_entry.user.id != @user.id %>
           <%= link_to t('issues.report'), new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, reported_user_id: diary_entry.user.id) %>
-        <% end %>
       </li>
+    <% 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 de4989afd1852e3de9ddda4025e4446a42db66cd..2e259a1698049dc4754f2a73a85393c4a2fc8165 100644 (file)
@@ -6,6 +6,11 @@
                </div>
                <b> <%= link_to comment.user.display_name, :controller => :user,:action =>:view, :display_name => comment.user.display_name %> </b> <br/>
                <%= comment.body %>
+
+               <% if comment.reassign %>
+                       <br/>
+                       <i><%= t('issues.show.comments.reassign') %></i>
+               <% end %>
        </div>
        <span class="deemphasize">
        On <%= l comment.created_at.to_datetime, :format => :long %> </span>
@@ -16,6 +21,9 @@
 <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 => 10, :rows => 8 %>
+           <%= label_tag t('issues.show.comments.reassign_param') %> <%= check_box_tag :reassign, true %> 
+           <br/>
+           <br/>
        <%= submit_tag 'Submit' %>
        <% end %>
 </div>
\ No newline at end of file
index 101df96ba6e8ffefed16a2a94cbf164ff8b4363f..4002e9db3e40152d14a2ea01e9aa19a276ea676f 100644 (file)
@@ -1,7 +1,7 @@
 <p id= "notice"><%= notice %></p>
 
 <% content_for :heading do %>
-       <h1>List of existing Issues:</h1>
+       <h1>List of <%= @user_role %> issues:</h1>
 <% end %>
 
 <%= form_tag(issues_path, :method => :get) do %>
index 1f57c454e73a62babb9d18a9f3e1a4cceff2c8b5..4de7a77c6efb795bf0975c6915030e67828c75e3 100644 (file)
@@ -4,7 +4,7 @@
        <p>Issue type: <%= @issue.reportable_type %></p>
        <p class="deemphasize">
                <small>
-                       <%= @issue.reports.count %> reports | First reported: <%= l @issue.created_at.to_date, :format => :long %>  <%= "| Last resolved at #{l(@issue.resolved_at.to_datetime, :format =>:long)}" if @issue.resolved_at? %>
+                       <%= @issue.reports.count %> reports | First reported: <%= l @issue.created_at.to_date, :format => :long %>  <%= "| Last resolved at #{l(@issue.resolved_at.to_datetime, :format =>:long)}" if @issue.resolved_at? %> <%= "| Last updated at #{l(@issue.updated_at.to_datetime, :format => :long)} by #{@updated_by_admin.display_name}" if @updated_by_admin %>
                </small>
        </p>
        <p><%= link_to t('issues.resolve'), resolve_issue_url(@issue), :method => :post if @issue.may_resolve? %></p>
index 5962eb747b6175313cc3c0a016f71283001c201b..e62069a5e6bc59b89b709fce07e58113179f30c9 100644 (file)
@@ -953,6 +953,10 @@ en-GB:
       provide_details: Please provide the required details
     new:
       details: Please provide some more details into the problem. (This field cannot be left blank!)
+    show:
+      comments:
+        reassign: The Issue was reassigned
+        reassign_param: Reassign Issue?        
     resolved: Issue status has been set to 'Resolved'
     ignored: Issue status has been set to 'Ignored'
     reopened: Issue status has been set to 'Open'
index 46de256bf18652b0056d667764890896e9c1478b..c65f51bc6a71e7ee6e1b7a3bc90372c7ec6129cc 100644 (file)
@@ -923,6 +923,10 @@ en:
       provide_details: Please provide the required details
     new:
       details: Please provide some more details into the problem. (This field cannot be left blank!)
+    show: 
+      comments:
+        reassign: The Issue was reassigned
+        reassign_param: Reassign Issue?
     resolved: Issue status has been set to 'Resolved'
     ignored: Issue status has been set to 'Ignored'
     reopened: Issue status has been set to 'Open'
index 153dbd6906cc299c18b00732a2e2558e8e1dde23..709754dbf325e6cbefcf6523202d6308cea19a6e 100644 (file)
@@ -7,10 +7,12 @@ class CreateIssuesAndReports < ActiveRecord::Migration
       t.integer :reportable_id, :null => false
       t.integer :reported_user_id, :null => false
       t.integer :status
+      t.string :issue_type
       t.datetime :resolved_at
       t.integer :resolved_by
       t.datetime :created_at
       t.datetime :updated_at
+      t.integer :updated_by
 
       t.timestamps null: false
     end
index 688fa2b996a66f146d9645c65be685aefc5152fa..9fb35a9225b81c77a3a0090f74cdd196a31547fe 100644 (file)
@@ -5,7 +5,7 @@ class CreateIssueComments < ActiveRecord::Migration
       t.integer :commenter_user_id
       t.text :body
       t.datetime :created_at
-
+      t.boolean :reassign
       t.timestamps null: false
     end
 
index e19788329962a50a1b931e3474b08d8ee13c8438..4c1328a183564db1e5e81acfe0b15e94fdc08687 100644 (file)
@@ -151,10 +151,6 @@ CREATE FUNCTION xid_to_int4(xid) RETURNS integer
     AS '$libdir/libpgosm', 'xid_to_int4';
 
 
-SET default_tablespace = '';
-
-SET default_with_oids = false;
-
 SET default_tablespace = '';
 
 SET default_with_oids = false;
@@ -677,6 +673,7 @@ CREATE TABLE issue_comments (
     commenter_user_id integer,
     body text,
     created_at timestamp without time zone NOT NULL,
+    reassign boolean,
     updated_at timestamp without time zone NOT NULL
 );
 
@@ -710,10 +707,12 @@ CREATE TABLE issues (
     reportable_id integer NOT NULL,
     reported_user_id integer NOT NULL,
     status integer,
+    issue_type character varying,
     resolved_at timestamp without time zone,
     resolved_by integer,
     created_at timestamp without time zone NOT NULL,
-    updated_at timestamp without time zone NOT NULL
+    updated_at timestamp without time zone NOT NULL,
+    updated_by integer
 );