summaryrefslogtreecommitdiff
path: root/help/app/models/ticket.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-04-11 10:03:19 +0200
committerAzul <azul@leap.se>2014-04-11 10:07:23 +0200
commit636692f9921bd695d726695d2d46c91f5a6e56f3 (patch)
treea7cc0b89007bd273ae7719f31c16e052a141fec7 /help/app/models/ticket.rb
parent32136605ddd405a0bf47f3b795b22fd4b49465b5 (diff)
move engines into engines directory
Also renamed help to support so it's harder to confuse it with documentation
Diffstat (limited to 'help/app/models/ticket.rb')
-rw-r--r--help/app/models/ticket.rb105
1 files changed, 0 insertions, 105 deletions
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb
deleted file mode 100644
index cd22758..0000000
--- a/help/app/models/ticket.rb
+++ /dev/null
@@ -1,105 +0,0 @@
-#
-# TODO: thought i should reverse keys for descending, but that didn't work.
-# look into whether that should be tweaked, and whether it works okay with
-# pagination (seems to now...)
-#
-# TODO: better validation of email
-#
-# TODO: don't hardcode strings 'unknown user' and 'unauthenticated user'
-#
-class Ticket < CouchRest::Model::Base
- use_database "tickets"
-
- property :created_by, String, :protected => true # nil for anonymous tickets, should never be changed
- property :regarding_user, String # may be nil or valid username
- property :subject, String
- property :email, String
- property :is_open, TrueClass, :default => true
- property :comments, [TicketComment]
-
- timestamps!
-
- before_validation :set_email, :set_regarding_user, :on => :create
-
- design do
- view :by_updated_at
- view :by_created_at
- view :by_created_by
-
- view :by_is_open_and_created_at
- view :by_is_open_and_updated_at
-
- own_path = Pathname.new(File.dirname(__FILE__))
- load_views(own_path.join('..', 'designs', 'ticket'))
- end
-
- validates :subject, :presence => true
- validates :email, :allow_blank => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/
-
- def self.search(options = {})
- @selection = TicketSelection.new(options)
- @selection.tickets
- end
-
- def self.destroy_all_from(user)
- self.by_created_by.key(user.id).each do |ticket|
- ticket.destroy
- end
- end
-
- def is_creator_validated?
- !!created_by
- end
-
- def set_email
- self.email = nil if self.email == ""
- end
-
- def set_regarding_user
- self.regarding_user = nil if self.regarding_user == ""
- end
-
- def close
- self.is_open = false
- end
-
- def reopen
- self.is_open = true
- end
-
- def commenters
- commenters = []
- self.comments.each do |comment|
- if comment.posted_by
- if user = User.find(comment.posted_by)
- commenters << user.login if user and !commenters.include?(user.login)
- else
- commenters << 'unknown user' if !commenters.include?('unknown user')
- end
- else
- commenters << 'unauthenticated user' if !commenters.include?('unauthenticated user')
- end
- end
- commenters.join(', ')
- end
-
- #
- # update comments. User should be set by controller.
- #
- def comments_attributes=(attributes)
- if attributes
- comment = TicketComment.new(attributes.values.first)
- comment.posted_at = Time.now
- comments << comment
- end
- end
-
- def created_by_user
- User.find(self.created_by)
- end
-
- def regarding_user_actual_user
- User.find_by_login(self.regarding_user)
- end
-
-end