Topicstarter moderation implemented

main
Inga 🏳‍🌈 14 years ago
parent a9e0690fb3
commit 20409ac0ec
  1. 2
      Builder/IISMainHandler/build.txt
  2. 36
      Common/dataobjects/Board.cs
  3. 13
      Common/dataobjects/Category.cs
  4. 9
      Common/dataobjects/Moderator.cs
  5. 13
      Common/dataobjects/Post.cs
  6. 2
      Common/dataobjects/Punishment.cs
  7. 4
      Common/dataobjects/PunishmentTransfer.cs
  8. 2
      IISMainHandler/handlers/BoardsHandler.cs
  9. 2
      IISMainHandler/handlers/request/PunishHandler.cs
  10. 9
      IISMainHandler/handlers/response/PunishHandler.cs
  11. 7
      templates/Full/PostPunish.xslt

@ -30,6 +30,8 @@ namespace FLocal.Common.dataobjects {
public const string FIELD_DESCRIPTION = "Comment";
public const string FIELD_PARENTBOARDID = "ParentBoardId";
public const string FIELD_LEGACYNAME = "LegacyName";
public const string FIELD_ISTRANSFERTARGET = "IsTransferTarget";
public const string FIELD_ISTOPICSTARTERMODERATION = "IsTopicstarterModeration";
public static readonly TableSpec instance = new TableSpec();
public string name { get { return TABLE; } }
public string idName { get { return FIELD_ID; } }
@ -140,6 +142,22 @@ namespace FLocal.Common.dataobjects {
return this._legacyName;
}
}
private bool _isTransferTarget;
public bool isTransferTarget {
get {
this.LoadIfNotLoaded();
return this._isTransferTarget;
}
}
private bool _isTopicstarterModeration;
public bool isTopicstarterModeration {
get {
this.LoadIfNotLoaded();
return this._isTopicstarterModeration;
}
}
protected override void doFromHash(Dictionary<string, string> data) {
this._sortOrder = int.Parse(data[TableSpec.FIELD_SORTORDER]);
@ -151,6 +169,8 @@ namespace FLocal.Common.dataobjects {
this._description = data[TableSpec.FIELD_DESCRIPTION];
this._parentBoardId = Util.ParseInt(data[TableSpec.FIELD_PARENTBOARDID]);
this._legacyName = data[TableSpec.FIELD_LEGACYNAME].ToLower();
this._isTransferTarget = Util.string2bool(data[TableSpec.FIELD_ISTRANSFERTARGET]);
this._isTopicstarterModeration = Util.string2bool(data[TableSpec.FIELD_ISTOPICSTARTERMODERATION]);
}
private readonly object subBoards_Locker = new object();
@ -208,12 +228,18 @@ namespace FLocal.Common.dataobjects {
);
}
public XElement exportToXmlSimple(UserContext context) {
return new XElement("board",
public XElement exportToXmlSimple(UserContext context, Board.SubboardsOptions subboardsOptions) {
XElement result = new XElement("board",
new XElement("id", this.id),
new XElement("name", this.name),
new XElement("description", this.description)
new XElement("description", this.description),
new XElement("isTopicstarterModeration", this.isTopicstarterModeration.ToPlainString()),
new XElement("isTransferTarget", this.isTransferTarget.ToPlainString())
);
if((subboardsOptions & SubboardsOptions.FirstLevel) == SubboardsOptions.FirstLevel) {
result.Add(new XElement("subBoards", from board in this.subBoards select board.exportToXmlSimple(context, (subboardsOptions == SubboardsOptions.AllLevels) ? SubboardsOptions.AllLevels : SubboardsOptions.None)));
}
return result;
}
public XElement exportToXml(UserContext context, Board.SubboardsOptions subboardsOptions, params XElement[] additional) {
@ -226,7 +252,9 @@ namespace FLocal.Common.dataobjects {
new XElement("name", this.name),
new XElement("description", this.description),
new XElement("lastPostInfo", this.exportLastPostInfo(context)),
new XElement("moderators", from moderator in Moderator.GetModerators(this) select moderator.user.exportToXmlForViewing(context))
new XElement("moderators", from moderator in Moderator.GetModerators(this) select moderator.user.exportToXmlForViewing(context)),
new XElement("isTopicstarterModeration", this.isTopicstarterModeration.ToPlainString()),
new XElement("isTransferTarget", this.isTransferTarget.ToPlainString())
);
if(context.account != null) {

@ -110,12 +110,21 @@ namespace FLocal.Common.dataobjects {
);
}
public XElement exportToXmlForMainPage(UserContext context, Board.SubboardsOptions subboardsOptions) {
public XElement exportToXmlForMainPage(UserContext context) {
return new XElement("category",
new XElement("id", this.id),
new XElement("name", this.name),
new XElement("sortOrder", this.sortOrder),
new XElement("boards", from board in this.subBoards select board.exportToXml(context, subboardsOptions))
new XElement("boards", from board in this.subBoards select board.exportToXml(context, Board.SubboardsOptions.FirstLevel))
);
}
public XElement exportToXmlForTree(UserContext context) {
return new XElement("category",
new XElement("id", this.id),
new XElement("name", this.name),
new XElement("sortOrder", this.sortOrder),
new XElement("boards", from board in this.subBoards select board.exportToXmlSimple(context, Board.SubboardsOptions.AllLevels))
);
}

@ -74,7 +74,7 @@ namespace FLocal.Common.dataobjects {
}
private static readonly Dictionary<int, Dictionary<int, bool>> isModerator_cache = new Dictionary<int,Dictionary<int,bool>>();
public static bool isModerator(Account account, Board board) {
public static bool isTrueModerator(Account account, Board board) {
//slight optimisation...
UserGroup group = account.user.userGroup;
if(group.name != UserGroup.NAME_ADMINISTRATORS && group.name != UserGroup.NAME_MODERATORS) return false;
@ -112,14 +112,17 @@ namespace FLocal.Common.dataobjects {
}
return isModerator_cache[account.id][board.id];
}
public static bool isModerator(User user, Board board) {
public static bool isModerator(Account account, Thread thread) {
return (thread.board.isTopicstarterModeration && thread.topicstarterId == account.userId) || isTrueModerator(account, thread.board);
}
public static bool isModerator(User user, Thread thread) {
Account account;
try {
account = Account.LoadByUser(user);
} catch(NotFoundInDBException) {
return false;
}
return isModerator(account, board);
return isModerator(account, thread);
}
private static readonly Dictionary<int, IEnumerable<int>> byBoard_cache = new Dictionary<int,IEnumerable<int>>();

@ -236,7 +236,7 @@ namespace FLocal.Common.dataobjects {
new XElement("poster",
this.poster.exportToXmlForViewing(
context,
new XElement("isModerator", Moderator.isModerator(this.poster, this.thread.board).ToPlainString())
new XElement("isModerator", Moderator.isModerator(this.poster, this.thread).ToPlainString())
)
),
new XElement("postDate", this.postDate.ToXml()),
@ -247,7 +247,7 @@ namespace FLocal.Common.dataobjects {
//this.XMLBody(context),
new XElement("bodyShort", this.bodyShort),
new XElement("threadId", this.threadId),
new XElement("isPunishmentEnabled", ((context.account != null) && Moderator.isModerator(context.account, this.thread.board)).ToPlainString()),
new XElement("isPunishmentEnabled", ((context.account != null) && Moderator.isModerator(context.account, this.thread)).ToPlainString()),
new XElement("isOwner", ((context.account != null) && (this.poster.id == context.account.user.id)).ToPlainString()),
new XElement(
"specific",
@ -359,7 +359,14 @@ namespace FLocal.Common.dataobjects {
private readonly object Punish_Locker = new object();
public void Punish(Account account, PunishmentType type, string comment, PunishmentTransfer.NewTransferInfo? transferInfo) {
if(!Moderator.isModerator(account, this.thread.board)) throw new FLocalException(account.id + " is not a moderator in board " + this.thread.board.id);
if(string.IsNullOrEmpty(comment)) throw new FLocalException("Comment is empty");
if(!Moderator.isModerator(account, this.thread)) throw new FLocalException(account.id + " is not a moderator in board " + this.thread.board.id);
if(!Moderator.isTrueModerator(account, this.thread.board)) {
if(type.weight != 0) throw new FLocalException("You cannot set punishments with weight != 0");
if(transferInfo.HasValue && !transferInfo.Value.newBoard.isTransferTarget) throw new FLocalException("You cannot transfer in '" + transferInfo.Value.newBoard.name + "'");
}
if(account.user.id == this.poster.id) throw new FLocalException("You cannot punish your own posts");

@ -158,7 +158,7 @@ namespace FLocal.Common.dataobjects {
return new XElement("punishment",
this.post.exportToXmlBase(context),
new XElement("owner", this.owner.exportToXmlForViewing(context)),
new XElement("originalBoard", this.originalBoard.exportToXmlSimple(context)),
new XElement("originalBoard", this.originalBoard.exportToXmlSimple(context, Board.SubboardsOptions.None)),
new XElement("moderator", this.moderator.user.exportToXmlForViewing(context)),
new XElement("punishmentDate", this.punishmentDate.ToXml()),
this.punishmentType.exportToXml(context),

@ -100,9 +100,9 @@ namespace FLocal.Common.dataobjects {
public XElement exportToXml(UserContext context) {
return new XElement("transfer",
new XElement("id", this.id),
new XElement("oldBoard", this.oldBoard.exportToXmlSimple(context)),
new XElement("oldBoard", this.oldBoard.exportToXmlSimple(context, Board.SubboardsOptions.None)),
this.oldParentPostId.HasValue ? new XElement("oldParentPost", this.oldParentPost.exportToXmlBase(context)) : null,
new XElement("newBoard", this.newBoard.exportToXmlSimple(context)),
new XElement("newBoard", this.newBoard.exportToXmlSimple(context, Board.SubboardsOptions.None)),
new XElement("isSubthreadTransfer", this.isSubthreadTransfer.ToPlainString())
);
}

@ -22,7 +22,7 @@ namespace FLocal.IISHandler.handlers {
override protected IEnumerable<XElement> getSpecificData(WebContext context) {
return new XElement[] {
new XElement("categories", from category in Category.allCategories select category.exportToXmlForMainPage(context, Board.SubboardsOptions.FirstLevel)),
new XElement("categories", from category in Category.allCategories select category.exportToXmlForMainPage(context)),
new XElement("totalRegistered", Config.instance.mainConnection.GetCountByConditions(User.TableSpec.instance, new EmptyCondition())),
new XElement("activity",
new XElement("threshold", Config.instance.ActivityThreshold.ToString()),

@ -21,7 +21,7 @@ namespace FLocal.IISHandler.handlers.request {
post.Punish(
context.session.account,
PunishmentType.LoadById(int.Parse(context.httprequest.Form["punishmentTypeId"])),
context.httprequest.Form["comment"],
context.httprequest.Form["comment"].Trim(),
(context.httprequest.Form["transfer"] == "transfer")
?
(PunishmentTransfer.NewTransferInfo?)new PunishmentTransfer.NewTransferInfo(Board.LoadById(int.Parse(context.httprequest.Form["transfer_boardId"])), context.httprequest.Form["transfer_subThread"] == "transfer_subThread")

@ -21,7 +21,7 @@ namespace FLocal.IISHandler.handlers.response {
override protected IEnumerable<XElement> getSpecificNewMessageData(WebContext context) {
Post post = Post.LoadById(int.Parse(context.requestParts[1]));
if(!Moderator.isModerator(context.account, post.thread.board)) throw new FLocalException(context.account.id + " is not a moderator in board " + post.thread.board.id);
if(!Moderator.isModerator(context.account, post.thread)) throw new FLocalException(context.account.id + " is not a moderator in board " + post.thread.board.id);
if(context.account.user.id == post.poster.id) throw new FLocalException("You cannot punish your own posts");
return new XElement[] {
@ -34,13 +34,14 @@ namespace FLocal.IISHandler.handlers.response {
),
new XElement("categories",
from category in Category.allCategories select
category.exportToXmlForMainPage(context, Board.SubboardsOptions.AllLevels)
category.exportToXmlForTree(context)
),
new XElement("punishmentTypes",
from punishmentType in PunishmentType.allTypes select punishmentType.exportToXml(context)
)
),
new XElement("isTrueModerator", Moderator.isTrueModerator(context.account, post.thread.board).ToPlainString())
};
}
}
}

@ -94,6 +94,9 @@
<input type="radio" name="punishmentTypeId">
<xsl:attribute name="id">punishmentTypeId_<xsl:value-of select="id"/></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="id"/></xsl:attribute>
<xsl:if test="not(/root/isTrueModerator = 'true') and not(weight = '0')">
<xsl:attribute name="disabled">disabled</xsl:attribute>
</xsl:if>
</input>
<label>
<xsl:attribute name="for">punishmentTypeId_<xsl:value-of select="id"/></xsl:attribute>
@ -119,7 +122,9 @@
<xsl:template match="board" mode="select">
<xsl:param name="prefix"/>
<option>
<xsl:attribute name="value"><xsl:value-of select="id"/></xsl:attribute>
<xsl:if test="not(/root/isTrueModerator = 'true') and not(isTransferTarget = 'true')">
<xsl:attribute name="disabled">disabled</xsl:attribute>
</xsl:if>
<xsl:value-of select="$prefix"/>
<xsl:value-of select="name"/>
</option>

Loading…
Cancel
Save