Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions modules/backlogs/lib/open_project/backlogs/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,10 @@ def self.settings
end

config.to_prepare do
enabled_backlogs_story = ->(_type, project: nil) do
project.nil? || project.backlogs_enabled?
%i[position story_points sprint].each do |attribute|
::Type.add_constraint attribute, ->(_type, project: nil) { project.nil? || project.backlogs_enabled? }
end

story_and_sprint_permission = ->(_type, project: nil) do
project.nil? || User.current.allowed_in_project?(:view_sprints, project)
end

::Type.add_constraint :position, enabled_backlogs_story
::Type.add_constraint :story_points, enabled_backlogs_story
::Type.add_constraint :sprint, story_and_sprint_permission

::Type.add_default_mapping(:estimates_and_progress, :story_points)
::Type.add_default_mapping(:other, :position)
::Type.add_default_mapping(:details, :sprint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@
API::V3::WorkPackages::Schema::SpecificWorkPackageSchema.new(work_package:)
end
let(:representer) { described_class.create(schema, form_embedded: true, self_link: nil, current_user:) }
let(:project) { work_package.project }
let(:work_package) { build_stubbed(:work_package, type: build_stubbed(:type)) }
let(:backlogs_enabled) { true }
let(:project) do
work_package.project.tap do |p|
allow(p).to receive(:backlogs_enabled?).and_return(backlogs_enabled)
end
end
let(:work_package_type) { build_stubbed(:type, attribute_groups: [["Agile", %w[position sprint story_points]]]) }
let(:work_package) { build_stubbed(:work_package, type: work_package_type) }

let(:current_user) { build_stubbed(:user) }
let(:permissions) { %i(view_work_packages edit_work_packages view_sprints manage_sprint_items) }
Expand All @@ -50,9 +56,6 @@
end

login_as(current_user)

allow(schema.project).to receive(:backlogs_enabled?).and_return(true)
allow(work_package).to receive(:leaf?).and_return(true)
end

subject { representer.to_json }
Expand All @@ -67,9 +70,7 @@
end

context "when backlogs module is disabled" do
before do
allow(schema.project).to receive(:backlogs_enabled?).and_return(false)
end
let(:backlogs_enabled) { false }

it "does not show story points" do
expect(subject).not_to have_json_path("storyPoints")
Expand All @@ -87,9 +88,7 @@
end

context "when backlogs module is disabled" do
before do
allow(schema.project).to receive(:backlogs_enabled?).and_return(false)
end
let(:backlogs_enabled) { false }

it "does not show position" do
expect(subject).not_to have_json_path("position")
Expand Down Expand Up @@ -135,4 +134,31 @@
end
end
end

describe "attribute_groups" do
context "with backlogs enabled" do
it "has backlogs properties listed in the right group" do
expect(subject).to be_json_eql(%w[position sprint storyPoints])
.at_path("_attributeGroups/0/attributes")
end
end

context "with backlogs enabled and permissions missing" do
let(:permissions) { %i(view_work_packages edit_work_packages) }

it "has backlogs properties listed in the right group" do
expect(subject).to be_json_eql(%w[position sprint storyPoints])
.at_path("_attributeGroups/0/attributes")
end
end

context "with backlogs disabled" do
let(:backlogs_enabled) { false }

it "lacks the backlogs properties" do
expect(subject).to be_json_eql(%w[])
.at_path("_attributeGroups/0/attributes")
end
end
end
end
Loading