From a6de1561461cc719fddd8175c93588a47513a4b8 Mon Sep 17 00:00:00 2001 From: jessib Date: Fri, 5 Oct 2012 15:41:03 -0700 Subject: Rough code to add & comment on tickets. --- help/app/models/ticket.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'help/app/models/ticket.rb') diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index 784d7ef..355ae02 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -29,7 +29,8 @@ 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 @@ -38,9 +39,10 @@ class Ticket < CouchRest::Model::Base 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 +53,11 @@ class Ticket < CouchRest::Model::Base self.code = SecureRandom.hex(8) if !is_creator_validated? end + + def set_email + #self.email = current users email if is_creator_validated? + end + def close self.is_open = false save -- cgit v1.2.3 From c27f2a0686db0705553eda88c799d4c486c20bac Mon Sep 17 00:00:00 2001 From: jessib Date: Wed, 10 Oct 2012 10:55:25 -0700 Subject: Pushing some tweaks as I try to get server-side validation working. --- help/app/models/ticket.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'help/app/models/ticket.rb') diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index 355ae02..8cec0df 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,6 +29,8 @@ class Ticket < CouchRest::Model::Base timestamps! + #accepts_nested_attributes_for :ticketcomments #?? + #before_validation :set_created_by, :set_code, :set_email, :on => :create before_validation :set_code, :set_email, :on => :create @@ -36,7 +38,11 @@ class Ticket < CouchRest::Model::Base 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 #TODO: @@ -55,6 +61,7 @@ class Ticket < CouchRest::Model::Base def set_email + self.email = nil if self.email == "" #self.email = current users email if is_creator_validated? end @@ -68,6 +75,11 @@ class Ticket < CouchRest::Model::Base save end + #probably not useful, but trying it: + def ticket_comment_attributes=(attributes) + @ticket_comment = TicketComment.new(attributes) + end + =begin def validate if email_address and not email_address.strip =~ RFC822::EmailAddress -- cgit v1.2.3 From cf9ed38ab1840092352efdbb71bfeb5bc3b9f9d5 Mon Sep 17 00:00:00 2001 From: jessib Date: Wed, 10 Oct 2012 15:52:08 -0700 Subject: Some tweaks to get server-side validation working when adding the embedded ticket comment to a new ticket. --- help/app/models/ticket.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'help/app/models/ticket.rb') diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index 8cec0df..e829a5f 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -29,8 +29,6 @@ class Ticket < CouchRest::Model::Base timestamps! - #accepts_nested_attributes_for :ticketcomments #?? - #before_validation :set_created_by, :set_code, :set_email, :on => :create before_validation :set_code, :set_email, :on => :create @@ -75,9 +73,12 @@ class Ticket < CouchRest::Model::Base save end - #probably not useful, but trying it: - def ticket_comment_attributes=(attributes) - @ticket_comment = TicketComment.new(attributes) + 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 -- cgit v1.2.3 From 56273c13f54a872d02db286c90a8d5103cf7a663 Mon Sep 17 00:00:00 2001 From: jessib Date: Fri, 12 Oct 2012 14:42:57 -0700 Subject: more work on ticket creation/updating functionality --- help/app/models/ticket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'help/app/models/ticket.rb') diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index e829a5f..537a7c6 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -37,7 +37,7 @@ class Ticket < CouchRest::Model::Base end validates :title, :presence => true - validates :comments, :presence => true #do we want it like this? + #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. -- cgit v1.2.3 From 48d6c2aac9ae2bf1c140e734a576e45289c99150 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 16 Oct 2012 15:51:35 -0700 Subject: Some functional tests and other tweaks. --- help/app/models/ticket.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'help/app/models/ticket.rb') diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index 537a7c6..76fa5c8 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, 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? + property :created_by, String, :protected => true #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 @@ -32,6 +32,9 @@ class Ticket < CouchRest::Model::Base #before_validation :set_created_by, :set_code, :set_email, :on => :create before_validation :set_code, :set_email, :on => :create + + #named_scope :open, :conditions => {:is_open => true} #?? + design do view :by_title end @@ -60,7 +63,7 @@ class Ticket < CouchRest::Model::Base def set_email self.email = nil if self.email == "" - #self.email = current users email if is_creator_validated? + # in controller set to be current users email if that exists end def close @@ -74,8 +77,9 @@ class Ticket < CouchRest::Model::Base 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_by = User.current_test.id if User.current_test #should we not access User.current here? comment.posted_at = Time.now comments << comment -- cgit v1.2.3 From 8b9d5235faed6c15e8ef2e2dc76aec7f24d0bb50 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 18 Oct 2012 13:42:37 -0700 Subject: Uses the working authentication code. --- help/app/models/ticket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'help/app/models/ticket.rb') diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index 76fa5c8..f38fed2 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -79,7 +79,7 @@ class Ticket < CouchRest::Model::Base def comments_attributes=(attributes) comment = TicketComment.new(attributes.values.first) #TicketComment.new(attributes) - comment.posted_by = User.current_test.id if User.current_test #should we not access User.current here? + #comment.posted_by = User.current.id if User.current #we want to avoid User.current, and current_user won't work here. instead will set in tickets_controller comment.posted_at = Time.now comments << comment -- cgit v1.2.3