Commit ecea68ee authored by Patrick Derichs's avatar Patrick Derichs

Add #parent method to milestone

parent 1e638da0
...@@ -170,6 +170,14 @@ class Milestone < ApplicationRecord ...@@ -170,6 +170,14 @@ class Milestone < ApplicationRecord
alias_method :group_milestone?, :group_timebox? alias_method :group_milestone?, :group_timebox?
alias_method :project_milestone?, :project_timebox? alias_method :project_milestone?, :project_timebox?
def parent
if group_milestone?
group
else
project
end
end
private private
def milestone_format_reference(format = :iid) def milestone_format_reference(format = :iid)
......
...@@ -41,15 +41,7 @@ class BurnupChartService ...@@ -41,15 +41,7 @@ class BurnupChartService
attr_reader :milestone, :start_date, :due_date, :end_date, :user attr_reader :milestone, :start_date, :due_date, :end_date, :user
def can_read_milestone? def can_read_milestone?
Ability.allowed?(user, :read_milestone, milestone_parent) Ability.allowed?(user, :read_milestone, milestone.parent)
end
def milestone_parent
if milestone.group_milestone?
milestone.group
else
milestone.project
end
end end
def handle_added_milestone(event, assigned_milestones) def handle_added_milestone(event, assigned_milestones)
......
...@@ -480,4 +480,22 @@ describe Milestone do ...@@ -480,4 +480,22 @@ describe Milestone do
it { is_expected.not_to match("#{Gitlab.config.gitlab.url}/gitlab-org/gitlab-foss/issues/123") } it { is_expected.not_to match("#{Gitlab.config.gitlab.url}/gitlab-org/gitlab-foss/issues/123") }
it { is_expected.not_to match("gitlab-org/gitlab-ce/milestones/123") } it { is_expected.not_to match("gitlab-org/gitlab-ce/milestones/123") }
end end
describe '#parent' do
context 'with group' do
it 'returns the expected parent' do
group = create(:group)
expect(build(:milestone, group: group).parent).to eq(group)
end
end
context 'with project' do
it 'returns the expected parent' do
project = create(:project)
expect(build(:milestone, project: project).parent).to eq(project)
end
end
end
end end
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