2014-04-02 06:38:35 -04:00
|
|
|
module Issues
|
2014-04-02 12:55:23 -04:00
|
|
|
class CreateService < Issues::BaseService
|
2016-03-18 09:48:55 -04:00
|
|
|
def execute
|
2016-07-30 00:18:32 -04:00
|
|
|
@request = params.delete(:request)
|
|
|
|
@api = params.delete(:api)
|
2017-01-27 11:25:39 -05:00
|
|
|
@recaptcha_verified = params.delete(:recaptcha_verified)
|
|
|
|
@spam_log_id = params.delete(:spam_log_id)
|
2014-04-02 06:38:35 -04:00
|
|
|
|
2016-10-26 17:21:50 -04:00
|
|
|
issue_attributes = params.merge(merge_request_for_resolving_discussions: merge_request_for_resolving_discussions)
|
|
|
|
@issue = BuildService.new(project, current_user, issue_attributes).execute
|
2016-07-18 19:17:43 -04:00
|
|
|
|
2016-08-16 18:49:53 -04:00
|
|
|
create(@issue)
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
2014-04-02 06:38:35 -04:00
|
|
|
|
2016-08-16 20:59:55 -04:00
|
|
|
def before_create(issuable)
|
2017-01-27 11:25:39 -05:00
|
|
|
if @recaptcha_verified
|
|
|
|
spam_log = current_user.spam_logs.find_by(id: @spam_log_id, title: issuable.title)
|
|
|
|
spam_log.update!(recaptcha_verified: true) if spam_log
|
|
|
|
else
|
|
|
|
issuable.spam = spam_service.check(@api)
|
|
|
|
issuable.spam_log = spam_service.spam_log
|
|
|
|
end
|
2016-08-16 20:59:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def after_create(issuable)
|
2016-06-30 11:34:19 -04:00
|
|
|
event_service.open_issue(issuable, current_user)
|
|
|
|
notification_service.new_issue(issuable, current_user)
|
|
|
|
todo_service.new_issue(issuable, current_user)
|
2016-08-16 18:49:53 -04:00
|
|
|
user_agent_detail_service.create
|
2016-10-26 17:21:50 -04:00
|
|
|
|
|
|
|
if merge_request_for_resolving_discussions.try(:discussions_can_be_resolved_by?, current_user)
|
|
|
|
resolve_discussions_in_merge_request(issuable)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve_discussions_in_merge_request(issue)
|
|
|
|
Discussions::ResolveService.new(project, current_user,
|
|
|
|
merge_request: merge_request_for_resolving_discussions,
|
|
|
|
follow_up_issue: issue).
|
|
|
|
execute(merge_request_for_resolving_discussions.resolvable_discussions)
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
2016-07-21 19:11:53 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-08-05 18:10:08 -04:00
|
|
|
def spam_service
|
2017-01-27 11:25:39 -05:00
|
|
|
@spam_service ||= SpamService.new(@issue, @request)
|
2016-07-21 19:11:53 -04:00
|
|
|
end
|
2016-07-27 20:03:06 -04:00
|
|
|
|
2016-07-30 00:18:32 -04:00
|
|
|
def user_agent_detail_service
|
|
|
|
UserAgentDetailService.new(@issue, @request)
|
2016-07-21 19:11:53 -04:00
|
|
|
end
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
|
|
|
end
|