summaryrefslogtreecommitdiff
path: root/help/app/models
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2012-10-10 10:55:25 -0700
committerjessib <jessib@riseup.net>2012-10-10 10:55:25 -0700
commitc27f2a0686db0705553eda88c799d4c486c20bac (patch)
treeedc4e1b36e747fb87ac429d2fd348abfaec11c28 /help/app/models
parentb077363d51de511d53c9b20ade1cb26707f3ecdf (diff)
Pushing some tweaks as I try to get server-side validation working.
Diffstat (limited to 'help/app/models')
-rw-r--r--help/app/models/ticket.rb16
-rw-r--r--help/app/models/ticket_comment.rb2
2 files changed, 16 insertions, 2 deletions
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
diff --git a/help/app/models/ticket_comment.rb b/help/app/models/ticket_comment.rb
index 6b6b4db..9026bc1 100644
--- a/help/app/models/ticket_comment.rb
+++ b/help/app/models/ticket_comment.rb
@@ -8,6 +8,8 @@ class TicketComment
#property :posted_verified, TrueClass, :protected => true #should be true if current_user is set when the comment is created
property :body, String
+
+ validates :body, :presence => true
#before_validation :set_time#, :set_posted_by
#design do