summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--help/app/models/ticket.rb6
-rw-r--r--help/app/models/ticket_comment.rb3
-rw-r--r--help/test/unit/ticket_comment_test.rb7
-rw-r--r--help/test/unit/ticket_test.rb3
-rw-r--r--users/app/controllers/sessions_controller.rb6
-rw-r--r--users/app/models/user.rb7
6 files changed, 27 insertions, 5 deletions
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb
index 8a282b5..0f38bf4 100644
--- a/help/app/models/ticket.rb
+++ b/help/app/models/ticket.rb
@@ -28,7 +28,7 @@ class Ticket < CouchRest::Model::Base
timestamps!
- before_validation :set_code, :on => :create
+ before_validation :set_created_by, :set_code, :on => :create
design do
view :by_title
@@ -37,7 +37,9 @@ class Ticket < CouchRest::Model::Base
validates :email, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :if => :email #email address is optional
- #set created_by to be current_user
+ def set_created_by
+ self.created_by = User.current if User.current
+ end
def is_creator_validated?
!!created_by
diff --git a/help/app/models/ticket_comment.rb b/help/app/models/ticket_comment.rb
index 1e23136..6c2a792 100644
--- a/help/app/models/ticket_comment.rb
+++ b/help/app/models/ticket_comment.rb
@@ -26,8 +26,7 @@ class TicketComment < CouchRest::Model::Base #?? do we want this to be a base mo
end
def set_posted_by
- #should be something like this, but current_user is not set yet
- #self.posted_by = current_user if current_user
+ self.posted_by = User.current if User.current
end
end
diff --git a/help/test/unit/ticket_comment_test.rb b/help/test/unit/ticket_comment_test.rb
index 37e6e67..ba6120b 100644
--- a/help/test/unit/ticket_comment_test.rb
+++ b/help/test/unit/ticket_comment_test.rb
@@ -25,6 +25,13 @@ class TicketCommentTest < ActiveSupport::TestCase
#tc.ticket = Ticket.find_by_title("test title")
#tc.ticket.title
end
+
+ test "create authenticated comment" do
+ User.current = 4
+ comment2 = TicketComment.new :body => "help my email is broken!"
+ comment2.save
+ assert_not_nil comment2.posted_by
+ end
test "add comments" do
testticket = Ticket.create :title => "testing"
diff --git a/help/test/unit/ticket_test.rb b/help/test/unit/ticket_test.rb
index fddd719..2dbd63c 100644
--- a/help/test/unit/ticket_test.rb
+++ b/help/test/unit/ticket_test.rb
@@ -41,7 +41,8 @@ class TicketTest < ActiveSupport::TestCase
assert_not_nil t1.code
assert_nil t1.created_by
- t2 = Ticket.create :title => 'test title', :created_by => 4
+ User.current = 4
+ t2 = Ticket.create :title => 'test title'
assert_nil t2.code
assert_not_nil t2.created_by
diff --git a/users/app/controllers/sessions_controller.rb b/users/app/controllers/sessions_controller.rb
index e68d798..d398057 100644
--- a/users/app/controllers/sessions_controller.rb
+++ b/users/app/controllers/sessions_controller.rb
@@ -8,6 +8,7 @@ class SessionsController < ApplicationController
def create
@user = User.find_by_param(params[:login])
session[:handshake] = @user.initialize_auth(params['A'].hex)
+ User.current = @user #?
render :json => { :B => session[:handshake].bb.to_s(16) }
rescue RECORD_NOT_FOUND
render :json => {:errors => {:login => ["unknown user"]}}
@@ -17,6 +18,7 @@ class SessionsController < ApplicationController
@user = User.find_by_param(params[:id])
@server_auth = @user.authenticate!(params[:client_auth].hex, session.delete(:handshake))
session[:user_id] = @user.id
+ User.current = @user #?
render :json => {:M2 => @server_auth}
rescue WRONG_PASSWORD
session[:handshake] = nil
@@ -25,6 +27,10 @@ class SessionsController < ApplicationController
def destroy
session[:user_id] = nil
+ User.current = nil #?
redirect_to root_path
end
+
+
+
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index fa64f42..95ee810 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -46,4 +46,11 @@ class User < CouchRest::Model::Base
password_verifier.hex
end
+ def self.current
+ Thread.current[:user]
+ end
+ def self.current=(user)
+ Thread.current[:user] = user
+ end
+
end