summaryrefslogtreecommitdiff
path: root/help/app/models
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2012-10-31 12:19:15 -0700
committerjessib <jessib@riseup.net>2012-10-31 12:19:15 -0700
commit872b9fa6759d5708f5efb19ba46b3c8e2b5d4862 (patch)
treee62b451a6c58825963bdb43c7f238aae272fdc80 /help/app/models
parent6c60b179a09030da985462d15dbdf076367b5ea4 (diff)
Looks like the help code has already been merged into the develop branch, and thus merging into feature-admin_users branch.
Diffstat (limited to 'help/app/models')
-rw-r--r--help/app/models/ticket.rb36
-rw-r--r--help/app/models/ticket_comment.rb14
2 files changed, 40 insertions, 10 deletions
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb
index 784d7ef..f38fed2 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, :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
@@ -29,18 +29,27 @@ 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
+
+
+ #named_scope :open, :conditions => {:is_open => true} #??
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 +60,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 == ""
+ # in controller set to be current users email if that exists
+ end
+
def close
self.is_open = false
save
@@ -61,6 +76,15 @@ 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.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
+
+ 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 652133a..49e5c6c 100644
--- a/help/app/models/ticket_comment.rb
+++ b/help/app/models/ticket_comment.rb
@@ -2,13 +2,15 @@ class TicketComment
include CouchRest::Model::Embeddable
#belongs_to :ticket #is this best way to do it? will want to access all of a tickets comments, so maybe this isn't the way?
- property :posted_by, Integer, :protected => true# maybe this should be current_user if that is set, meaning the user is logged in #String # user??
+ property :posted_by, String#, :protected => true #Integer#this should be current_user if that is set, meaning the user is logged in #cannot have it be protected and set via comments_attributes=. also, if it is protected and we set in the tickets_controller, it gets unset. TODO---is this okay to have it not protected and manually check it? We do not users to be able to set this.
# if the current user is not set, then we could just say the comment comes from an 'unauthenticated user', which would be somebody with the secret URL
- property :posted_at, Time, :protected => true
+ property :posted_at, Time#, :protected => true
#property :posted_verified, TrueClass, :protected => true #should be true if current_user is set when the comment is created
property :body, String
- before_validation :set_time#, :set_posted_by
+ # ? timestamps!
+ validates :body, :presence => true
+ #before_validation :set_time#, :set_posted_by
#design do
# view :by_posted_at
@@ -18,10 +20,14 @@ class TicketComment
def is_comment_validated?
!!posted_by
end
-
+
+=begin
+ #TODO.
+ #this is resetting all comments associated with the ticket:
def set_time
self.posted_at = Time.now
end
+=end
=begin
def set_posted_by