Commit 4371496c authored by Eulyeon Ko's avatar Eulyeon Ko

Remove group-level licensed features from boards

Public projects under free tier namespace are
only entitled to the project-level features of Ultimate.

Group-level Ultimate features need to be checked
at the namespace level and hidden appropriately.
parent 809f0965
......@@ -89,6 +89,10 @@ module BoardsHelper
@current_board_parent ||= @group || @project
end
def current_board_namespace
@current_board_namespace = board.group_board? ? @group : @project.namespace
end
def can_update?
can?(current_user, :admin_issue, board)
end
......
......@@ -25,22 +25,33 @@ module EE
label_ids: board.label_ids,
labels: board.labels.to_json(only: [:id, :title, :color, :text_color] ),
board_weight: board.weight,
multiple_assignees_feature_available: current_board_parent.feature_available?(:multiple_issue_assignees).to_s,
weight_feature_available: current_board_parent.feature_available?(:issue_weights).to_s,
milestone_lists_available: current_board_parent.feature_available?(:board_milestone_lists).to_s,
assignee_lists_available: current_board_parent.feature_available?(:board_assignee_lists).to_s,
iteration_lists_available: current_board_parent.feature_available?(:board_iteration_lists).to_s,
epic_feature_available: current_board_parent.feature_available?(:epics).to_s,
iteration_feature_available: current_board_parent.feature_available?(:iterations).to_s,
show_promotion: show_feature_promotion,
scoped_labels: current_board_parent.feature_available?(:scoped_labels)&.to_s,
can_update: can_update?.to_s,
can_admin_list: can_admin_list?.to_s,
disabled: disabled?.to_s,
emails_disabled: current_board_parent.emails_disabled?.to_s
}
super.merge(data)
super.merge(data).merge(licensed_features).merge(group_level_features)
end
def licensed_features
# These features are available at both project- and group-level
{
multiple_assignees_feature_available: current_board_parent.feature_available?(:multiple_issue_assignees).to_s,
weight_feature_available: current_board_parent.feature_available?(:issue_weights).to_s,
milestone_lists_available: current_board_parent.feature_available?(:board_milestone_lists).to_s,
assignee_lists_available: current_board_parent.feature_available?(:board_assignee_lists).to_s,
scoped_labels: current_board_parent.feature_available?(:scoped_labels)&.to_s
}
end
def group_level_features
{
iteration_lists_available: current_board_namespace.feature_available?(:board_iteration_lists).to_s,
epic_feature_available: current_board_namespace.feature_available?(:epics).to_s,
iteration_feature_available: current_board_namespace.feature_available?(:iterations).to_s
}
end
override :can_update?
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Boards licensed features', :js do
include BoardHelpers
let_it_be(:user) { create(:user) }
let(:card) { find('.board:nth-child(1)').find('[data-testid="board_card"]') }
before do
sign_in user
end
context "Project board sidebar" do
shared_examples "hides group-level licensed features in sidebar" do
before do
visit project_board_path(project, board)
wait_for_requests
click_card(card)
end
it "hides epic widget" do
expect(page).not_to have_selector('[data-testid="sidebar-epic"]')
end
it "hides iteration widget" do
expect(page).not_to have_selector('[data-testid="iteration-edit-link"]')
end
end
shared_context "project issue board" do
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:board) { create(:board, project: project) }
let_it_be(:list) { create(:backlog_list, board: board) }
end
context "GitLab SaaS" do
let_it_be(:plan_license) { :free }
let_it_be(:global_license) { create(:license) }
before do
enable_namespace_license_check!
allow(License).to receive(:current).and_return(global_license)
allow(global_license).to receive(:features).and_return([
:epics,
:iterations
])
end
context "Public project under Free plan under group namespace" do
let_it_be(:group) { create(:group, :public) }
let_it_be(:project) { create(:project, :public, group: group) }
let_it_be(:gitlab_subscription) { create(:gitlab_subscription, :free, namespace: group) }
include_context "project issue board"
before do
group.add_owner(user)
end
include_examples "hides group-level licensed features in sidebar"
end
context "Public project under Free plan under user namespace" do
let_it_be(:project) { create(:project, :public, namespace: user.namespace) }
let_it_be(:gitlab_subscription) { create(:gitlab_subscription, :free, namespace: user.namespace) }
include_context "project issue board"
include_examples "hides group-level licensed features in sidebar"
end
end
end
end
......@@ -3,9 +3,9 @@
require 'spec_helper'
RSpec.describe BoardsHelper do
let_it_be(:project) { create(:project) }
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let_it_be_with_refind(:project) { create(:project) }
let_it_be(:project_board) { create(:board, project: project) }
describe '#board_list_data' do
......@@ -105,15 +105,22 @@ RSpec.describe BoardsHelper do
end
end
[[:multiple_issue_assignees, :multiple_assignees_feature_available],
[:issue_weights, :weight_feature_available],
[:board_milestone_lists, :milestone_lists_available],
[:board_assignee_lists, :assignee_lists_available],
[:board_iteration_lists, :iteration_lists_available],
[:epics, :epic_feature_available],
[:iterations, :iteration_feature_available],
[:scoped_labels, :scoped_labels]].each do |feature_name, feature_key|
include_examples "serializes the availability of a licensed feature", feature_name, feature_key
context "group and project-level licensed features" do
[[:multiple_issue_assignees, :multiple_assignees_feature_available],
[:issue_weights, :weight_feature_available],
[:board_milestone_lists, :milestone_lists_available],
[:board_assignee_lists, :assignee_lists_available],
[:scoped_labels, :scoped_labels]].each do |feature_name, feature_key|
include_examples "serializes the availability of a licensed feature", feature_name, feature_key
end
end
context "group-level licensed features" do
[[:board_iteration_lists, :iteration_lists_available],
[:epics, :epic_feature_available],
[:iterations, :iteration_feature_available]].each do |feature_name, feature_key|
include_examples "serializes the availability of a licensed feature", feature_name, feature_key
end
end
end
......
......@@ -36,7 +36,7 @@ RSpec.describe BoardsHelper do
end
describe '#board_base_url' do
context 'when project board' do
context 'when group board' do
it 'generates the correct url' do
assign(:board, group_board)
assign(:group, base_group)
......@@ -55,6 +55,43 @@ RSpec.describe BoardsHelper do
end
end
describe '#current_board_namespace' do
context 'when group board' do
it 'returns the correct namespace' do
assign(:board, group_board)
assign(:group, base_group)
expect(helper.current_board_namespace).to be(base_group)
end
end
context 'project under group' do
context 'when project board' do
it 'returns the correct namespace' do
assign(:project, project)
assign(:board, project_board)
expect(helper.current_board_namespace).to be(project.parent)
end
end
end
context 'project under user namespace' do
let_it_be(:project_under_user) { create(:project, namespace: user.namespace) }
context 'when project board' do
let_it_be(:project_board) { create(:board, project: project_under_user) }
it 'returns the correct namespace' do
assign(:project, project_under_user)
assign(:board, project_board)
expect(helper.current_board_namespace).to be(user.namespace)
end
end
end
end
describe '#board_data' do
context 'project_board' do
before 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