From 20409ac0ec208fc0515a3aaf5f148669067ff241 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Fri, 3 Sep 2010 17:06:50 +0000 Subject: [PATCH] Topicstarter moderation implemented --- Builder/IISMainHandler/build.txt | 2 +- Common/dataobjects/Board.cs | 36 ++++++++++++++++--- Common/dataobjects/Category.cs | 13 +++++-- Common/dataobjects/Moderator.cs | 9 +++-- Common/dataobjects/Post.cs | 13 +++++-- Common/dataobjects/Punishment.cs | 2 +- Common/dataobjects/PunishmentTransfer.cs | 4 +-- IISMainHandler/handlers/BoardsHandler.cs | 2 +- .../handlers/request/PunishHandler.cs | 2 +- .../handlers/response/PunishHandler.cs | 9 ++--- templates/Full/PostPunish.xslt | 7 +++- 11 files changed, 76 insertions(+), 23 deletions(-) diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index a89dec1..0f746c7 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -1034 \ No newline at end of file +1038 \ No newline at end of file diff --git a/Common/dataobjects/Board.cs b/Common/dataobjects/Board.cs index 2fb89c4..62ad2bf 100644 --- a/Common/dataobjects/Board.cs +++ b/Common/dataobjects/Board.cs @@ -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 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) { diff --git a/Common/dataobjects/Category.cs b/Common/dataobjects/Category.cs index 93a4d7c..12621a0 100644 --- a/Common/dataobjects/Category.cs +++ b/Common/dataobjects/Category.cs @@ -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)) ); } diff --git a/Common/dataobjects/Moderator.cs b/Common/dataobjects/Moderator.cs index 8554569..96230e7 100644 --- a/Common/dataobjects/Moderator.cs +++ b/Common/dataobjects/Moderator.cs @@ -74,7 +74,7 @@ namespace FLocal.Common.dataobjects { } private static readonly Dictionary> isModerator_cache = new Dictionary>(); - 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> byBoard_cache = new Dictionary>(); diff --git a/Common/dataobjects/Post.cs b/Common/dataobjects/Post.cs index 12d1889..2bd6a83 100644 --- a/Common/dataobjects/Post.cs +++ b/Common/dataobjects/Post.cs @@ -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"); diff --git a/Common/dataobjects/Punishment.cs b/Common/dataobjects/Punishment.cs index 9d57b24..7ed2722 100644 --- a/Common/dataobjects/Punishment.cs +++ b/Common/dataobjects/Punishment.cs @@ -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), diff --git a/Common/dataobjects/PunishmentTransfer.cs b/Common/dataobjects/PunishmentTransfer.cs index 397296c..b60341b 100644 --- a/Common/dataobjects/PunishmentTransfer.cs +++ b/Common/dataobjects/PunishmentTransfer.cs @@ -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()) ); } diff --git a/IISMainHandler/handlers/BoardsHandler.cs b/IISMainHandler/handlers/BoardsHandler.cs index 5194088..aba4e20 100644 --- a/IISMainHandler/handlers/BoardsHandler.cs +++ b/IISMainHandler/handlers/BoardsHandler.cs @@ -22,7 +22,7 @@ namespace FLocal.IISHandler.handlers { override protected IEnumerable 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()), diff --git a/IISMainHandler/handlers/request/PunishHandler.cs b/IISMainHandler/handlers/request/PunishHandler.cs index 4c41c5f..88e853c 100644 --- a/IISMainHandler/handlers/request/PunishHandler.cs +++ b/IISMainHandler/handlers/request/PunishHandler.cs @@ -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") diff --git a/IISMainHandler/handlers/response/PunishHandler.cs b/IISMainHandler/handlers/response/PunishHandler.cs index 5d2dc3d..284ce5c 100644 --- a/IISMainHandler/handlers/response/PunishHandler.cs +++ b/IISMainHandler/handlers/response/PunishHandler.cs @@ -21,7 +21,7 @@ namespace FLocal.IISHandler.handlers.response { override protected IEnumerable 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()) }; } } - + } \ No newline at end of file diff --git a/templates/Full/PostPunish.xslt b/templates/Full/PostPunish.xslt index 40574e2..ab30ebc 100644 --- a/templates/Full/PostPunish.xslt +++ b/templates/Full/PostPunish.xslt @@ -94,6 +94,9 @@ punishmentTypeId_ + + disabled +