Skip to content
Snippets Groups Projects
Commit cca2f43d authored by drew stachon's avatar drew stachon :wave:
Browse files

Merge branch '425166_add_feature_flag_to_min_access_check' into 'master'

Add a feature flag around the code with poor performance

See merge request !132025



Merged-by: default avatardrew stachon <730684-drew@users.noreply.gitlab.com>
Approved-by: default avatarRoss Byrne <robyrne@gitlab.com>
Approved-by: default avatardrew stachon <730684-drew@users.noreply.gitlab.com>
Co-authored-by: Vasilii Iakliushin's avatarVasilii Iakliushin <viakliushin@gitlab.com>
parents 98ecef75 4fe04456
No related branches found
No related tags found
1 merge request!132025Add a feature flag around the code with poor performance
Pipeline #1011819811 failed
Pipeline: E2E Omnibus GitLab EE

#1011872506

    Pipeline: GitLab

    #1011822222

      Pipeline: E2E GDK

      #1011821196

        +21
        ---
        name: project_templates_without_min_access
        introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/132025
        rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/425452
        milestone: '16.5'
        type: development
        group: group::source code
        default_enabled: false
        ......@@ -167,14 +167,22 @@ def membership_locked?
        end
        def group_project_templates_count(group_id)
        projects_not_aimed_for_deletions_for(group_id).count do |project|
        can?(current_user, :download_code, project)
        if ::Feature.enabled?(:project_templates_without_min_access, current_user)
        projects_not_aimed_for_deletions_for(group_id).count do |project|
        can?(current_user, :download_code, project)
        end
        else
        projects_not_aimed_for_deletions_for(group_id).count
        end
        end
        def group_project_templates(group_id)
        projects_not_aimed_for_deletions_for(group_id).select do |project|
        can?(current_user, :download_code, project)
        def group_project_templates(group)
        if ::Feature.enabled?(:project_templates_without_min_access, current_user)
        projects_not_aimed_for_deletions_for(group.id).select do |project|
        can?(current_user, :download_code, project)
        end
        else
        group.projects.not_aimed_for_deletion
        end
        end
        ......
        ......@@ -301,7 +301,9 @@ def search_membership_ancestry
        def available_subgroups_with_custom_project_templates(group_id = nil)
        found_groups = GroupsWithTemplatesFinder.new(self, group_id).execute
        ::GroupsFinder.new(self)
        params = ::Feature.enabled?(:project_templates_without_min_access, self) ? {} : { min_access_level: ::Gitlab::Access::DEVELOPER }
        ::GroupsFinder.new(self, params)
        .execute
        .where(id: found_groups.select(:custom_project_templates_group_id))
        .preload(:projects)
        ......
        .custom-project-templates
        - if @groups_with_project_templates.present?
        - @groups_with_project_templates.each do |group|
        - projects = group_project_templates(group.id)
        - projects = group_project_templates(group)
        .template-group-options.js-template-group-options{ class: ('expanded border-top-0' if @groups_with_project_templates.first == group) }
        .template-header.d-flex.align-items-center
        .template-subgroup.d-flex.flex-fill.align-items-center
        ......
        ......@@ -172,6 +172,16 @@
        specify do
        expect(helper.group_project_templates_count(parent_group.id)).to eq 0
        end
        context 'when feature flag "project_templates_without_min_access" is disabled' do
        before do
        stub_feature_flags(project_templates_without_min_access: false)
        end
        specify do
        expect(helper.group_project_templates_count(parent_group.id)).to eq 1
        end
        end
        end
        context 'when there are multiple groups' do
        ......@@ -234,6 +244,16 @@
        specify do
        expect(helper.group_project_templates(parent_group)).to be_empty
        end
        context 'when feature flag "project_templates_without_min_access" is disabled' do
        before do
        stub_feature_flags(project_templates_without_min_access: false)
        end
        specify do
        expect(helper.group_project_templates(parent_group)).to be_empty
        end
        end
        end
        end
        ......
        ......@@ -849,25 +849,76 @@
        it 'only templates in publicly visible groups with projects are available' do
        expect(available_subgroups).to match_array([subgroup_1, subsubgroup_1, subsubgroup_4])
        end
        context 'when feature flag "project_templates_without_min_access" is disabled' do
        before do
        stub_feature_flags(project_templates_without_min_access: false)
        end
        it 'returns an empty collection' do
        expect(available_subgroups).to be_empty
        end
        end
        end
        context 'when a user is a member of the groups' do
        subject(:available_subgroups) { user.available_subgroups_with_custom_project_templates }
        where(:access_level) do
        [:guest, :reporter, :developer, :maintainer, :owner]
        context 'when the access level is not sufficient' do
        where(:access_level) do
        [:guest, :reporter]
        end
        with_them do
        before do
        group_1.add_member(user, access_level)
        group_2.add_member(user, access_level)
        group_3.add_member(user, access_level)
        group_4.add_member(user, access_level)
        end
        it 'the templates in groups with projects are available' do
        expect(available_subgroups).to match_array([subgroup_1, subgroup_2, subsubgroup_1, subsubgroup_4])
        end
        context 'when feature flag "project_templates_without_min_access" is disabled' do
        before do
        stub_feature_flags(project_templates_without_min_access: false)
        end
        it 'returns an empty collection' do
        expect(available_subgroups).to be_empty
        end
        end
        end
        end
        with_them do
        before do
        group_1.add_member(user, access_level)
        group_2.add_member(user, access_level)
        group_3.add_member(user, access_level)
        group_4.add_member(user, access_level)
        context 'when the access level is enough' do
        where(:access_level) do
        [:developer, :maintainer, :owner]
        end
        it 'the templates in groups with projects are available' do
        expect(available_subgroups).to match_array([subgroup_1, subgroup_2, subsubgroup_1, subsubgroup_4])
        with_them do
        before do
        group_1.add_member(user, access_level)
        group_2.add_member(user, access_level)
        group_3.add_member(user, access_level)
        group_4.add_member(user, access_level)
        end
        it 'the templates in groups with projects are available' do
        expect(available_subgroups).to match_array([subgroup_1, subgroup_2, subsubgroup_1, subsubgroup_4])
        end
        context 'when feature flag "project_templates_without_min_access" is disabled' do
        before do
        stub_feature_flags(project_templates_without_min_access: false)
        end
        it 'the templates in groups with projects are available' do
        expect(available_subgroups).to match_array([subgroup_1, subgroup_2, subsubgroup_1, subsubgroup_4])
        end
        end
        end
        end
        end
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment