Commit b545d3a9 authored by Justin Ho's avatar Justin Ho

Refactor backend code after review

- Update condition of `activated` to show the actual
state of an active integration.
- Memoize queries in backend code.
- Add comment in HAML view to avoid possible security
issues.
parent e840a7ce
......@@ -104,7 +104,7 @@ module IntegrationsHelper
form_data = {
id: integration.id,
show_active: integration.show_active_box?.to_s,
activated: ((integration.active || integration.new_record?) && integration.activate_disabled_reason.nil?).to_s,
activated: (integration.active || (integration.new_record? && integration.activate_disabled_reason.nil?)).to_s,
activate_disabled: integration.activate_disabled_reason.present?.to_s,
type: integration.to_param,
merge_request_events: integration.merge_requests_events.to_s,
......
......@@ -141,7 +141,7 @@ module Integrations
def other_external_issue_trackers
return [] unless project_level?
project.integrations.external_issue_trackers.where.not(id: id)
@other_external_issue_trackers ||= project.integrations.external_issue_trackers.where.not(id: id)
end
def enabled_in_gitlab_config
......
......@@ -80,7 +80,7 @@ module Integrations
def external_issue_trackers
return [] unless project_level?
project.integrations.external_issue_trackers
@external_issue_trackers ||= project.integrations.external_issue_trackers
end
def allowed_branch?(ref)
......
......@@ -2,6 +2,9 @@
= render "projects/services/#{integration.to_param}/top", integration: integration
- if integration.activate_disabled_reason.present? && integration.activate_disabled_reason[:trackers].any?
-# When using integration.activate_disabled_reason[:trackers], it's potentially insecure to use the raw records
-# when passed directly to the frontend. Only use specific fields that are needed for render.
-# For example, we can get the link to each tracker with scoped_edit_integration_path(tracker, tracker.project)
= render 'shared/global_alert',
title: s_('ExternalIssueIntegration|Another issue tracker is already in use'),
variant: :warning,
......
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