Class: IssuableLinks::CreateService
- Inherits:
-
BaseService
- Object
- BaseService
- IssuableLinks::CreateService
- Defined in:
- app/services/issuable_links/create_service.rb
Direct Known Subclasses
IssueLinks::CreateService, WorkItems::ParentLinks::BaseService, WorkItems::RelatedWorkItemLinks::CreateService
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#issuable ⇒ Object
readonly
Returns the value of attribute issuable.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Attributes inherited from BaseService
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(issuable, user, params) ⇒ CreateService
constructor
A new instance of CreateService.
-
#relate_issuables(referenced_issuable) ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
Methods included from BaseServiceUtility
#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level
Methods included from Gitlab::Allowable
Constructor Details
#initialize(issuable, user, params) ⇒ CreateService
Returns a new instance of CreateService.
7 8 9 10 11 12 |
# File 'app/services/issuable_links/create_service.rb', line 7 def initialize(issuable, user, params) @issuable = issuable @current_user = user @params = params.dup @errors = [] end |
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
5 6 7 |
# File 'app/services/issuable_links/create_service.rb', line 5 def current_user @current_user end |
#issuable ⇒ Object (readonly)
Returns the value of attribute issuable.
5 6 7 |
# File 'app/services/issuable_links/create_service.rb', line 5 def issuable @issuable end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'app/services/issuable_links/create_service.rb', line 5 def params @params end |
Instance Method Details
#execute ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/issuable_links/create_service.rb', line 14 def execute # If ALL referenced issues are already assigned to the given epic it renders a conflict status, # otherwise create issue links for the issues which # are still not assigned and return success message. if render_conflict_error? return error(, 409) end if return error(, 403) end if render_not_found_error? return error(, 404) end references = create_links if @errors.present? return error(@errors.join('. '), 422) end track_event success(created_references: references) end |
#relate_issuables(referenced_issuable) ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/services/issuable_links/create_service.rb', line 42 def relate_issuables(referenced_issuable) link = link_class.find_or_initialize_by(source: issuable, target: referenced_issuable) set_link_type(link) if link.changed? && link.save create_notes(link) end link end |