summaryrefslogtreecommitdiff
path: root/engines/support/app/models/ticket.rb
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2014-05-14 08:41:13 +0200
committerazul <azul@riseup.net>2014-05-14 08:41:13 +0200
commitc85028fba2a25f22b375b8714c2e1999c35f8e82 (patch)
treee9c6a5c25e0bb7acaddae1f34a9fd0de886bbeb8 /engines/support/app/models/ticket.rb
parent4843db127a5d5d038f227d9ffe5f0b83d95fd9f6 (diff)
parent3278e474a32ef4926b1dab0d97ca4df1c59aa2a0 (diff)
Merge pull request #157 from azul/bugfix/5664-stop-email-autofill
Bugfix/5664 stop email autofill
Diffstat (limited to 'engines/support/app/models/ticket.rb')
-rw-r--r--engines/support/app/models/ticket.rb25
1 files changed, 16 insertions, 9 deletions
diff --git a/engines/support/app/models/ticket.rb b/engines/support/app/models/ticket.rb
index cd22758..bf5df53 100644
--- a/engines/support/app/models/ticket.rb
+++ b/engines/support/app/models/ticket.rb
@@ -19,8 +19,6 @@ class Ticket < CouchRest::Model::Base
timestamps!
- before_validation :set_email, :set_regarding_user, :on => :create
-
design do
view :by_updated_at
view :by_created_at
@@ -34,7 +32,12 @@ class Ticket < CouchRest::Model::Base
end
validates :subject, :presence => true
- validates :email, :allow_blank => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/
+
+ # email can have three states:
+ # * nil - prefilled with created_by's email
+ # * "" - cleared
+ # * valid email address
+ validates :email, :allow_blank => true, :format => /\A(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\Z/
def self.search(options = {})
@selection = TicketSelection.new(options)
@@ -48,15 +51,15 @@ class Ticket < CouchRest::Model::Base
end
def is_creator_validated?
- !!created_by
+ created_by_user.is_a? User
end
- def set_email
- self.email = nil if self.email == ""
+ def email
+ read_attribute(:email) || created_by_user.email
end
- def set_regarding_user
- self.regarding_user = nil if self.regarding_user == ""
+ def regarding_user
+ read_attribute(:regarding_user) || created_by_user.login
end
def close
@@ -95,7 +98,11 @@ class Ticket < CouchRest::Model::Base
end
def created_by_user
- User.find(self.created_by)
+ if self.created_by
+ User.find(self.created_by) || AnonymousUser.new
+ else
+ AnonymousUser.new
+ end
end
def regarding_user_actual_user