summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-10-29 19:19:35 +0100
committerAzul <azul@leap.se>2012-10-29 19:19:35 +0100
commit428aea3c577c44a3bb13cced23c5c0cafc5b4d93 (patch)
treee36349452e599c11b67e1912df2e68db5140c504
parent3ba2e664a26e96a93c8640b57241af6386db361e (diff)
parent56273c13f54a872d02db286c90a8d5103cf7a663 (diff)
Merge branch 'help_develop' into develop
-rw-r--r--.gitignore1
-rw-r--r--Gemfile2
-rw-r--r--app/views/home/index.html.haml8
-rw-r--r--help/app/controllers/tickets_controller.rb66
-rw-r--r--help/app/models/ticket.rb32
-rw-r--r--help/app/models/ticket_comment.rb14
-rw-r--r--help/app/views/tickets/_comment.html.haml11
-rw-r--r--help/app/views/tickets/_new_comment.html.haml3
-rw-r--r--help/app/views/tickets/index.html.haml8
-rw-r--r--help/app/views/tickets/new.html.haml16
-rw-r--r--help/app/views/tickets/show.html.haml17
-rw-r--r--help/config/routes.rb3
-rw-r--r--help/test/functional/tickets_controller_test.rb15
-rw-r--r--help/test/unit/ticket_comment_test.rb11
-rw-r--r--help/test/unit/ticket_test.rb8
-rw-r--r--users/app/models/user.rb4
16 files changed, 200 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index 3567ebd..93547cd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,7 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
+*~
/pkg
/*/pkg
/log
diff --git a/Gemfile b/Gemfile
index 10c661a..40030b5 100644
--- a/Gemfile
+++ b/Gemfile
@@ -9,7 +9,7 @@ eval(File.read(File.dirname(__FILE__) + '/ui_dependencies.rb'))
gem "leap_web_core", :path => 'core'
gem 'leap_web_users', :path => 'users'
gem 'leap_web_certs', :path => 'certs'
-# gem 'leap_web_help', :path => 'help'
+gem 'leap_web_help', :path => 'help'
# To use debugger
gem 'ruby-debug'
diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml
index 0be7ca2..9e68674 100644
--- a/app/views/home/index.html.haml
+++ b/app/views/home/index.html.haml
@@ -1,3 +1,11 @@
Try to fetch a
= link_to "cert", cert_path
+
+%p
+Try to create a
+= link_to "ticket", new_ticket_path
+
+%p
+See all
+= link_to "tickets", tickets_path
diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb
new file mode 100644
index 0000000..f4b38de
--- /dev/null
+++ b/help/app/controllers/tickets_controller.rb
@@ -0,0 +1,66 @@
+class TicketsController < ApplicationController
+
+ respond_to :html #, :json
+
+ def new
+ @ticket = Ticket.new
+ @ticket.comments.build
+ 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
+
+ flash[:notice] = 'Ticket was successfully created.' if @ticket.save
+ respond_with(@ticket)
+
+ end
+
+=begin
+ def edit
+ @ticket = Ticket.find(params[:id])
+ @ticket.comments.build
+ # build ticket comments?
+ end
+=end
+
+ def show
+ @ticket = Ticket.find(params[:id])
+ # @ticket.comments.build
+ # build ticket comments?
+ end
+
+ def update
+ @ticket = Ticket.find(params[:id])
+ @ticket.attributes = params[:ticket]
+ #add_comment #or should we use ticket attributes?
+ # @ticket.save
+ if @ticket.save
+ flash[:notice] = 'Ticket was successfully updated.'
+ respond_with @ticket
+ else
+ #redirect_to [:show, @ticket] #
+ flash[:alert] = 'Ticket has not been changed'
+ redirect_to @ticket
+ #respond_with(@ticket) # why does this go to edit?? redirect???
+ end
+ end
+
+ def index
+ # @tickets = Ticket.by_title #not actually what we will want
+ respond_with(@tickets = Ticket.all)
+ end
+
+ private
+
+ # not using now, as we are using comment_attributes= from the Ticket model
+ def add_comment
+ comment = TicketComment.new(params[:comment])
+ comment.posted_by = User.current_test.id if User.current_test #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
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
diff --git a/help/app/models/ticket_comment.rb b/help/app/models/ticket_comment.rb
index 652133a..9026bc1 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, Integer#, :protected => true# maybe this should be current_user if that is set, meaning the user is logged in #String # user??
# 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
+
+ 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
diff --git a/help/app/views/tickets/_comment.html.haml b/help/app/views/tickets/_comment.html.haml
new file mode 100644
index 0000000..19e1ddf
--- /dev/null
+++ b/help/app/views/tickets/_comment.html.haml
@@ -0,0 +1,11 @@
+- # style is super ugly but just for now
+%div{:style => "border: solid 1px"}
+ - if User.find(comment.posted_by)
+ Posted by
+ = User.find(comment.posted_by).login
+ %p
+ Posted at
+ = comment.posted_at
+ %p
+ = comment.body
+ %p \ No newline at end of file
diff --git a/help/app/views/tickets/_new_comment.html.haml b/help/app/views/tickets/_new_comment.html.haml
new file mode 100644
index 0000000..a924dfd
--- /dev/null
+++ b/help/app/views/tickets/_new_comment.html.haml
@@ -0,0 +1,3 @@
+= #do we want this partial? not using it now
+= simple_fields_for :comment do |c|
+ = c.input :body, :label => 'Comment', :as => :text
diff --git a/help/app/views/tickets/index.html.haml b/help/app/views/tickets/index.html.haml
new file mode 100644
index 0000000..d2e0ea0
--- /dev/null
+++ b/help/app/views/tickets/index.html.haml
@@ -0,0 +1,8 @@
+%h2 Tickets
+- @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
new file mode 100644
index 0000000..d784720
--- /dev/null
+++ b/help/app/views/tickets/new.html.haml
@@ -0,0 +1,16 @@
+%h2=t :new_ticket
+= 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.simple_fields_for :comments do |c|
+ = c.input :body, :label => 'Comment', :as => :text
+
+ = #render :partial => 'new_comment' #what we were using
+ = # regarding_user if not logged in
+ = # email if not logged in
+ = #f.button :submit, :value => t(:submit), :class => 'btn-primary'
+ = f.button :submit
+ = link_to t(:cancel), tickets_path, :class => :btn
diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml
new file mode 100644
index 0000000..04dd676
--- /dev/null
+++ b/help/app/views/tickets/show.html.haml
@@ -0,0 +1,17 @@
+- if flash[:notice]
+ =flash[:notice]
+- if flash[:alert]
+ =flash[:alert]
+%h2= @ticket.title
+is open?
+= @ticket.is_open
+code:
+= @ticket.code
+= render(:partial => "comment", :collection => @ticket.comments)
+
+= simple_form_for (@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test
+ = f.simple_fields_for :comments, TicketComment.new do |c|
+ = c.input :body, :label => 'Comment', :as => :text
+ = #render :partial => 'new_comment'
+ = f.button :submit
+ = link_to t(:cancel), tickets_path, :class => :btn \ No newline at end of file
diff --git a/help/config/routes.rb b/help/config/routes.rb
index 1daf9a4..5e57e02 100644
--- a/help/config/routes.rb
+++ b/help/config/routes.rb
@@ -1,2 +1,5 @@
Rails.application.routes.draw do
+
+ resources :tickets, :only => [:new, :create, :index, :show, :update]
+ #resources :ticket, :only => [:show]
end
diff --git a/help/test/functional/tickets_controller_test.rb b/help/test/functional/tickets_controller_test.rb
new file mode 100644
index 0000000..6d9ff09
--- /dev/null
+++ b/help/test/functional/tickets_controller_test.rb
@@ -0,0 +1,15 @@
+require 'test_helper'
+
+class TicketsControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+ test "should get new" do
+ get :new
+ assert_equal Ticket, assigns(:ticket).class
+ assert_response :success
+ end
+
+
+
+end
diff --git a/help/test/unit/ticket_comment_test.rb b/help/test/unit/ticket_comment_test.rb
index 883720f..1fe1fe2 100644
--- a/help/test/unit/ticket_comment_test.rb
+++ b/help/test/unit/ticket_comment_test.rb
@@ -16,8 +16,8 @@ class TicketCommentTest < ActiveSupport::TestCase
comment2 = TicketComment.new :body => "help my email is broken!"
assert comment2.valid?
- assert_not_nil comment2.posted_at
- assert_nil comment2.posted_by #if not logged in
+ #assert_not_nil comment2.posted_at #?
+ #assert_nil comment2.posted_by #if not logged in #TODO
#comment.ticket = testticket #Ticket.find_by_title("testing")
#assert_equal testticket.title, comment.ticket.title
@@ -49,9 +49,10 @@ class TicketCommentTest < ActiveSupport::TestCase
testticket.comments << comment2 #this should validate comment2
testticket.valid?
assert_equal testticket.comments.count, 2
- assert_not_nil comment.posted_at
- assert_not_nil testticket.comments.last.posted_at
- assert testticket.comments.first.posted_at < testticket.comments.last.posted_at
+ # where should posted_at be set?
+ #assert_not_nil comment.posted_at
+ #assert_not_nil testticket.comments.last.posted_at
+ #assert testticket.comments.first.posted_at < testticket.comments.last.posted_at
end
end
diff --git a/help/test/unit/ticket_test.rb b/help/test/unit/ticket_test.rb
index c3a4759..6b63a23 100644
--- a/help/test/unit/ticket_test.rb
+++ b/help/test/unit/ticket_test.rb
@@ -41,18 +41,20 @@ class TicketTest < ActiveSupport::TestCase
assert @sample.is_creator_validated?
end
+=begin
+# TODO: do once have current_user stuff in order
test "code if & only if not creator-validated" do
+ User.current_test = nil
t1 = Ticket.create :title => 'test title'
assert_not_nil t1.code
assert_nil t1.created_by
- User.current = 4
+ User.current_test = 4
t2 = Ticket.create :title => 'test title'
assert_nil t2.code
assert_not_nil t2.created_by
-
-
end
+=end
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index 1afb9db..8b7c0b3 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -70,4 +70,8 @@ class User < CouchRest::Model::Base
Thread.current[:user] = user
end
+ def self.current_test
+ User.first
+ end
+
end