2020-06-02 08:08:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-05-12 08:10:24 -04:00
|
|
|
module HasIntegrations
|
2020-06-02 08:08:33 -04:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
2020-06-04 08:08:21 -04:00
|
|
|
def with_custom_integration_for(integration, page = nil, per = nil)
|
2021-05-12 08:10:24 -04:00
|
|
|
custom_integration_project_ids = Integration
|
2021-04-14 11:09:04 -04:00
|
|
|
.select(:project_id)
|
2020-06-04 08:08:21 -04:00
|
|
|
.where(type: integration.type)
|
|
|
|
.where(inherit_from_id: nil)
|
2021-04-14 11:09:04 -04:00
|
|
|
.where.not(project_id: nil)
|
2020-06-04 08:08:21 -04:00
|
|
|
.page(page)
|
|
|
|
.per(per)
|
2020-06-02 08:08:33 -04:00
|
|
|
|
2020-06-04 08:08:21 -04:00
|
|
|
Project.where(id: custom_integration_project_ids)
|
2020-06-02 08:08:33 -04:00
|
|
|
end
|
2020-06-23 14:09:28 -04:00
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
def without_integration(integration)
|
2021-05-12 08:10:24 -04:00
|
|
|
integrations = Integration
|
2020-06-23 14:09:28 -04:00
|
|
|
.select('1')
|
|
|
|
.where('services.project_id = projects.id')
|
|
|
|
.where(type: integration.type)
|
|
|
|
|
|
|
|
Project
|
2021-05-12 08:10:24 -04:00
|
|
|
.where('NOT EXISTS (?)', integrations)
|
2020-06-23 14:09:28 -04:00
|
|
|
.where(pending_delete: false)
|
|
|
|
.where(archived: false)
|
|
|
|
end
|
2020-06-02 08:08:33 -04:00
|
|
|
end
|
|
|
|
end
|