Added soft comment deletion. Updates issue 43.

This commit is contained in:
Tobi Schäfer 2010-04-02 13:50:15 +00:00
parent 64f2966b56
commit 2835f03425
2 changed files with 52 additions and 12 deletions

View file

@ -29,8 +29,8 @@
/** /**
* @see defineConstants * @see defineConstants
*/ */
Comment.getStatus = defineConstants(Comment, "closed", Comment.getStatus = defineConstants(Comment, "deleted", "pending",
"pending", "readonly", "public"); "readonly", "public");
/** /**
* @returns {String} * @returns {String}
@ -87,16 +87,20 @@ Comment.prototype.getPermission = function(action) {
case ".": case ".":
case "main": case "main":
case "comment": case "comment":
// FIXME: temporary fix for lost stories due to shrunk database
if (!this.story) {
return false;
}
return this.site.commentMode === Site.ENABLED && return this.site.commentMode === Site.ENABLED &&
this.story.getPermission(action) && this.story.getPermission(action) &&
this.status !== Comment.CLOSED &&
this.status !== Comment.PENDING; this.status !== Comment.PENDING;
case "delete": case "delete":
return this.story.getPermission.call(this, "delete");
case "edit": case "edit":
case "rotate":
if (this.status === Comment.DELETED) {
if (this.creator !== this.modifier) {
return User.require(User.PRIVILEGED);
} else {
return session.user === this.creator;
}
}
return this.story.getPermission.call(this, "delete"); return this.story.getPermission.call(this, "delete");
} }
return false; return false;
@ -159,7 +163,7 @@ Comment.prototype.update = function(data) {
this.setMetadata(data); this.setMetadata(data);
if (this.story.commentMode === Story.MODERATED) { if (this.story.commentMode === Story.MODERATED) {
this.mode = Comment.PENDING; this.status = Comment.PENDING;
} else if (delta > 50) { } else if (delta > 50) {
this.modified = new Date; this.modified = new Date;
if (this.story.status !== Story.CLOSED) { if (this.story.status !== Story.CLOSED) {
@ -175,6 +179,14 @@ Comment.prototype.update = function(data) {
return; return;
} }
/**
* @returns {String}
*/
Comment.prototype.getConfirmText = function() {
return gettext("You are about to delete a comment by user {0}.",
this.creator.name);
}
/** /**
* *
* @param {String} name * @param {String} name
@ -189,9 +201,36 @@ Comment.prototype.getMacroHandler = function(name) {
} }
/** /**
* @returns {String} *
*/ */
Comment.prototype.getConfirmText = function() { Comment.prototype.text_macro = function() {
return gettext("You are about to delete a comment by user {0}.", if (this.status === Comment.DELETED) {
this.creator.name); res.write("<em>");
res.write(this.modifier === this.creator ?
gettext("This comment was removed by the author.") :
gettext("This comment was removed."));
res.writeln("</em>");
} else {
res.write(this.text);
}
return;
}
Comment.prototype.link_macro = function(param, action, text) {
switch (action) {
case "rotate":
if (this.status === Comment.DELETED) {
text = gettext("Show");
} else {
text = gettext("Hide");
}
}
return HopObject.prototype.link_macro.call(this, param, action, text);
}
Comment.prototype.rotate_action = function() {
this.status = this.status === Comment.DELETED ?
Comment.PUBLIC : Comment.DELETED;
this.touch();
return res.redirect(this.href());
} }

View file

@ -5,6 +5,7 @@
<% comment.link . <% gettext Link %> prefix="... " %> <% comment.link . <% gettext Link %> prefix="... " %>
<% comment.link edit prefix="... " %> <% comment.link edit prefix="... " %>
<% comment.link delete prefix="... " %> <% comment.link delete prefix="... " %>
<% comment.link rotate prefix="... " %>
</p> </p>
<% comment.comments %> <% comment.comments %>
<div class="reply small"> <div class="reply small">