mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Add post_edit_time_limit site setting to limit the how long a post can be edited and deleted by the author. Default is 1 year.
This commit is contained in:
@@ -459,7 +459,17 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
post.destroy(user);
|
||||
post.destroy(user).then(null, function(e) {
|
||||
console.log('Error case?');
|
||||
console.log(e);
|
||||
post.undoDeleteState();
|
||||
var response = $.parseJSON(e.responseText);
|
||||
if (response && response.errors) {
|
||||
bootbox.alert(response.errors[0]);
|
||||
} else {
|
||||
bootbox.alert(I18n.t('generic_error'));
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ Discourse.Post = Discourse.Model.extend({
|
||||
// We're updating a post
|
||||
return Discourse.ajax("/posts/" + (this.get('id')), {
|
||||
type: 'PUT',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
post: { raw: this.get('raw'), edit_reason: this.get('editReason') },
|
||||
image_sizes: this.get('imageSizes')
|
||||
@@ -236,6 +237,8 @@ Discourse.Post = Discourse.Model.extend({
|
||||
@param {Discourse.User} deletedBy The user deleting the post
|
||||
**/
|
||||
setDeletedState: function(deletedBy) {
|
||||
this.set('oldCooked', this.get('cooked'));
|
||||
|
||||
// Moderators can delete posts. Regular users can only trigger a deleted at message.
|
||||
if (deletedBy.get('staff')) {
|
||||
this.setProperties({
|
||||
@@ -255,6 +258,26 @@ Discourse.Post = Discourse.Model.extend({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
Changes the state of the post to NOT be deleted. Does not call the server.
|
||||
This can only be called after setDeletedState was called, but the delete
|
||||
failed on the server.
|
||||
|
||||
@method undoDeletedState
|
||||
**/
|
||||
undoDeleteState: function() {
|
||||
if (this.get('oldCooked')) {
|
||||
this.setProperties({
|
||||
deleted_at: null,
|
||||
deleted_by: null,
|
||||
cooked: this.get('oldCooked'),
|
||||
version: this.get('version') - 1,
|
||||
can_recover: false,
|
||||
user_deleted: false
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
Deletes a post
|
||||
|
||||
|
||||
Reference in New Issue
Block a user