summaryrefslogtreecommitdiff
path: root/lib/api/issues.rb
diff options
context:
space:
mode:
authorAngus MacArthur <amacarthur@blackberry.com>2013-10-04 15:11:50 -0400
committerAngus MacArthur <amacarthur@blackberry.com>2013-10-16 01:20:53 -0400
commitaefe2e952f33267ce38fb9270400f4f6f194d37b (patch)
tree3546807c2b7942585a41cfb1163dc5e6a69e40e0 /lib/api/issues.rb
parenta8eb525e72f6883a07539af9429ccd41dbc8698b (diff)
downloadgitlab-ce-aefe2e952f33267ce38fb9270400f4f6f194d37b.tar.gz
Fixing unsafe use of Thread.current variable :current_user
Diffstat (limited to 'lib/api/issues.rb')
-rw-r--r--lib/api/issues.rb39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index a15203d1563..3d15c35b8cc 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -2,7 +2,6 @@ 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
@@ -49,15 +48,17 @@ module API
# Example Request:
# POST /projects/:id/issues
post ":id/issues" do
- required_attributes! [:title]
- attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id]
- attrs[:label_list] = params[:labels] if params[:labels].present?
- @issue = user_project.issues.new attrs
- @issue.author = current_user
- if @issue.save
- present @issue, with: Entities::Issue
- else
- not_found!
+ set_current_user_for_thread do
+ required_attributes! [:title]
+ attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id]
+ attrs[:label_list] = params[:labels] if params[:labels].present?
+ @issue = user_project.issues.new attrs
+ @issue.author = current_user
+ if @issue.save
+ present @issue, with: Entities::Issue
+ else
+ not_found!
+ end
end
end
@@ -75,16 +76,18 @@ module API
# Example Request:
# PUT /projects/:id/issues/:issue_id
put ":id/issues/:issue_id" do
- @issue = user_project.issues.find(params[:issue_id])
- authorize! :modify_issue, @issue
+ set_current_user_for_thread do
+ @issue = user_project.issues.find(params[:issue_id])
+ authorize! :modify_issue, @issue
- attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event]
- attrs[:label_list] = params[:labels] if params[:labels].present?
+ attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event]
+ attrs[:label_list] = params[:labels] if params[:labels].present?
- if @issue.update_attributes attrs
- present @issue, with: Entities::Issue
- else
- not_found!
+ if @issue.update_attributes attrs
+ present @issue, with: Entities::Issue
+ else
+ not_found!
+ end
end
end