Commit 4245cb12 authored by James Lopez's avatar James Lopez

Merge branch 'open-project-integration-3' into 'master'

Prepare OpenProjectService

See merge request gitlab-org/gitlab!28012
parents d052b592 5becd865
# frozen_string_literal: true
module Services
module DataFields
extend ActiveSupport::Concern
included do
belongs_to :service
delegate :activated?, to: :service, allow_nil: true
validates :service, presence: true
end
class_methods do
def encryption_options
{
key: Settings.attr_encrypted_db_key_base_32,
encode: true,
mode: :per_attribute_iv,
algorithm: 'aes-256-gcm'
}
end
end
end
end
...@@ -44,6 +44,7 @@ module DataFields ...@@ -44,6 +44,7 @@ module DataFields
included do included do
has_one :issue_tracker_data, autosave: true has_one :issue_tracker_data, autosave: true
has_one :jira_tracker_data, autosave: true has_one :jira_tracker_data, autosave: true
has_one :open_project_tracker_data, autosave: true
def data_fields def data_fields
raise NotImplementedError raise NotImplementedError
......
# frozen_string_literal: true # frozen_string_literal: true
class IssueTrackerData < ApplicationRecord class IssueTrackerData < ApplicationRecord
belongs_to :service include Services::DataFields
delegate :activated?, to: :service, allow_nil: true
validates :service, presence: true
def self.encryption_options
{
key: Settings.attr_encrypted_db_key_base_32,
encode: true,
mode: :per_attribute_iv,
algorithm: 'aes-256-gcm'
}
end
attr_encrypted :project_url, encryption_options attr_encrypted :project_url, encryption_options
attr_encrypted :issues_url, encryption_options attr_encrypted :issues_url, encryption_options
......
# frozen_string_literal: true # frozen_string_literal: true
class JiraTrackerData < ApplicationRecord class JiraTrackerData < ApplicationRecord
belongs_to :service include Services::DataFields
delegate :activated?, to: :service, allow_nil: true
validates :service, presence: true
def self.encryption_options
{
key: Settings.attr_encrypted_db_key_base_32,
encode: true,
mode: :per_attribute_iv,
algorithm: 'aes-256-gcm'
}
end
attr_encrypted :url, encryption_options attr_encrypted :url, encryption_options
attr_encrypted :api_url, encryption_options attr_encrypted :api_url, encryption_options
......
# frozen_string_literal: true
class OpenProjectService < IssueTrackerService
validates :url, public_url: true, presence: true, if: :activated?
validates :api_url, public_url: true, allow_blank: true, if: :activated?
validates :token, presence: true, if: :activated?
validates :project_identifier_code, presence: true, if: :activated?
data_field :url, :api_url, :token, :closed_status_id, :project_identifier_code
def data_fields
open_project_tracker_data || self.build_open_project_tracker_data
end
def self.to_param
'open_project'
end
end
# frozen_string_literal: true
class OpenProjectTrackerData < ApplicationRecord
include Services::DataFields
# When the Open Project is fresh installed, the default closed status id is "13" based on current version: v8.
DEFAULT_CLOSED_STATUS_ID = "13"
attr_encrypted :url, encryption_options
attr_encrypted :api_url, encryption_options
attr_encrypted :token, encryption_options
def closed_status_id
super || DEFAULT_CLOSED_STATUS_ID
end
end
...@@ -126,6 +126,26 @@ FactoryBot.define do ...@@ -126,6 +126,26 @@ FactoryBot.define do
end end
end end
factory :open_project_service do
project
active { true }
transient do
url { 'http://openproject.example.com' }
api_url { 'http://openproject.example.com/issues/:id' }
token { 'supersecret' }
closed_status_id { '15' }
project_identifier_code { 'PRJ-1' }
end
after(:build) do |service, evaluator|
create(:open_project_tracker_data, service: service,
url: evaluator.url, api_url: evaluator.api_url, token: evaluator.token,
closed_status_id: evaluator.closed_status_id, project_identifier_code: evaluator.project_identifier_code
)
end
end
trait :jira_cloud_service do trait :jira_cloud_service do
url { 'https://mysite.atlassian.net' } url { 'https://mysite.atlassian.net' }
username { 'jira_user' } username { 'jira_user' }
......
...@@ -9,4 +9,12 @@ FactoryBot.define do ...@@ -9,4 +9,12 @@ FactoryBot.define do
factory :issue_tracker_data do factory :issue_tracker_data do
service service
end end
factory :open_project_tracker_data do
service
url { 'http://openproject.example.com'}
token { 'supersecret' }
project_identifier_code { 'PRJ-1' }
closed_status_id { '15' }
end
end end
...@@ -252,6 +252,7 @@ services: ...@@ -252,6 +252,7 @@ services:
- service_hook - service_hook
- jira_tracker_data - jira_tracker_data
- issue_tracker_data - issue_tracker_data
- open_project_tracker_data
hooks: hooks:
- project - project
- web_hook_logs - web_hook_logs
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
describe JiraTrackerData do describe JiraTrackerData do
let(:service) { create(:jira_service, active: false, properties: {}) } let(:service) { create(:jira_service, active: false) }
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:service) } it { is_expected.to belong_to(:service) }
......
# frozen_string_literal: true
require 'spec_helper'
describe OpenProjectService do
describe 'Validations' do
context 'when service is active' do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:url) }
it { is_expected.to validate_presence_of(:token) }
it { is_expected.to validate_presence_of(:project_identifier_code) }
it_behaves_like 'issue tracker service URL attribute', :url
it_behaves_like 'issue tracker service URL attribute', :api_url
end
context 'when service is inactive' do
before do
subject.active = false
end
it { is_expected.not_to validate_presence_of(:url) }
it { is_expected.not_to validate_presence_of(:token) }
it { is_expected.not_to validate_presence_of(:project_identifier_code) }
end
end
describe 'Associations' do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
end
# frozen_string_literal: true
require 'spec_helper'
describe OpenProjectTrackerData do
describe 'Associations' do
it { is_expected.to belong_to(:service) }
end
describe 'closed_status_id' do
it 'returns the set value' do
expect(build(:open_project_tracker_data).closed_status_id).to eq('15')
end
it 'returns the default value if not set' do
expect(build(:open_project_tracker_data, closed_status_id: nil).closed_status_id).to eq('13')
end
end
end
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