diff --git a/doc/api/protected_branches.md b/doc/api/protected_branches.md index a703c0657c5ddffaec83cfbb6dab3a29cc5df34f..5f6e03fde4d21931aefcab3e27cb204bb9b4b083 100644 --- a/doc/api/protected_branches.md +++ b/doc/api/protected_branches.md @@ -83,7 +83,8 @@ Example response: ``` Users on GitLab Premium or higher also see -the `user_id` and `group_id` parameters: +the `user_id`, `group_id` and `inherited` parameters. If the `inherited` parameter +exists, means the setting was inherited from the project's group. Example response: @@ -111,7 +112,8 @@ Example response: } ], "allow_force_push":false, - "code_owner_approval_required": false + "code_owner_approval_required": false, + "inherited": true }, ... ] diff --git a/ee/app/models/concerns/ee/protected_branch.rb b/ee/app/models/concerns/ee/protected_branch.rb index 2b083b1c326b558f057f426f7e96f6794ce608cb..4e3f559c9d2b98ebb04edf712be7978c869d5c1a 100644 --- a/ee/app/models/concerns/ee/protected_branch.rb +++ b/ee/app/models/concerns/ee/protected_branch.rb @@ -44,5 +44,10 @@ def supports_unprotection_restrictions? project.licensed_feature_available?(:unprotection_restrictions) end + + def inherited? + !namespace_id.nil? + end + alias_method :inherited, :inherited? end end diff --git a/ee/lib/ee/api/entities/protected_branch.rb b/ee/lib/ee/api/entities/protected_branch.rb index e3b5753da926538f1addd33627f5f41fa465e437..5b7a13a599b8dca54533ec8bf70cf45bec9fc14e 100644 --- a/ee/lib/ee/api/entities/protected_branch.rb +++ b/ee/lib/ee/api/entities/protected_branch.rb @@ -9,6 +9,7 @@ module ProtectedBranch prepended do expose :unprotect_access_levels, using: ::API::Entities::ProtectedRefAccess, documentation: { is_array: true } expose :code_owner_approval_required, documentation: { type: 'boolean' } + expose :inherited, documentation: { type: 'boolean' } end end end diff --git a/ee/spec/models/ee/protected_branch_spec.rb b/ee/spec/models/ee/protected_branch_spec.rb index a4512c5c6aa81c4b8e8eb2e0d921a8d1b98a412f..17841d3d6a79c149248682d67f3d73791b3f79af 100644 --- a/ee/spec/models/ee/protected_branch_spec.rb +++ b/ee/spec/models/ee/protected_branch_spec.rb @@ -258,4 +258,22 @@ end end end + + describe '#inherited?' do + context 'when the `namespace_id` is nil' do + before do + subject.assign_attributes(namespace_id: nil) + end + + it { is_expected.not_to be_inherited } + end + + context 'when the `namespace_id` is present' do + before do + subject.assign_attributes(namespace_id: 123) + end + + it { is_expected.to be_inherited } + end + end end diff --git a/ee/spec/requests/api/protected_branches_spec.rb b/ee/spec/requests/api/protected_branches_spec.rb index 5a1ff2d2d69196fb27f964370b0b123e29f421a3..95746de36a3ed3a6725315a1844d8f6cab9c46d1 100644 --- a/ee/spec/requests/api/protected_branches_spec.rb +++ b/ee/spec/requests/api/protected_branches_spec.rb @@ -21,6 +21,7 @@ expect(response).to have_gitlab_http_status(:ok) expect(json_response['unprotect_access_levels']).to eq([]) + expect(json_response).to include('inherited') end context 'with per user/group access levels' do