Commit 87cda478 authored by Nick Thomas's avatar Nick Thomas

Merge branch '30769-update-protected-branch-export' into 'master'

Add ExportedProtectedBranch model for Import/Export

See merge request gitlab-org/gitlab!47181
parents 9d425085 d3f5267b
# 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
...@@ -33,6 +33,7 @@ RSpec.describe Project, factory_default: :keep do ...@@ -33,6 +33,7 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_many(:deploy_keys) } it { is_expected.to have_many(:deploy_keys) }
it { is_expected.to have_many(:hooks) } it { is_expected.to have_many(:hooks) }
it { is_expected.to have_many(:protected_branches) } it { is_expected.to have_many(:protected_branches) }
it { is_expected.to have_many(:exported_protected_branches) }
it { is_expected.to have_one(:slack_service) } it { is_expected.to have_one(:slack_service) }
it { is_expected.to have_one(:microsoft_teams_service) } it { is_expected.to have_one(:microsoft_teams_service) }
it { is_expected.to have_one(:mattermost_service) } it { is_expected.to have_one(:mattermost_service) }
......
...@@ -45,6 +45,14 @@ RSpec.describe Projects::ImportExport::ProjectExportPresenter do ...@@ -45,6 +45,14 @@ RSpec.describe Projects::ImportExport::ProjectExportPresenter do
end end
end end
describe '#protected_branches' do
it 'returns the project exported protected branches' do
expect(project).to receive(:exported_protected_branches)
subject.protected_branches
end
end
describe '#project_members' do describe '#project_members' do
let(:user2) { create(:user, email: 'group@member.com') } let(:user2) { create(:user, email: 'group@member.com') }
let(:member_emails) do let(:member_emails) do
......
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