Commit fc178334 authored by Etienne Baqué's avatar Etienne Baqué

Added ExportedProtectedBranch model

Model to manage protected branch import export.
Added specs accordingly.
parent 3e64c76b
# frozen_string_literal: true
class ExportedProtectedBranch < ProtectedBranch
has_many :push_access_levels, -> { where(deploy_key_id: nil) }, class_name: "ProtectedBranch::PushAccessLevel", foreign_key: :protected_branch_id
end
...@@ -222,6 +222,7 @@ class Project < ApplicationRecord ...@@ -222,6 +222,7 @@ class Project < ApplicationRecord
has_many :snippets, class_name: 'ProjectSnippet' has_many :snippets, class_name: 'ProjectSnippet'
has_many :hooks, class_name: 'ProjectHook' has_many :hooks, class_name: 'ProjectHook'
has_many :protected_branches has_many :protected_branches
has_many :exported_protected_branches
has_many :protected_tags has_many :protected_tags
has_many :repository_languages, -> { order "share DESC" } has_many :repository_languages, -> { order "share DESC" }
has_many :designs, inverse_of: :project, class_name: 'DesignManagement::Design' has_many :designs, inverse_of: :project, class_name: 'DesignManagement::Design'
......
...@@ -15,6 +15,10 @@ module Projects ...@@ -15,6 +15,10 @@ module Projects
self.respond_to?(:override_description) ? override_description : super self.respond_to?(:override_description) ? override_description : super
end end
def protected_branches
project.exported_protected_branches
end
private private
def converted_group_members def converted_group_members
......
...@@ -51,6 +51,9 @@ Note the following: ...@@ -51,6 +51,9 @@ Note the following:
then new branches associated with such merge requests will be created then new branches associated with such merge requests will be created
within a project during the import/export. Thus, the number of branches within a project during the import/export. Thus, the number of branches
in the exported project could be bigger than in the original project. in the exported project could be bigger than in the original project.
- Deploy keys allowed to push to protected branches are not exported. Therefore,
you will need to recreate this association by first enabling these deploy keys in your
imported project and then updating your protected branches accordingly.
## Version history ## Version history
......
...@@ -169,6 +169,7 @@ excluded_attributes: ...@@ -169,6 +169,7 @@ excluded_attributes:
- :compliance_framework_setting - :compliance_framework_setting
- :show_default_award_emojis - :show_default_award_emojis
- :services - :services
- :exported_protected_branches
namespaces: namespaces:
- :runners_token - :runners_token
- :runners_token_encrypted - :runners_token_encrypted
......
# frozen_string_literal: true
FactoryBot.define do
factory :exported_protected_branch, class: 'ExportedProtectedBranch', parent: :protected_branch
end
...@@ -552,6 +552,7 @@ project: ...@@ -552,6 +552,7 @@ project:
- pipeline_artifacts - pipeline_artifacts
- terraform_states - terraform_states
- alert_management_http_integrations - alert_management_http_integrations
- exported_protected_branches
award_emoji: award_emoji:
- awardable - awardable
- user - user
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ExportedProtectedBranch do
describe 'Associations' do
it { is_expected.to have_many(:push_access_levels) }
end
describe '.push_access_levels' do
it 'returns the correct push access levels' do
exported_branch = create(:exported_protected_branch, :developers_can_push)
deploy_key = create(:deploy_key)
create(:deploy_keys_project, :write_access, project: exported_branch.project, deploy_key: deploy_key )
create(:protected_branch_push_access_level, protected_branch: exported_branch, deploy_key: deploy_key)
dev_push_access_level = exported_branch.push_access_levels.first
expect(exported_branch.push_access_levels).to contain_exactly(dev_push_access_level)
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