Commit 0a1b4ba2 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'remove-thread-var' into 'master'

Remove thread variables

Lets get rid of thread variables. It produces additional complexity and weird stack trace.

Also part of !1133

- - -

Also it fixes issue/merge_request close and reopen bug via API when no dashboard event and comment was created.
parents f451a697 f6ee55aa
...@@ -4,7 +4,6 @@ class ApplicationController < ActionController::Base ...@@ -4,7 +4,6 @@ class ApplicationController < ActionController::Base
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :reject_blocked! before_filter :reject_blocked!
before_filter :check_password_expiration before_filter :check_password_expiration
around_filter :set_current_user_for_thread
before_filter :add_abilities before_filter :add_abilities
before_filter :ldap_security_check before_filter :ldap_security_check
before_filter :dev_tools if Rails.env == 'development' before_filter :dev_tools if Rails.env == 'development'
...@@ -53,15 +52,6 @@ class ApplicationController < ActionController::Base ...@@ -53,15 +52,6 @@ class ApplicationController < ActionController::Base
end end
end end
def set_current_user_for_thread
Thread.current[:current_user] = current_user
begin
yield
ensure
Thread.current[:current_user] = nil
end
end
def abilities def abilities
@abilities ||= Six.new @abilities ||= Six.new
end end
......
...@@ -37,7 +37,7 @@ class Projects::MilestonesController < Projects::ApplicationController ...@@ -37,7 +37,7 @@ class Projects::MilestonesController < Projects::ApplicationController
end end
def create def create
@milestone = @project.milestones.new(params[:milestone]) @milestone = Milestones::CreateService.new(project, current_user, params[:milestone]).execute
if @milestone.save if @milestone.save
redirect_to project_milestone_path(@project, @milestone) redirect_to project_milestone_path(@project, @milestone)
...@@ -47,7 +47,7 @@ class Projects::MilestonesController < Projects::ApplicationController ...@@ -47,7 +47,7 @@ class Projects::MilestonesController < Projects::ApplicationController
end end
def update def update
@milestone.update_attributes(params[:milestone]) @milestone = Milestones::UpdateService.new(project, current_user, params[:milestone]).execute(milestone)
respond_to do |format| respond_to do |format|
format.js format.js
......
...@@ -10,12 +10,4 @@ class BaseObserver < ActiveRecord::Observer ...@@ -10,12 +10,4 @@ class BaseObserver < ActiveRecord::Observer
def log_info message def log_info message
Gitlab::AppLogger.info message Gitlab::AppLogger.info message
end end
def current_user
Thread.current[:current_user]
end
def current_commit
Thread.current[:current_commit]
end
end end
class MilestoneObserver < BaseObserver
def after_create(milestone)
event_service.open_milestone(milestone, current_user)
end
def after_close(milestone, transition)
event_service.close_milestone(milestone, current_user)
end
def after_reopen(milestone, transition)
event_service.reopen_milestone(milestone, current_user)
end
end
...@@ -5,7 +5,7 @@ class NoteObserver < BaseObserver ...@@ -5,7 +5,7 @@ class NoteObserver < BaseObserver
# Skip system notes, like status changes and cross-references. # Skip system notes, like status changes and cross-references.
# Skip wall notes to prevent spamming of dashboard # Skip wall notes to prevent spamming of dashboard
if note.noteable_type.present? && !note.system if note.noteable_type.present? && !note.system
event_service.leave_note(note, current_user) event_service.leave_note(note, note.author)
end end
unless note.system? unless note.system?
...@@ -18,6 +18,6 @@ class NoteObserver < BaseObserver ...@@ -18,6 +18,6 @@ class NoteObserver < BaseObserver
end end
def after_update(note) def after_update(note)
note.notice_added_references(note.project, current_user) note.notice_added_references(note.project, note.author)
end end
end end
module Issues module Issues
class UpdateService < Issues::BaseService class UpdateService < Issues::BaseService
def execute(issue) def execute(issue)
state = params.delete('state_event') state = params.delete('state_event') || params.delete(:state_event)
case state case state
when 'reopen' when 'reopen'
......
...@@ -10,7 +10,7 @@ module MergeRequests ...@@ -10,7 +10,7 @@ module MergeRequests
params.delete(:source_project_id) params.delete(:source_project_id)
params.delete(:target_project_id) params.delete(:target_project_id)
state = params.delete('state_event') state = params.delete('state_event') || params.delete(:state_event)
case state case state
when 'reopen' when 'reopen'
......
module Milestones
class BaseService < ::BaseService
end
end
module Milestones
class CloseService < Milestones::BaseService
def execute(milestone)
if milestone.close
event_service.close_milestone(milestone, current_user)
end
milestone
end
end
end
module Milestones
class CreateService < Milestones::BaseService
def execute
milestone = project.milestones.new(params)
if milestone.save
event_service.open_milestone(milestone, current_user)
end
milestone
end
end
end
module Milestones
class ReopenService < Milestones::BaseService
def execute(milestone)
if milestone.activate
event_service.reopen_milestone(milestone, current_user)
end
milestone
end
end
end
module Milestones
class UpdateService < Milestones::BaseService
def execute(milestone)
state = params.delete('state_event') || params.delete(:state_event)
case state
when 'activate'
Milestones::ReopenService.new(project, current_user, {}).execute(milestone)
when 'close'
Milestones::CloseService.new(project, current_user, {}).execute(milestone)
end
if params.present?
milestone.update_attributes(params)
end
milestone
end
end
end
...@@ -19,8 +19,7 @@ module Gitlab ...@@ -19,8 +19,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ] # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running. # Activate observers that should always be running.
config.active_record.observers = :milestone_observer, config.active_record.observers = :project_activity_cache_observer,
:project_activity_cache_observer,
:note_observer, :note_observer,
:project_observer, :project_observer,
:system_hook_observer, :system_hook_observer,
......
...@@ -36,16 +36,6 @@ module API ...@@ -36,16 +36,6 @@ module API
end end
end end
def set_current_user_for_thread
Thread.current[:current_user] = current_user
begin
yield
ensure
Thread.current[:current_user] = nil
end
end
def user_project def user_project
@project ||= find_project(params[:id]) @project ||= find_project(params[:id])
@project || not_found! @project || not_found!
......
...@@ -184,7 +184,6 @@ module API ...@@ -184,7 +184,6 @@ module API
# POST /projects/:id/merge_request/:merge_request_id/comments # POST /projects/:id/merge_request/:merge_request_id/comments
# #
post ":id/merge_request/:merge_request_id/comments" do post ":id/merge_request/:merge_request_id/comments" do
set_current_user_for_thread do
required_attributes! [:note] required_attributes! [:note]
merge_request = user_project.merge_requests.find(params[:merge_request_id]) merge_request = user_project.merge_requests.find(params[:merge_request_id])
...@@ -198,7 +197,5 @@ module API ...@@ -198,7 +197,5 @@ module API
end end
end end
end end
end
end end
end end
...@@ -40,19 +40,17 @@ module API ...@@ -40,19 +40,17 @@ module API
# Example Request: # Example Request:
# POST /projects/:id/milestones # POST /projects/:id/milestones
post ":id/milestones" do post ":id/milestones" do
set_current_user_for_thread do
authorize! :admin_milestone, user_project authorize! :admin_milestone, user_project
required_attributes! [:title] required_attributes! [:title]
attrs = attributes_for_keys [:title, :description, :due_date] attrs = attributes_for_keys [:title, :description, :due_date]
@milestone = user_project.milestones.new attrs milestone = ::Milestones::CreateService.new(user_project, current_user, attrs).execute
if @milestone.save
present @milestone, with: Entities::Milestone if milestone.valid?
present milestone, with: Entities::Milestone
else else
not_found! not_found!
end end
end end
end
# Update an existing project milestone # Update an existing project milestone
# #
...@@ -66,18 +64,17 @@ module API ...@@ -66,18 +64,17 @@ module API
# Example Request: # Example Request:
# PUT /projects/:id/milestones/:milestone_id # PUT /projects/:id/milestones/:milestone_id
put ":id/milestones/:milestone_id" do put ":id/milestones/:milestone_id" do
set_current_user_for_thread do
authorize! :admin_milestone, user_project authorize! :admin_milestone, user_project
@milestone = user_project.milestones.find(params[:milestone_id])
attrs = attributes_for_keys [:title, :description, :due_date, :state_event] attrs = attributes_for_keys [:title, :description, :due_date, :state_event]
if @milestone.update_attributes attrs milestone = user_project.milestones.find(params[:milestone_id])
present @milestone, with: Entities::Milestone milestone = ::Milestones::UpdateService.new(user_project, current_user, attrs).execute(milestone)
if milestone.valid?
present milestone, with: Entities::Milestone
else else
not_found! not_found!
end end
end end
end end
end end
end
end end
...@@ -41,7 +41,6 @@ module API ...@@ -41,7 +41,6 @@ module API
# Example Request: # Example Request:
# POST /projects/:id/notes # POST /projects/:id/notes
post ":id/notes" do post ":id/notes" do
set_current_user_for_thread do
required_attributes! [:body] required_attributes! [:body]
@note = user_project.notes.new(note: params[:body]) @note = user_project.notes.new(note: params[:body])
...@@ -55,7 +54,6 @@ module API ...@@ -55,7 +54,6 @@ module API
not_found! not_found!
end end
end end
end
NOTEABLE_TYPES.each do |noteable_type| NOTEABLE_TYPES.each do |noteable_type|
noteables_str = noteable_type.to_s.underscore.pluralize noteables_str = noteable_type.to_s.underscore.pluralize
...@@ -99,7 +97,6 @@ module API ...@@ -99,7 +97,6 @@ module API
# POST /projects/:id/issues/:noteable_id/notes # POST /projects/:id/issues/:noteable_id/notes
# POST /projects/:id/snippets/:noteable_id/notes # POST /projects/:id/snippets/:noteable_id/notes
post ":id/#{noteables_str}/:#{noteable_id_str}/notes" do post ":id/#{noteables_str}/:#{noteable_id_str}/notes" do
set_current_user_for_thread do
required_attributes! [:body] required_attributes! [:body]
@noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"]) @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"])
...@@ -116,5 +113,4 @@ module API ...@@ -116,5 +113,4 @@ module API
end end
end end
end end
end
end end
...@@ -9,12 +9,7 @@ module Gitlab ...@@ -9,12 +9,7 @@ module Gitlab
end end
def self.by_user(user) def self.by_user(user)
begin
Thread.current[:current_user] = user
yield yield
ensure
Thread.current[:current_user] = nil
end
end end
def self.mute_mailer def self.mute_mailer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment