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
1d36dec9
Commit
1d36dec9
authored
Feb 12, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
3328ce94
da1aaaf2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
55 deletions
+38
-55
app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
+29
-5
app/models/concerns/with_uploads.rb
app/models/concerns/with_uploads.rb
+4
-30
changelogs/unreleased/fast-destroy-uploads.yml
changelogs/unreleased/fast-destroy-uploads.yml
+5
-0
spec/support/shared_examples/models/with_uploads_shared_examples.rb
...rt/shared_examples/models/with_uploads_shared_examples.rb
+0
-20
No files found.
app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
View file @
1d36dec9
...
...
@@ -36,13 +36,20 @@ export class CopyAsGFM {
div
.
appendChild
(
el
.
cloneNode
(
true
));
const
html
=
div
.
innerHTML
;
clipboardData
.
setData
(
'
text/plain
'
,
el
.
textContent
);
clipboardData
.
setData
(
'
text/html
'
,
html
);
// We are also setting this as fallback to transform the selection to gfm on paste
clipboardData
.
setData
(
'
text/x-gfm-html
'
,
html
);
CopyAsGFM
.
nodeToGFM
(
el
)
.
then
(
res
=>
{
clipboardData
.
setData
(
'
text/plain
'
,
el
.
textContent
);
clipboardData
.
setData
(
'
text/x-gfm
'
,
res
);
clipboardData
.
setData
(
'
text/html
'
,
html
);
})
.
catch
(()
=>
{});
.
catch
(()
=>
{
// Not showing the error as Firefox might doesn't allow
// it or other browsers who have a time limit on the execution
// of the copy event
});
}
static
pasteGFM
(
e
)
{
...
...
@@ -51,11 +58,28 @@ export class CopyAsGFM {
const
text
=
clipboardData
.
getData
(
'
text/plain
'
);
const
gfm
=
clipboardData
.
getData
(
'
text/x-gfm
'
);
if
(
!
gfm
)
return
;
const
gfmHtml
=
clipboardData
.
getData
(
'
text/x-gfm-html
'
);
if
(
!
gfm
&&
!
gfmHtml
)
return
;
e
.
preventDefault
();
window
.
gl
.
utils
.
insertText
(
e
.
target
,
textBefore
=>
{
// We have the original selection already converted to gfm
if
(
gfm
)
{
CopyAsGFM
.
insertPastedText
(
e
.
target
,
text
,
gfm
);
}
else
{
// Due to the async copy call we are not able to produce gfm so we transform the cached HTML
const
div
=
document
.
createElement
(
'
div
'
);
div
.
innerHTML
=
gfmHtml
;
CopyAsGFM
.
nodeToGFM
(
div
)
.
then
(
transformedGfm
=>
{
CopyAsGFM
.
insertPastedText
(
e
.
target
,
text
,
transformedGfm
);
})
.
catch
(()
=>
{});
}
}
static
insertPastedText
(
target
,
text
,
gfm
)
{
window
.
gl
.
utils
.
insertText
(
target
,
textBefore
=>
{
// If the text before the cursor contains an odd number of backticks,
// we are either inside an inline code span that starts with 1 backtick
// or a code block that starts with 3 backticks.
...
...
app/models/concerns/with_uploads.rb
View file @
1d36dec9
...
...
@@ -27,40 +27,14 @@ module WithUploads
included
do
has_many
:uploads
,
as: :model
has_many
:file_uploads
,
->
{
where
(
uploader:
FILE_UPLOADERS
)
},
class_name:
'Upload'
,
as: :model
has_many
:file_uploads
,
->
{
where
(
uploader:
FILE_UPLOADERS
)
},
class_name:
'Upload'
,
as: :model
,
dependent: :delete_all
# rubocop:disable Cop/ActiveRecordDependent
# TODO: when feature flag is removed, we can use just dependent: destroy
# option on :file_uploads
before_destroy
:remove_file_uploads
use_fast_destroy
:file_uploads
,
if: :fast_destroy_enabled?
use_fast_destroy
:file_uploads
end
def
retrieve_upload
(
_identifier
,
paths
)
uploads
.
find_by
(
path:
paths
)
end
private
# mounted uploads are deleted in carrierwave's after_commit hook,
# but FileUploaders which are not mounted must be deleted explicitly and
# it can not be done in after_commit because FileUploader requires loads
# associated model on destroy (which is already deleted in after_commit)
def
remove_file_uploads
fast_destroy_enabled?
?
delete_uploads
:
destroy_uploads
end
def
delete_uploads
file_uploads
.
delete_all
(
:delete_all
)
end
def
destroy_uploads
file_uploads
.
find_each
do
|
upload
|
upload
.
destroy
end
end
def
fast_destroy_enabled?
Feature
.
enabled?
(
:fast_destroy_uploads
,
self
)
end
end
changelogs/unreleased/fast-destroy-uploads.yml
0 → 100644
View file @
1d36dec9
---
title
:
File uploads are deleted asynchronously when deleting a project or group.
merge_request
:
author
:
type
:
added
spec/support/shared_examples/models/with_uploads_shared_examples.rb
View file @
1d36dec9
...
...
@@ -44,26 +44,6 @@ shared_examples_for 'model with uploads' do |supports_fileuploads|
model_object
.
destroy
end
end
describe
'destroy strategy depending on feature flag'
do
let!
(
:upload
)
{
create
(
:upload
,
uploader:
FileUploader
,
model:
model_object
)
}
it
'does not destroy uploads by default'
do
expect
(
model_object
).
to
receive
(
:delete_uploads
)
expect
(
model_object
).
not_to
receive
(
:destroy_uploads
)
model_object
.
destroy
end
it
'uses before destroy callback if feature flag is disabled'
do
stub_feature_flags
(
fast_destroy_uploads:
false
)
expect
(
model_object
).
to
receive
(
:destroy_uploads
)
expect
(
model_object
).
not_to
receive
(
:delete_uploads
)
model_object
.
destroy
end
end
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