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:
Neil Lalonde
2014-01-07 10:32:09 -05:00
parent e750ea010f
commit 259295d865
10 changed files with 118 additions and 5 deletions

View File

@@ -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'));
}
});
}
},

View File

@@ -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