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