summaryrefslogtreecommitdiff
path: root/help/app
diff options
context:
space:
mode:
Diffstat (limited to 'help/app')
-rw-r--r--help/app/controllers/tickets_controller.rb25
-rw-r--r--help/app/models/ticket.rb12
-rw-r--r--help/app/models/ticket_comment.rb4
-rw-r--r--help/app/views/tickets/_comment.html.haml2
-rw-r--r--help/app/views/tickets/index.html.haml8
-rw-r--r--help/app/views/tickets/new.html.haml4
-rw-r--r--help/app/views/tickets/show.html.haml13
7 files changed, 46 insertions, 22 deletions
diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb
index f4b38de..4c7415b 100644
--- a/help/app/controllers/tickets_controller.rb
+++ b/help/app/controllers/tickets_controller.rb
@@ -1,6 +1,7 @@
class TicketsController < ApplicationController
respond_to :html #, :json
+ #has_scope :open, :type => boolean
def new
@ticket = Ticket.new
@@ -8,10 +9,14 @@ class TicketsController < ApplicationController
end
def create
- @ticket = Ticket.new #:created_by => User.current_test.id
- @ticket.attributes = params[:ticket]#.except(:comments)
- @ticket.created_by = User.current_test.id if User.current_test
- #instead of calling add_comment, we are using comment_attributes= from the Ticket model
+ @ticket = Ticket.new(params[:ticket])
+ if current_user
+ @ticket.created_by = current_user.id
+ @ticket.email = current_user.email if current_user.email
+ @ticket.comments.last.posted_by = current_user.id
+ else
+ @ticket.comments.last.posted_by = nil #hacky, but protecting this attribute doesn't work right, so this should make sure it isn't set.
+ end
flash[:notice] = 'Ticket was successfully created.' if @ticket.save
respond_with(@ticket)
@@ -35,8 +40,9 @@ class TicketsController < ApplicationController
def update
@ticket = Ticket.find(params[:id])
@ticket.attributes = params[:ticket]
- #add_comment #or should we use ticket attributes?
- # @ticket.save
+
+ @ticket.comments.last.posted_by = (current_user ? current_user.id : nil) #protecting posted_by isn't working, so this should protect it.
+
if @ticket.save
flash[:notice] = 'Ticket was successfully updated.'
respond_with @ticket
@@ -50,17 +56,18 @@ class TicketsController < ApplicationController
def index
# @tickets = Ticket.by_title #not actually what we will want
- respond_with(@tickets = Ticket.all)
+ respond_with(@tickets = Ticket.all) #we'll want only tickets that this user can access
end
private
# not using now, as we are using comment_attributes= from the Ticket model
+=begin
def add_comment
comment = TicketComment.new(params[:comment])
- comment.posted_by = User.current_test.id if User.current_test #could be nil
+ comment.posted_by = User.current.id if User.current #could be nil
comment.posted_at = Time.now # TODO: it seems strange to have this here, and not in model
@ticket.comments << comment
end
-
+=end
end
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb
index 537a7c6..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, 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.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
diff --git a/help/app/models/ticket_comment.rb b/help/app/models/ticket_comment.rb
index 9026bc1..49e5c6c 100644
--- a/help/app/models/ticket_comment.rb
+++ b/help/app/models/ticket_comment.rb
@@ -2,13 +2,13 @@ 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_verified, TrueClass, :protected => true #should be true if current_user is set when the comment is created
property :body, String
-
+ # ? timestamps!
validates :body, :presence => true
#before_validation :set_time#, :set_posted_by
diff --git a/help/app/views/tickets/_comment.html.haml b/help/app/views/tickets/_comment.html.haml
index 19e1ddf..1ba3bd1 100644
--- a/help/app/views/tickets/_comment.html.haml
+++ b/help/app/views/tickets/_comment.html.haml
@@ -3,6 +3,8 @@
- if User.find(comment.posted_by)
Posted by
= User.find(comment.posted_by).login
+ - else
+ Unauthenticated post
%p
Posted at
= comment.posted_at
diff --git a/help/app/views/tickets/index.html.haml b/help/app/views/tickets/index.html.haml
index d2e0ea0..6db2140 100644
--- a/help/app/views/tickets/index.html.haml
+++ b/help/app/views/tickets/index.html.haml
@@ -1,8 +1,10 @@
+%h2 tickets index (just as space)
+Create a
+= link_to "new ticket", new_ticket_path
+= # below shouldn't be unless logged in
%h2 Tickets
+= # want to have selection option to see tickets, that are open, closed or all
- @tickets.each do |ticket|
%p
= link_to ticket.title, ticket
-%p
-Create a
-= link_to "new ticket", new_ticket_path
= #render(:partial => "ticket", :collection => @tickets)
diff --git a/help/app/views/tickets/new.html.haml b/help/app/views/tickets/new.html.haml
index d784720..537b97f 100644
--- a/help/app/views/tickets/new.html.haml
+++ b/help/app/views/tickets/new.html.haml
@@ -1,9 +1,9 @@
%h2=t :new_ticket
-= simple_form_for (@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test
+= simple_form_for(@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test
= #@ticket.errors.messages
= f.input :title
= #f.input :email #if there is no current_user
- = f.input :email if !User.current_test #hmm--might authenticated users want to submit an alternate email?
+ = f.input :email if !current_user #hmm--might authenticated users want to submit an alternate email?
= f.simple_fields_for :comments do |c|
= c.input :body, :label => 'Comment', :as => :text
diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml
index 04dd676..a9b994e 100644
--- a/help/app/views/tickets/show.html.haml
+++ b/help/app/views/tickets/show.html.haml
@@ -5,8 +5,17 @@
%h2= @ticket.title
is open?
= @ticket.is_open
-code:
-= @ticket.code
+- if @ticket.code
+ code:
+ = @ticket.code
+- if @ticket.email
+ email:
+ = @ticket.email
+- if User.find(@ticket.created_by)
+ Created by
+ = User.find(@ticket.created_by).login
+- else
+ Unauthenticated ticket creator
= render(:partial => "comment", :collection => @ticket.comments)
= simple_form_for (@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test