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

Move update issue code to separate service

parent cfd9fd30
No related branches found
No related tags found
No related merge requests found
Loading
@@ -74,8 +74,7 @@ class Projects::IssuesController < Projects::ApplicationController
Loading
@@ -74,8 +74,7 @@ class Projects::IssuesController < Projects::ApplicationController
end end
   
def update def update
@issue.update_attributes(params[:issue]) @issue = Issues::UpdateService.new(project, current_user, params[:issue]).execute(issue)
@issue.reset_events_cache
   
respond_to do |format| respond_to do |format|
format.js format.js
Loading
Loading
Loading
@@ -12,16 +12,6 @@ class IssueObserver < BaseObserver
Loading
@@ -12,16 +12,6 @@ class IssueObserver < BaseObserver
execute_hooks(issue) execute_hooks(issue)
end end
   
def after_update(issue)
if issue.is_being_reassigned?
notification.reassigned_issue(issue, current_user)
create_assignee_note(issue)
end
issue.notice_added_references(issue.project, current_user)
execute_hooks(issue)
end
protected protected
   
# Create issue note with service comment like 'Status changed to closed' # Create issue note with service comment like 'Status changed to closed'
Loading
Loading
module Issues
class BaseService < ::BaseService
private
# Create issue note with service comment like 'Status changed to closed'
def create_note(issue)
Note.create_status_change_note(issue, issue.project, current_user, issue.state, current_commit)
end
def create_assignee_note(issue)
Note.create_assignee_change_note(issue, issue.project, current_user, issue.assignee)
end
def execute_hooks(issue)
issue.project.execute_hooks(issue.to_hook_data, :issue_hooks)
end
end
end
Loading
@@ -13,11 +13,5 @@ module Issues
Loading
@@ -13,11 +13,5 @@ module Issues
   
issue issue
end end
private
def execute_hooks(issue)
issue.project.execute_hooks(issue.to_hook_data, :issue_hooks)
end
end end
end end
module Issues
class UpdateService < BaseService
def execute(issue)
if issue.update_attributes(params)
issue.reset_events_cache
if issue.is_being_reassigned?
notification.reassigned_issue(issue, current_user)
create_assignee_note(issue)
end
issue.notice_added_references(issue.project, current_user)
execute_hooks(issue)
end
issue
end
end
end
Loading
@@ -74,18 +74,18 @@ module API
Loading
@@ -74,18 +74,18 @@ module API
# Example Request: # Example Request:
# PUT /projects/:id/issues/:issue_id # PUT /projects/:id/issues/:issue_id
put ":id/issues/:issue_id" do put ":id/issues/:issue_id" do
set_current_user_for_thread do issue = user_project.issues.find(params[:issue_id])
@issue = user_project.issues.find(params[:issue_id]) authorize! :modify_issue, issue
authorize! :modify_issue, @issue
   
attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event] attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event]
attrs[:label_list] = params[:labels] if params[:labels].present? attrs[:label_list] = params[:labels] if params[:labels].present?
issue = ::Issues::UpdateService.new(user_project, current_user, attrs).execute(issue)
   
if @issue.update_attributes attrs if issue.valid?
present @issue, with: Entities::Issue present issue, with: Entities::Issue
else else
not_found! not_found!
end
end end
end end
   
Loading
Loading
Loading
@@ -17,6 +17,7 @@ describe Issues::CreateService do
Loading
@@ -17,6 +17,7 @@ describe Issues::CreateService do
end end
   
it { @issue.should be_valid } it { @issue.should be_valid }
it { @issue.title.should == 'Awesome issue' }
end end
end end
end end
require 'spec_helper'
describe Issues::UpdateService do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
let(:issue) { create(:issue) }
describe :execute do
context "valid params" do
before do
project.team << [user, :master]
opts = {
title: 'New title',
description: 'Also please fix'
}
@issue = Issues::UpdateService.new(project, user, opts).execute(issue)
end
it { @issue.should be_valid }
it { @issue.title.should == 'New title' }
end
end
end
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