From fd3f22abaa86f7cc8fd756a1f24f985e52af0106 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 12 Apr 2017 19:43:24 +0800 Subject: [PATCH] fix for tickets --- .../admin/tickets_api_controller.rb | 1 + app/models/ticket.rb | 21 ++++++++++++------- app/models/ticket_query_response.rb | 5 +++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/tickets_api_controller.rb b/app/controllers/admin/tickets_api_controller.rb index 4607212..2858bfd 100644 --- a/app/controllers/admin/tickets_api_controller.rb +++ b/app/controllers/admin/tickets_api_controller.rb @@ -107,6 +107,7 @@ class Admin::TicketsApiController < ApplicationController response["ticket"] = get_ticket_hash(ticket) response["ticket"]["creator_name"] = ticket.ticket_creater_name response["ticket"]["creator_id"] = ticket.ticket_creater_id + response["ticket"]["creater_cpanel_id"] = ticket.ticket_creater_cpanel_id response["ticket"]["queries"] = [] ticket.ticket_queries.asc(:created_at).each do |qu| r = {"query" => qu.query, "responses" => []} diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 91c6c3e..3b21f48 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -2,34 +2,39 @@ class Ticket include Mongoid::Document include Mongoid::Timestamps include OrbitTag::Taggable - include OrbitCategory::Categorizable + include OrbitCategory::Categorizable include Slug field :site_type field :ticket_creater_id field :ticket_creater_name + field :ticket_creater_cpanel_id field :subject field :urgent, type: Boolean, default: false field :reopened_count, type: Integer, :default => 0 field :status, :default => "open" field :taken_by, type: BSON::ObjectId - scope :open, ->{ where(status: "open") } - scope :closed, ->{ where(status: "closed") } - scope :commenced, ->{ where(status: "commenced") } - scope :not_urgent, ->{ where(:urgent.in => [false,nil]) } - scope :all_urgent, ->{ where(urgent: true) } + scope :open, ->{ where(status: "open") } + scope :closed, ->{ where(status: "closed") } + scope :commenced, ->{ where(status: "commenced") } + scope :not_urgent, ->{ where(:urgent.in => [false,nil]) } + scope :all_urgent, ->{ where(urgent: true) } belongs_to :registered_site - has_many :ticket_queries, :dependent => :destroy - + has_many :ticket_queries, :autosave => true, :dependent => :destroy + accepts_nested_attributes_for :ticket_queries, :allow_destroy => true def can_be_reopened? self.reopened_count < 2 end + def author + !self.ticket_creater_name.nil? ? self.ticket_creater_name : self.ticket_creater_cpanel_id + end + def is_urgent? self.urgent end diff --git a/app/models/ticket_query_response.rb b/app/models/ticket_query_response.rb index 99b40c7..d0aba94 100644 --- a/app/models/ticket_query_response.rb +++ b/app/models/ticket_query_response.rb @@ -11,4 +11,9 @@ class TicketQueryResponse scope :for_clients, ->{ where(:internal_response.in => [nil, false]) } belongs_to :ticket_query + + def author + User.find(self.response_by) + end + end \ No newline at end of file