diff options
author | Azul <azul@leap.se> | 2012-10-29 19:19:35 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-10-29 19:19:35 +0100 |
commit | 428aea3c577c44a3bb13cced23c5c0cafc5b4d93 (patch) | |
tree | e36349452e599c11b67e1912df2e68db5140c504 /help/app/models/ticket.rb | |
parent | 3ba2e664a26e96a93c8640b57241af6386db361e (diff) | |
parent | 56273c13f54a872d02db286c90a8d5103cf7a663 (diff) |
Merge branch 'help_develop' into develop
Diffstat (limited to 'help/app/models/ticket.rb')
-rw-r--r-- | help/app/models/ticket.rb | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index 784d7ef..537a7c6 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -15,8 +15,8 @@ class Ticket < CouchRest::Model::Base =end #belongs_to :user #from leap_web_users. doesn't necessarily belong to a user though - property :created_by, Integer #nil unless user was authenticated for ticket creation, #THIS should not be changed after being set - property :regarding_user, Integer # form cannot be submitted if they type in a username w/out corresponding ID. this field can be nil. for authenticated ticket creation by non-admins, should this just automatically be set to be same as created_by? or maybe we don't use this field unless created_by is nil? + property :created_by, String#Integer #nil unless user was authenticated for ticket creation, #THIS should not be changed after being set + property :regarding_user, String#Integer # form cannot be submitted if they type in a username w/out corresponding ID. this field can be nil. for authenticated ticket creation by non-admins, should this just automatically be set to be same as created_by? or maybe we don't use this field unless created_by is nil? #also, both created_by and regarding_user could be nil---say user forgets username, or has general question property :title, String property :email, String #verify @@ -29,18 +29,24 @@ class Ticket < CouchRest::Model::Base timestamps! - before_validation :set_created_by, :set_code, :on => :create + #before_validation :set_created_by, :set_code, :set_email, :on => :create + before_validation :set_code, :set_email, :on => :create design do view :by_title end + validates :title, :presence => true + #validates :comments, :presence => true #do we want it like this? + + # html5 has built-in validation which isn't ideal, as it says 'please enter an email address' for invalid email addresses, which implies an email address is required, and it is not. validates :email, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :if => :email #email address is optional - def set_created_by - self.created_by = User.current if User.current - end + #TODO: + #def set_created_by + # self.created_by = User.current if User.current + #end def is_creator_validated? !!created_by @@ -51,6 +57,12 @@ class Ticket < CouchRest::Model::Base self.code = SecureRandom.hex(8) if !is_creator_validated? end + + def set_email + self.email = nil if self.email == "" + #self.email = current users email if is_creator_validated? + end + def close self.is_open = false save @@ -61,6 +73,14 @@ class Ticket < CouchRest::Model::Base save end + def comments_attributes=(attributes) + comment = TicketComment.new(attributes.values.first) #TicketComment.new(attributes) + comment.posted_by = User.current_test.id if User.current_test + comment.posted_at = Time.now + comments << comment + + end + =begin def validate if email_address and not email_address.strip =~ RFC822::EmailAddress |