summaryrefslogtreecommitdiff
path: root/engines/support/app/models
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-05-13 13:52:16 +0200
committerAzul <azul@leap.se>2014-05-13 14:02:15 +0200
commit81a4a0527639fe4b560b8d98f977f6dbac67bb41 (patch)
tree725b9effd20be6d9d62e5f0e5443c7e4c5398fcf /engines/support/app/models
parent84ce597ad0516b92d6633c1f81c03517b5d74004 (diff)
prefill ticket form from the model - fixes #5657
email and regarding user fields can be set to defaults based on created_by user. If these fields are emptied by the submitting user they will be set to whereas they are nil if they have not been initialized. In that case we will use meaningful defaults from the user who created the ticket.
Diffstat (limited to 'engines/support/app/models')
-rw-r--r--engines/support/app/models/ticket.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/engines/support/app/models/ticket.rb b/engines/support/app/models/ticket.rb
index cd22758..d5a0b5d 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,7 @@ class Ticket < CouchRest::Model::Base
end
def created_by_user
- User.find(self.created_by)
+ User.find(self.created_by) || AnonymousUser.new
end
def regarding_user_actual_user