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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
0d000d35
Commit
0d000d35
authored
Jan 16, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issuable stale object error handler for js when updating tasklists
parent
61e2a3eb
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
111 additions
and
19 deletions
+111
-19
app/assets/javascripts/task_list.js
app/assets/javascripts/task_list.js
+12
-0
app/controllers/concerns/issuable_actions.rb
app/controllers/concerns/issuable_actions.rb
+17
-0
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+1
-2
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+11
-12
changelogs/unreleased/issue_24815.yml
changelogs/unreleased/issue_24815.yml
+4
-0
spec/controllers/projects/issues_controller_spec.rb
spec/controllers/projects/issues_controller_spec.rb
+7
-5
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+2
-0
spec/support/update_invalid_issuable.rb
spec/support/update_invalid_issuable.rb
+57
-0
No files found.
app/assets/javascripts/task_list.js
View file @
0d000d35
/* global Flash */
require
(
'
vendor/task_list
'
);
class
TaskList
{
...
...
@@ -6,6 +7,16 @@ class TaskList {
this
.
dataType
=
options
.
dataType
;
this
.
fieldName
=
options
.
fieldName
;
this
.
onSuccess
=
options
.
onSuccess
||
(()
=>
{});
this
.
onError
=
function
showFlash
(
response
)
{
let
errorMessages
=
''
;
if
(
response
.
responseJSON
)
{
errorMessages
=
response
.
responseJSON
.
errors
.
join
(
'
'
);
}
return
new
Flash
(
errorMessages
||
'
Update failed
'
,
'
alert
'
);
};
this
.
init
();
}
...
...
@@ -32,6 +43,7 @@ class TaskList {
url
:
$target
.
data
(
'
update-url
'
)
||
$
(
'
form.js-issuable-update
'
).
attr
(
'
action
'
),
data
:
patchData
,
success
:
this
.
onSuccess
,
error
:
this
.
onError
,
});
}
}
...
...
app/controllers/concerns/issuable_actions.rb
View file @
0d000d35
...
...
@@ -26,6 +26,23 @@ module IssuableActions
private
def
render_conflict_response
respond_to
do
|
format
|
format
.
html
do
@conflict
=
true
render
:edit
end
format
.
json
do
render
json:
{
errors:
[
"Someone edited this
#{
issuable
.
human_class_name
}
at the same time you did. Please refresh your browser and make sure your changes will not unintentionally remove theirs."
]
},
status:
409
end
end
end
def
labels
@labels
||=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
end
...
...
app/controllers/projects/issues_controller.rb
View file @
0d000d35
...
...
@@ -134,8 +134,7 @@ class Projects::IssuesController < Projects::ApplicationController
end
rescue
ActiveRecord
::
StaleObjectError
@conflict
=
true
render
:edit
render_conflict_response
end
def
referenced_merge_requests
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
0d000d35
...
...
@@ -296,22 +296,21 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def
update
@merge_request
=
MergeRequests
::
UpdateService
.
new
(
project
,
current_user
,
merge_request_params
).
execute
(
@merge_request
)
if
@merge_request
.
valid?
respond_to
do
|
format
|
format
.
html
do
redirect_to
([
@merge_request
.
target_project
.
namespace
.
becomes
(
Namespace
),
@merge_request
.
target_project
,
@merge_request
])
if
@merge_request
.
valid?
redirect_to
([
@merge_request
.
target_project
.
namespace
.
becomes
(
Namespace
),
@merge_request
.
target_project
,
@merge_request
])
else
render
:edit
end
end
format
.
json
do
render
json:
@merge_request
.
to_json
(
include:
{
milestone:
{},
assignee:
{
methods: :avatar_url
},
labels:
{
methods: :text_color
}
},
methods:
[
:task_status
,
:task_status_short
])
end
end
else
render
"edit"
end
rescue
ActiveRecord
::
StaleObjectError
@conflict
=
true
render
:edit
render_conflict_response
end
def
remove_wip
...
...
changelogs/unreleased/issue_24815.yml
0 → 100644
View file @
0d000d35
---
title
:
Fix issuable stale object error handler for js when updating tasklists
merge_request
:
author
:
spec/controllers/projects/issues_controller_spec.rb
View file @
0d000d35
...
...
@@ -125,14 +125,16 @@ describe Projects::IssuesController do
end
describe
'PUT #update'
do
context
'when moving issue to another private project'
do
let
(
:another_project
)
{
create
(
:empty_project
,
:private
)
}
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:developer
]
end
it_behaves_like
'update invalid issuable'
,
Issue
context
'when moving issue to another private project'
do
let
(
:another_project
)
{
create
(
:empty_project
,
:private
)
}
context
'when user has access to move issue'
do
before
{
another_project
.
team
<<
[
user
,
:reporter
]
}
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
0d000d35
...
...
@@ -254,6 +254,8 @@ describe Projects::MergeRequestsController do
expect
{
merge_request
.
reload
.
target_branch
}.
not_to
change
{
merge_request
.
target_branch
}
end
it_behaves_like
'update invalid issuable'
,
MergeRequest
end
end
...
...
spec/support/update_invalid_issuable.rb
0 → 100644
View file @
0d000d35
shared_examples
'update invalid issuable'
do
|
klass
|
let
(
:params
)
do
{
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
issuable
.
iid
}
end
let
(
:issuable
)
do
klass
==
Issue
?
issue
:
merge_request
end
before
do
if
klass
==
Issue
params
.
merge!
(
issue:
{
title:
"any"
})
else
params
.
merge!
(
merge_request:
{
title:
"any"
})
end
end
context
'when updating causes conflicts'
do
before
do
allow_any_instance_of
(
issuable
.
class
).
to
receive
(
:save
).
and_raise
(
ActiveRecord
::
StaleObjectError
.
new
(
issuable
,
:save
))
end
it
'renders edit when format is html'
do
put
:update
,
params
expect
(
response
).
to
render_template
(
:edit
)
expect
(
assigns
[
:conflict
]).
to
be_truthy
end
it
'renders json error message when format is json'
do
params
.
merge!
(
format:
"json"
)
put
:update
,
params
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
JSON
.
parse
(
response
.
body
)).
to
have_key
(
'errors'
)
end
end
context
'when updating an invalid issuable'
do
before
do
key
=
klass
==
Issue
?
:issue
:
:merge_request
params
[
key
][
:title
]
=
""
end
it
'renders edit when merge request is invalid'
do
put
:update
,
params
expect
(
response
).
to
render_template
(
:edit
)
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