This repository has been archived by the owner on Apr 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Add discard button on document creation #767
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -30,6 +30,11 @@ <h2 class="document-title">{% trans "Edit page" %}</h2> | |||||||||
<button type="submit" class="btn btn-primary"> | ||||||||||
{% trans 'Save' %} | ||||||||||
</button> | ||||||||||
{% if document|num_revisions == 0 and not form.autosave_id %} | ||||||||||
<button type="button" class="btn btn-danger" id="discardDocumentButton" disabled="true"> | ||||||||||
{% trans 'Discard' %} | ||||||||||
</button> | ||||||||||
{% endif %} | ||||||||||
{% if document|num_revisions > 0 %} | ||||||||||
<button type="button" class="btn btn-danger" id="deleteDocumentButton"> | ||||||||||
{% trans 'Delete' %} | ||||||||||
|
@@ -259,6 +264,7 @@ <h4 class="modal-title" id="deleteAutosaveHeader">{% trans "Do you really want t | |||||||||
const destinationElement = $('#shareText'); | ||||||||||
destinationElement.attr('href', url); | ||||||||||
destinationElement.removeClass('hidden'); | ||||||||||
$("#discardDocumentButton").attr("disabled", false); | ||||||||||
}, | ||||||||||
error: function(jqXHR, textStatus, errorThrown) { | ||||||||||
const reasonDisplay = $('.autosaveErrorDialogExplanation'); | ||||||||||
|
@@ -307,6 +313,19 @@ <h4 class="modal-title" id="deleteAutosaveHeader">{% trans "Do you really want t | |||||||||
$('#image-upload-area').removeClass('hidden'); | ||||||||||
}); | ||||||||||
|
||||||||||
{% if document|num_revisions == 0 and not form.autosave_id %} | ||||||||||
$("#discardDocumentButton").attr("disabled", true); | ||||||||||
$('#discardDocumentButton').on('click', function (event) { | ||||||||||
$.post( | ||||||||||
"{% url "documents:delete_document" document.url_title %}", | ||||||||||
{}, | ||||||||||
function (data, textStatus, jqXHR) { | ||||||||||
window.location.replace("/"); | ||||||||||
} | ||||||||||
); | ||||||||||
}); | ||||||||||
{% endif %} | ||||||||||
|
||||||||||
{% if document|num_revisions > 0 %} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
function createCascadeList(cascade, domObject) { | ||||||||||
for(let i = 0; i < cascade.length; i++) { | ||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -468,7 +468,24 @@ def change_attachment(request): | |
|
||
def delete_document(request, title): | ||
document = get_object_or_404(Document, url_title=title) | ||
check_permissions(document, request.user, [document.edit_permission_name]) | ||
|
||
if document.is_in_creation: | ||
try: | ||
# check super user permissions | ||
check_permissions(document, request.user, [document.edit_permission_name]) | ||
except PermissionDenied: | ||
# check if an autosave has already been created | ||
autosaves_for_document = TemporaryDocumentText.objects.filter(document=document) | ||
if autosaves_for_document.exists(): | ||
# with an unsaved document, only one user can have autosaves | ||
if autosaves_for_document.first().author != request.user: | ||
raise PermissionDenied | ||
else: | ||
# no permission check possible if no autosave was saved (current behavior is not ideal) | ||
raise PermissionDenied | ||
else: | ||
check_permissions(document, request.user, [document.edit_permission_name]) | ||
|
||
document.delete() | ||
|
||
messages.success(request, _("Successfully deleted document: {}").format(document.title)) | ||
|
@@ -521,12 +538,16 @@ def delete_autosave(request, title): | |
|
||
# first check that the user actually may change this document | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the comments ("first ..." and "second ...") need to be updated |
||
document = get_object_or_404(Document, url_title=title) | ||
check_permissions(document, request.user, [document.edit_permission_name]) | ||
|
||
# second check that the supplied autosave id matches to the document and has been created by the user | ||
autosave_id = request.POST['autosave_id'] | ||
autosave = get_object_or_404(TemporaryDocumentText, id=autosave_id) | ||
autosaves_for_object_and_user = TemporaryDocumentText.objects.filter(document=document, author=request.user) | ||
|
||
# a new document does not have permissions, just check if the autosave author is correct | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment does not explain why a permission check is done nevertheless if the author does not match |
||
if autosave.author != request.user: | ||
check_permissions(document, request.user, [document.edit_permission_name]) | ||
|
||
if autosave not in autosaves_for_object_and_user: | ||
raise SuspiciousOperation | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.