From 26b620d5c461195047400a7033d4dd50921e97ea Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Wed, 15 Sep 2010 12:18:37 +0000 Subject: [PATCH] Boards administrators implemented --- Builder/IISMainHandler/build.txt | 2 +- Common/dataobjects/Board.cs | 18 +++++++++++++++++- Common/dataobjects/Moderator.cs | 28 +++++++++++++++++++++------- Common/dataobjects/Post.cs | 3 ++- templates/Full/elems/BoardInfo.xslt | 2 +- templates/Full/elems/Main.xslt | 11 ++++++++--- templates/Lite/elems/Main.xslt | 11 ++++++++--- 7 files changed, 58 insertions(+), 17 deletions(-) diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index d3e6945..1ca5934 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -1269 \ No newline at end of file +1287 \ No newline at end of file diff --git a/Common/dataobjects/Board.cs b/Common/dataobjects/Board.cs index 6da7517..18c8b87 100644 --- a/Common/dataobjects/Board.cs +++ b/Common/dataobjects/Board.cs @@ -33,6 +33,7 @@ namespace FLocal.Common.dataobjects { public const string FIELD_ISTRANSFERTARGET = "IsTransferTarget"; public const string FIELD_ISTOPICSTARTERMODERATION = "IsTopicstarterModeration"; public const string FIELD_ISFLOOBAGE = "IsFloobage"; + public const string FIELD_ADMINISTRATORID = "AdministratorId"; public static readonly TableSpec instance = new TableSpec(); public string name { get { return TABLE; } } public string idName { get { return FIELD_ID; } } @@ -168,6 +169,19 @@ namespace FLocal.Common.dataobjects { } } + private int _administratorId; + public int administratorId { + get { + this.LoadIfNotLoaded(); + return this._administratorId; + } + } + public Account administrator { + get { + return Account.LoadById(this._administratorId); + } + } + protected override void doFromHash(Dictionary data) { this._sortOrder = int.Parse(data[TableSpec.FIELD_SORTORDER]); this._categoryId = Util.ParseInt(data[TableSpec.FIELD_CATEGORYID]); @@ -181,6 +195,7 @@ namespace FLocal.Common.dataobjects { this._isTransferTarget = Util.string2bool(data[TableSpec.FIELD_ISTRANSFERTARGET]); this._isTopicstarterModeration = Util.string2bool(data[TableSpec.FIELD_ISTOPICSTARTERMODERATION]); this._isFloobage = Util.string2bool(data[TableSpec.FIELD_ISFLOOBAGE]); + this._administratorId = int.Parse(data[TableSpec.FIELD_ADMINISTRATORID]); } private readonly object subBoards_Locker = new object(); @@ -264,7 +279,8 @@ namespace FLocal.Common.dataobjects { new XElement("lastPostInfo", this.exportLastPostInfo(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()) + new XElement("isTransferTarget", this.isTransferTarget.ToPlainString()), + new XElement("administrator", this.administrator.user.exportToXmlForViewing(context, new XElement("isAdministrator", "true"))) ); if(context.account != null) { diff --git a/Common/dataobjects/Moderator.cs b/Common/dataobjects/Moderator.cs index 7165f04..daaddef 100644 --- a/Common/dataobjects/Moderator.cs +++ b/Common/dataobjects/Moderator.cs @@ -76,6 +76,7 @@ namespace FLocal.Common.dataobjects { private static readonly Dictionary> isModerator_cache = new Dictionary>(); public static bool isTrueModerator(Account account, Board board) { //slight optimisation... + if(board.administratorId == account.id) return true; UserGroup group = account.user.userGroup; if(group.name != UserGroup.NAME_ADMINISTRATORS && group.name != UserGroup.NAME_MODERATORS) return false; @@ -113,7 +114,14 @@ namespace FLocal.Common.dataobjects { return isModerator_cache[account.id][board.id]; } public static bool isModerator(Account account, Thread thread) { - return (thread.board.isFloobage) || (thread.board.isTopicstarterModeration && thread.topicstarterId == account.userId) || isTrueModerator(account, thread.board); + return + (thread.board.isFloobage) + || + (thread.board.administratorId == account.id) + || + (thread.board.isTopicstarterModeration && thread.topicstarterId == account.userId) + || + isTrueModerator(account, thread.board); } public static bool isModerator(User user, Thread thread) { Account account; @@ -125,11 +133,11 @@ namespace FLocal.Common.dataobjects { return isModerator(account, thread); } - private static readonly Dictionary> byBoard_cache = new Dictionary>(); + private static readonly Dictionary> byBoard_cache = new Dictionary>(); private static void byBoard_Recalculate(int boardId) { lock(byBoard_cache) { byBoard_cache[boardId] = - from stringId in Config.instance.mainConnection.LoadIdsByConditions( + (from stringId in Config.instance.mainConnection.LoadIdsByConditions( TableSpec.instance, new ComparisonCondition( TableSpec.instance.getColumnSpec(TableSpec.FIELD_BOARDID), @@ -138,7 +146,10 @@ namespace FLocal.Common.dataobjects { ), Diapasone.unlimited ) - select Moderator.LoadById(int.Parse(stringId)).accountId; + let moderator = Moderator.LoadById(int.Parse(stringId)) + where moderator.isActive + select moderator.accountId) + .ToList(); } } public static IEnumerable GetModerators(Board board) { @@ -148,11 +159,11 @@ namespace FLocal.Common.dataobjects { return from id in byBoard_cache[board.id] select Account.LoadById(id); } - private static readonly Dictionary> byAccount_cache = new Dictionary>(); + private static readonly Dictionary> byAccount_cache = new Dictionary>(); private static void byAccount_Recalculate(int accountId) { lock(byAccount_cache) { byAccount_cache[accountId] = - from stringId in Config.instance.mainConnection.LoadIdsByConditions( + (from stringId in Config.instance.mainConnection.LoadIdsByConditions( TableSpec.instance, new ComparisonCondition( TableSpec.instance.getColumnSpec(TableSpec.FIELD_ACCOUNTID), @@ -161,7 +172,10 @@ namespace FLocal.Common.dataobjects { ), Diapasone.unlimited ) - select Moderator.LoadById(int.Parse(stringId)).boardId; + let moderator = Moderator.LoadById(int.Parse(stringId)) + where moderator.isActive + select moderator.boardId) + .ToList(); } } public static IEnumerable GetModeratedBoards(Account account) { diff --git a/Common/dataobjects/Post.cs b/Common/dataobjects/Post.cs index a8e0c9a..4f92fcf 100644 --- a/Common/dataobjects/Post.cs +++ b/Common/dataobjects/Post.cs @@ -239,7 +239,8 @@ namespace FLocal.Common.dataobjects { new XElement("poster", this.poster.exportToXmlForViewing( context, - new XElement("isModerator", Moderator.isModerator(this.poster, this.thread).ToPlainString()) + new XElement("isModerator", Moderator.isModerator(this.poster, this.thread).ToPlainString()), + new XElement("isAdministrator", (this.thread.board.administrator.userId == this.poster.id).ToPlainString()) ) ), new XElement("postDate", this.postDate.ToXml()), diff --git a/templates/Full/elems/BoardInfo.xslt b/templates/Full/elems/BoardInfo.xslt index 5fd20ba..ffa08f5 100644 --- a/templates/Full/elems/BoardInfo.xslt +++ b/templates/Full/elems/BoardInfo.xslt @@ -47,7 +47,7 @@ - + diff --git a/templates/Full/elems/Main.xslt b/templates/Full/elems/Main.xslt index ba815da..adf4782 100644 --- a/templates/Full/elems/Main.xslt +++ b/templates/Full/elems/Main.xslt @@ -230,9 +230,14 @@ /Users/User//Info/ - - - + + + + + + + + diff --git a/templates/Lite/elems/Main.xslt b/templates/Lite/elems/Main.xslt index f64e7d0..f3de592 100644 --- a/templates/Lite/elems/Main.xslt +++ b/templates/Lite/elems/Main.xslt @@ -206,9 +206,14 @@ /Users/User//Info/ - - ^M - + + + ^A + + + ^M + +