Boards administrators implemented

main
Inga 🏳‍🌈 14 years ago
parent c3be9c02c4
commit 26b620d5c4
  1. 2
      Builder/IISMainHandler/build.txt
  2. 18
      Common/dataobjects/Board.cs
  3. 28
      Common/dataobjects/Moderator.cs
  4. 3
      Common/dataobjects/Post.cs
  5. 2
      templates/Full/elems/BoardInfo.xslt
  6. 11
      templates/Full/elems/Main.xslt
  7. 11
      templates/Lite/elems/Main.xslt

@ -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<string, string> 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) {

@ -76,6 +76,7 @@ namespace FLocal.Common.dataobjects {
private static readonly Dictionary<int, Dictionary<int, bool>> isModerator_cache = new Dictionary<int,Dictionary<int,bool>>();
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<int, IEnumerable<int>> byBoard_cache = new Dictionary<int,IEnumerable<int>>();
private static readonly Dictionary<int, List<int>> byBoard_cache = new Dictionary<int, List<int>>();
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<Account> 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<int, IEnumerable<int>> byAccount_cache = new Dictionary<int,IEnumerable<int>>();
private static readonly Dictionary<int, List<int>> byAccount_cache = new Dictionary<int, List<int>>();
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<Board> GetModeratedBoards(Account account) {

@ -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()),

@ -47,7 +47,7 @@
<xsl:apply-templates select="lastPostInfo"/>
</td>
<td width="10%" class="modcolumn" align="center">
<xsl:apply-templates select="moderators/user" mode="userLink"/>
<xsl:apply-templates select="administrator/user | moderators/user" mode="userLink"/>
</td>
</tr>
</xsl:template>

@ -230,9 +230,14 @@
</xsl:attribute>
<xsl:attribute name="href">/Users/User/<xsl:value-of select="id"/>/Info/</xsl:attribute>
<xsl:value-of select="name"/>
<xsl:if test="isModerator='true'">
<img src="/static/images/mod.gif" border="0"/>
</xsl:if>
<xsl:choose>
<xsl:when test="isAdministrator='true'">
<img src="/static/images/adm.gif" border="0"/>
</xsl:when>
<xsl:when test="isModerator='true'">
<img src="/static/images/mod.gif" border="0"/>
</xsl:when>
</xsl:choose>
</a>
</xsl:template>

@ -206,9 +206,14 @@
</xsl:attribute>
<xsl:attribute name="href">/Users/User/<xsl:value-of select="id"/>/Info/</xsl:attribute>
<xsl:value-of select="name"/>
<xsl:if test="isModerator='true'">
<xsl:text>^M</xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="isAdministrator='true'">
<xsl:text>^A</xsl:text>
</xsl:when>
<xsl:when test="isModerator='true'">
<xsl:text>^M</xsl:text>
</xsl:when>
</xsl:choose>
</a>
</xsl:template>

Loading…
Cancel
Save