Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1ba9a91c
Commit
1ba9a91c
authored
Mar 31, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix problem when creating milestones in groups without projects
parent
59466a47
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
5 deletions
+29
-5
app/controllers/groups/milestones_controller.rb
app/controllers/groups/milestones_controller.rb
+23
-5
spec/controllers/groups/milestones_controller_spec.rb
spec/controllers/groups/milestones_controller_spec.rb
+6
-0
No files found.
app/controllers/groups/milestones_controller.rb
View file @
1ba9a91c
...
...
@@ -18,14 +18,14 @@ class Groups::MilestonesController < Groups::ApplicationController
end
def
create
project_ids
=
params
[
:milestone
][
:project_ids
]
project_ids
=
params
[
:milestone
][
:project_ids
]
.
reject
(
&
:blank?
)
title
=
milestone_params
[
:title
]
@projects
.
where
(
id:
project_ids
).
each
do
|
project
|
Milestones
::
CreateService
.
new
(
project
,
current_user
,
milestone_params
).
execute
if
project_ids
.
present?
create_milestones
(
project_ids
,
title
)
else
render_new_with_error
(
"Select a project(s)."
)
end
redirect_to
milestone_path
(
title
)
end
def
show
...
...
@@ -41,6 +41,24 @@ class Groups::MilestonesController < Groups::ApplicationController
private
def
create_milestones
(
project_ids
,
title
)
begin
@projects
.
where
(
id:
project_ids
).
each
do
|
project
|
ActiveRecord
::
Base
.
transaction
{
Milestones
::
CreateService
.
new
(
project
,
current_user
,
milestone_params
).
execute
}
end
redirect_to
milestone_path
(
title
)
rescue
=>
e
render_new_with_error
(
"Error creating milestones:
#{
e
.
message
}
"
)
end
end
def
render_new_with_error
(
error
)
@milestone
=
Milestone
.
new
(
milestone_params
)
flash
[
:alert
]
=
error
render
:new
end
def
authorize_admin_milestones!
return
render_404
unless
can?
(
current_user
,
:admin_milestones
,
group
)
end
...
...
spec/controllers/groups/milestones_controller_spec.rb
View file @
1ba9a91c
...
...
@@ -23,5 +23,11 @@ describe Groups::MilestonesController do
expect
(
response
).
to
redirect_to
(
group_milestone_path
(
group
,
title
.
to_slug
.
to_s
,
title:
title
))
expect
(
Milestone
.
where
(
title:
title
).
count
).
to
eq
(
2
)
end
it
"redirects to new when there are no project ids"
do
post
:create
,
group_id:
group
.
id
,
milestone:
{
title:
title
,
project_ids:
[
""
]
}
expect
(
response
).
to
render_template
:new
expect
(
flash
[
:alert
]).
to_not
be_nil
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment