Skip to content
Snippets Groups Projects
Commit 993af5d0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

cattr_accessor is not threadsafe!

parent 5511a731
No related branches found
No related tags found
No related merge requests found
class ApplicationController < ActionController::Base
before_filter :authenticate_user!
before_filter :reject_blocked!
before_filter :set_current_user_for_observers
before_filter :set_current_user_for_thread
before_filter :add_abilities
before_filter :dev_tools if Rails.env == 'development'
before_filter :default_headers
Loading
Loading
@@ -47,9 +47,8 @@ class ApplicationController < ActionController::Base
end
end
 
def set_current_user_for_observers
MergeRequestObserver.current_user = current_user
IssueObserver.current_user = current_user
def set_current_user_for_thread
Thread.current[:current_user] = current_user
end
 
def abilities
Loading
Loading
Loading
Loading
@@ -6,4 +6,8 @@ class BaseObserver < ActiveRecord::Observer
def log_info message
Gitlab::AppLogger.info message
end
def current_user
Thread.current[:current_user]
end
end
class IssueObserver < BaseObserver
cattr_accessor :current_user
def after_create(issue)
notification.new_issue(issue, current_user)
end
Loading
Loading
class MergeRequestObserver < BaseObserver
cattr_accessor :current_user
def after_create(merge_request)
notification.new_merge_request(merge_request, current_user)
end
Loading
Loading
Loading
Loading
@@ -6,7 +6,7 @@ production:
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 5
pool: 10
username: root
password: "secure password"
# host: localhost
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ production:
adapter: postgresql
encoding: unicode
database: gitlabhq_production
pool: 5
pool: 10
username: git
password:
# host: localhost
Loading
Loading
Loading
Loading
@@ -2,6 +2,7 @@ module API
# Issues API
class Issues < Grape::API
before { authenticate! }
before { Thread.current[:current_user] = current_user }
 
resource :issues do
# Get currently authenticated user's issues
Loading
Loading
@@ -79,7 +80,7 @@ module API
 
attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event]
attrs[:label_list] = params[:labels] if params[:labels].present?
IssueObserver.current_user = current_user
if @issue.update_attributes attrs
present @issue, with: Entities::Issue
else
Loading
Loading
Loading
Loading
@@ -2,6 +2,7 @@ module API
# MergeRequest API
class MergeRequests < Grape::API
before { authenticate! }
before { Thread.current[:current_user] = current_user }
 
resource :projects do
helpers do
Loading
Loading
@@ -94,8 +95,6 @@ module API
 
authorize! :modify_merge_request, merge_request
 
MergeRequestObserver.current_user = current_user
if merge_request.update_attributes attrs
merge_request.reload_code
merge_request.mark_as_unchecked
Loading
Loading
Loading
Loading
@@ -39,7 +39,6 @@ describe Milestone do
end
 
it "should count closed issues" do
IssueObserver.current_user = issue.author
issue.close
milestone.issues << issue
milestone.percent_complete.should == 100
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment