Commit ecea68ee authored by Patrick Derichs's avatar Patrick Derichs

Add #parent method to milestone

parent 1e638da0
......@@ -170,6 +170,14 @@ class Milestone < ApplicationRecord
alias_method :group_milestone?, :group_timebox?
alias_method :project_milestone?, :project_timebox?
def parent
if group_milestone?
group
else
project
end
end
private
def milestone_format_reference(format = :iid)
......
......@@ -41,15 +41,7 @@ class BurnupChartService
attr_reader :milestone, :start_date, :due_date, :end_date, :user
def can_read_milestone?
Ability.allowed?(user, :read_milestone, milestone_parent)
end
def milestone_parent
if milestone.group_milestone?
milestone.group
else
milestone.project
end
Ability.allowed?(user, :read_milestone, milestone.parent)
end
def handle_added_milestone(event, assigned_milestones)
......
......@@ -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-org/gitlab-ce/milestones/123") }
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
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