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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
7342a456
Commit
7342a456
authored
Mar 14, 2016
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dry destroy action on issuables
parent
67043ec5
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
56 additions
and
43 deletions
+56
-43
app/controllers/concerns/issuable_action.rb
app/controllers/concerns/issuable_action.rb
+21
-0
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+2
-12
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+5
-1
app/models/ability.rb
app/models/ability.rb
+3
-1
app/models/concerns/internal_id.rb
app/models/concerns/internal_id.rb
+4
-5
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+2
-0
app/models/issue.rb
app/models/issue.rb
+0
-2
app/models/merge_request.rb
app/models/merge_request.rb
+0
-2
app/models/user.rb
app/models/user.rb
+0
-4
app/views/projects/merge_requests/show/_mr_title.html.haml
app/views/projects/merge_requests/show/_mr_title.html.haml
+1
-1
app/views/shared/issuable/_form.html.haml
app/views/shared/issuable/_form.html.haml
+9
-7
doc/api/issues.md
doc/api/issues.md
+1
-1
doc/api/merge_requests.md
doc/api/merge_requests.md
+1
-1
lib/api/issues.rb
lib/api/issues.rb
+3
-2
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+4
-4
No files found.
app/controllers/concerns/issuable_action.rb
0 → 100644
View file @
7342a456
module
IssuableAction
extend
ActiveSupport
::
Concern
def
destroy
issuable
=
@merge_request
||
@issue
unless
current_user
.
can?
(
:"remove_
#{
issuable
.
to_ability_name
}
"
,
issuable
)
return
access_denied!
end
issuable
.
destroy
route
=
polymorphic_path
([
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
issuable
.
class
])
issuable_name
=
issuable
.
class
.
name
.
underscore
.
gsub
(
'_'
,
' '
)
respond_to
do
|
format
|
format
.
html
{
redirect_to
route
,
notice:
"This
#{
issuable_name
}
was deleted."
}
format
.
json
{
head
:ok
}
end
end
end
app/controllers/projects/issues_controller.rb
View file @
7342a456
class
Projects::IssuesController
<
Projects
::
ApplicationController
class
Projects::IssuesController
<
Projects
::
ApplicationController
include
ToggleSubscriptionAction
include
ToggleSubscriptionAction
include
IssuableAction
before_action
:module_enabled
before_action
:module_enabled
before_action
:issue
,
only:
[
:edit
,
:update
,
:show
]
before_action
:issue
,
only:
[
:edit
,
:update
,
:show
,
:destroy
]
# Allow read any issue
# Allow read any issue
before_action
:authorize_read_issue!
,
only:
[
:show
]
before_action
:authorize_read_issue!
,
only:
[
:show
]
...
@@ -108,17 +109,6 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -108,17 +109,6 @@ class Projects::IssuesController < Projects::ApplicationController
end
end
end
end
def
destroy
return
access_denied!
unless
current_user
.
admin?
issue
.
destroy
respond_to
do
|
format
|
format
.
html
{
redirect_to
namespace_project_issues_path
(
@project
.
namespace
,
@project
),
notice:
"The issues was deleted."
}
format
.
json
{
head
:ok
}
end
end
def
bulk_update
def
bulk_update
result
=
Issues
::
BulkUpdateService
.
new
(
project
,
current_user
,
bulk_update_params
).
execute
result
=
Issues
::
BulkUpdateService
.
new
(
project
,
current_user
,
bulk_update_params
).
execute
redirect_back_or_default
(
default:
{
action:
'index'
},
options:
{
notice:
"
#{
result
[
:count
]
}
issues updated"
})
redirect_back_or_default
(
default:
{
action:
'index'
},
options:
{
notice:
"
#{
result
[
:count
]
}
issues updated"
})
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
7342a456
class
Projects::MergeRequestsController
<
Projects
::
ApplicationController
class
Projects::MergeRequestsController
<
Projects
::
ApplicationController
include
ToggleSubscriptionAction
include
ToggleSubscriptionAction
include
DiffHelper
include
DiffHelper
include
IssuableAction
before_action
:module_enabled
before_action
:module_enabled
before_action
:merge_request
,
only:
[
before_action
:merge_request
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:commits
,
:builds
,
:merge
,
:merge_check
,
:edit
,
:update
,
:show
,
:d
estroy
,
:d
iffs
,
:commits
,
:builds
,
:merge
,
:merge_check
,
:ci_status
,
:toggle_subscription
,
:cancel_merge_when_build_succeeds
,
:remove_wip
:ci_status
,
:toggle_subscription
,
:cancel_merge_when_build_succeeds
,
:remove_wip
]
]
before_action
:closes_issues
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:commits
,
:builds
]
before_action
:closes_issues
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:commits
,
:builds
]
...
@@ -164,6 +165,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -164,6 +165,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
end
end
end
<<<<<<<
67043
ec53b4c35d5a9862fe78bd3f47e412919cd
def
remove_wip
def
remove_wip
MergeRequests
::
UpdateService
.
new
(
project
,
current_user
,
title:
@merge_request
.
wipless_title
).
execute
(
@merge_request
)
MergeRequests
::
UpdateService
.
new
(
project
,
current_user
,
title:
@merge_request
.
wipless_title
).
execute
(
@merge_request
)
...
@@ -171,6 +173,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -171,6 +173,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
notice:
"The merge request can now be merged."
notice:
"The merge request can now be merged."
end
end
=======
>>>>>>>
Dry
destroy
action
on
issuables
def
merge_check
def
merge_check
@merge_request
.
check_if_can_be_merged
@merge_request
.
check_if_can_be_merged
...
...
app/models/ability.rb
View file @
7342a456
...
@@ -235,7 +235,9 @@ class Ability
...
@@ -235,7 +235,9 @@ class Ability
:rename_project
,
:rename_project
,
:remove_project
,
:remove_project
,
:archive_project
,
:archive_project
,
:remove_fork_project
:remove_fork_project
,
:remove_merge_request
,
:remove_issue
]
]
end
end
...
...
app/models/concerns/internal_id.rb
View file @
7342a456
...
@@ -7,11 +7,10 @@ module InternalId
...
@@ -7,11 +7,10 @@ module InternalId
end
end
def
set_iid
def
set_iid
max_iid
=
if
self
.
paranoid?
records
=
project
.
send
(
self
.
class
.
name
.
tableize
)
project
.
send
(
self
.
class
.
name
.
tableize
).
with_deleted
.
maximum
(
:iid
)
records
=
records
.
with_deleted
if
self
.
paranoid?
else
max_iid
=
records
.
maximum
(
:iid
)
project
.
send
(
self
.
class
.
name
.
tableize
).
maximum
(
:iid
)
end
self
.
iid
=
max_iid
.
to_i
+
1
self
.
iid
=
max_iid
.
to_i
+
1
end
end
...
...
app/models/concerns/issuable.rb
View file @
7342a456
...
@@ -58,6 +58,8 @@ module Issuable
...
@@ -58,6 +58,8 @@ module Issuable
attr_mentionable
:description
,
cache:
true
attr_mentionable
:description
,
cache:
true
participant
:author
,
:assignee
,
:notes_with_associations
participant
:author
,
:assignee
,
:notes_with_associations
strip_attributes
:title
strip_attributes
:title
acts_as_paranoid
end
end
module
ClassMethods
module
ClassMethods
...
...
app/models/issue.rb
View file @
7342a456
...
@@ -54,8 +54,6 @@ class Issue < ActiveRecord::Base
...
@@ -54,8 +54,6 @@ class Issue < ActiveRecord::Base
state
:closed
state
:closed
end
end
acts_as_paranoid
def
hook_attrs
def
hook_attrs
attributes
attributes
end
end
...
...
app/models/merge_request.rb
View file @
7342a456
...
@@ -142,8 +142,6 @@ class MergeRequest < ActiveRecord::Base
...
@@ -142,8 +142,6 @@ class MergeRequest < ActiveRecord::Base
scope
:join_project
,
->
{
joins
(
:target_project
)
}
scope
:join_project
,
->
{
joins
(
:target_project
)
}
scope
:references_project
,
->
{
references
(
:target_project
)
}
scope
:references_project
,
->
{
references
(
:target_project
)
}
acts_as_paranoid
def
self
.
reference_prefix
def
self
.
reference_prefix
'!'
'!'
end
end
...
...
app/models/user.rb
View file @
7342a456
...
@@ -440,10 +440,6 @@ class User < ActiveRecord::Base
...
@@ -440,10 +440,6 @@ class User < ActiveRecord::Base
Project
.
where
(
"projects.id IN (
#{
projects_union
.
to_sql
}
)"
)
Project
.
where
(
"projects.id IN (
#{
projects_union
.
to_sql
}
)"
)
end
end
def
owner?
(
project
)
owned_projects
.
include?
(
project
)
end
def
owned_projects
def
owned_projects
@owned_projects
||=
@owned_projects
||=
Project
.
where
(
'namespace_id IN (?) OR namespace_id = ?'
,
Project
.
where
(
'namespace_id IN (?) OR namespace_id = ?'
,
...
...
app/views/projects/merge_requests/show/_mr_title.html.haml
View file @
7342a456
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
-
if
@merge_request
.
open?
-
if
@merge_request
.
open?
=
link_to
'Close'
,
merge_request_path
(
@merge_request
,
merge_request:
{
state_event: :close
}),
method: :put
,
class:
'btn btn-nr btn-grouped btn-close'
,
title:
'Close merge request'
=
link_to
'Close'
,
merge_request_path
(
@merge_request
,
merge_request:
{
state_event: :close
}),
method: :put
,
class:
'btn btn-nr btn-grouped btn-close'
,
title:
'Close merge request'
=
link_to
edit_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
),
class:
'btn btn-nr btn-grouped issuable-edit'
,
id:
'edit_merge_request'
do
=
link_to
edit_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
),
class:
'btn btn-nr btn-grouped issuable-edit'
,
id:
'edit_merge_request'
do
=
icon
(
'pencil-square-o'
)
#%i.fa.fa-pencil-square-o
=
icon
(
'pencil-square-o'
)
Edit
Edit
-
if
@merge_request
.
closed?
-
if
@merge_request
.
closed?
=
link_to
'Reopen'
,
merge_request_path
(
@merge_request
,
merge_request:
{
state_event: :reopen
}),
method: :put
,
class:
'btn btn-nr btn-grouped btn-reopen reopen-mr-link'
,
title:
'Reopen merge request'
=
link_to
'Reopen'
,
merge_request_path
(
@merge_request
,
merge_request:
{
state_event: :reopen
}),
method: :put
,
class:
'btn btn-nr btn-grouped btn-reopen reopen-mr-link'
,
title:
'Reopen merge request'
app/views/shared/issuable/_form.html.haml
View file @
7342a456
...
@@ -106,10 +106,6 @@
...
@@ -106,10 +106,6 @@
=
f
.
submit
"Submit
#{
issuable
.
class
.
model_name
.
human
.
downcase
}
"
,
class:
'btn btn-create'
=
f
.
submit
"Submit
#{
issuable
.
class
.
model_name
.
human
.
downcase
}
"
,
class:
'btn btn-create'
-
else
-
else
=
f
.
submit
'Save changes'
,
class:
'btn btn-save'
=
f
.
submit
'Save changes'
,
class:
'btn btn-save'
-
if
current_user
.
admin?
||
current_user
.
owner?
(
@project
)
=
link_to
namespace_project_issue_path
(
@project
.
namespace
,
@project
,
issuable
),
method: :delete
,
class:
'btn'
do
=
icon
(
'trash-o'
)
Delete
-
if
!
issuable
.
persisted?
&&
!
issuable
.
project
.
empty_repo?
&&
(
guide_url
=
contribution_guide_path
(
issuable
.
project
))
-
if
!
issuable
.
persisted?
&&
!
issuable
.
project
.
empty_repo?
&&
(
guide_url
=
contribution_guide_path
(
issuable
.
project
))
.inline.prepend-left-10
.inline.prepend-left-10
...
@@ -118,7 +114,13 @@
...
@@ -118,7 +114,13 @@
for this project.
for this project.
-
if
issuable
.
new_record?
-
if
issuable
.
new_record?
-
cancel_project
=
issuable
.
source_project
=
link_to
namespace_project_issues_path
(
@project
.
namespace
,
@project
),
class:
'btn btn-cancel'
do
Cancel
-
else
-
else
-
cancel_project
=
issuable
.
project
-
if
current_user
.
can?
(
:"remove_
#{
issuable
.
to_ability_name
}
"
,
@project
)
=
link_to
'Cancel'
,
[
cancel_project
.
namespace
.
becomes
(
Namespace
),
cancel_project
,
issuable
],
class:
'btn btn-cancel'
.pull-right
=
link_to
polymorphic_path
([
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
issuable
]),
method: :delete
,
class:
'btn'
do
=
icon
(
'trash-o'
)
Delete
=
link_to
namespace_project_issue_path
(
@project
.
namespace
,
@project
,
issuable
),
class:
'btn btn-cancel'
do
Cancel
doc/api/issues.md
View file @
7342a456
...
@@ -328,7 +328,7 @@ Example response:
...
@@ -328,7 +328,7 @@ Example response:
## Delete existing issue
## Delete existing issue
Only for admins. Soft deletes the issue in question. Returns the issue which was deleted.
Only for admins
and project owners
. Soft deletes the issue in question. Returns the issue which was deleted.
```
```
DELETE /projects/:id/issues/:issue_id
DELETE /projects/:id/issues/:issue_id
...
...
doc/api/merge_requests.md
View file @
7342a456
...
@@ -382,7 +382,7 @@ If an error occurs, an error number and a message explaining the reason is retur
...
@@ -382,7 +382,7 @@ If an error occurs, an error number and a message explaining the reason is retur
## Delete a MR
## Delete a MR
Soft deletes a merge request. For admins only.
Soft deletes a merge request. For admins
and owners
only.
```
```
DELETE /projects/:id/merge_requests/:merge_request_id
DELETE /projects/:id/merge_requests/:merge_request_id
...
...
lib/api/issues.rb
View file @
7342a456
...
@@ -199,7 +199,8 @@ module API
...
@@ -199,7 +199,8 @@ module API
# Example Request:
# Example Request:
# DELETE /projects/:id/issues/:issue_id
# DELETE /projects/:id/issues/:issue_id
delete
":id/issues/:issue_id"
do
delete
":id/issues/:issue_id"
do
authenticated_as_admin!
issue
=
user_project
.
issues
.
find
(
params
[
:issue_id
])
!
JLJsdf
sdfijsf
current_user
.
can?
(
:remove_issue
,
issue
)
issue
=
user_project
.
issues
.
find
(
params
[
:issue_id
])
issue
=
user_project
.
issues
.
find
(
params
[
:issue_id
])
issue
.
destroy
issue
.
destroy
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
7342a456
...
@@ -123,7 +123,7 @@ describe Projects::MergeRequestsController do
...
@@ -123,7 +123,7 @@ describe Projects::MergeRequestsController do
end
end
end
end
describe
'
GET
#index'
do
describe
'#index'
do
def
get_merge_requests
def
get_merge_requests
get
:index
,
get
:index
,
namespace_id:
project
.
namespace
.
to_param
,
namespace_id:
project
.
namespace
.
to_param
,
...
@@ -157,8 +157,8 @@ describe Projects::MergeRequestsController do
...
@@ -157,8 +157,8 @@ describe Projects::MergeRequestsController do
end
end
end
end
describe
"
DELETE
#destroy"
do
describe
"#destroy"
do
it
"lets mere mortals not acces this endpoint"
do
it
"lets mere mortals not acces
s
this endpoint"
do
delete
:destroy
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
merge_request
.
iid
delete
:destroy
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
merge_request
.
iid
expect
(
response
.
status
).
to
eq
404
expect
(
response
.
status
).
to
eq
404
...
@@ -170,7 +170,7 @@ describe Projects::MergeRequestsController do
...
@@ -170,7 +170,7 @@ describe Projects::MergeRequestsController do
user
.
save
user
.
save
end
end
it
"lets an admin delete an issue"
do
it
"lets an admin
or owner
delete an issue"
do
delete
:destroy
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
merge_request
.
iid
delete
:destroy
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
merge_request
.
iid
expect
(
response
.
status
).
to
be
302
expect
(
response
.
status
).
to
be
302
...
...
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