PunishmentLayerChange implemented

main
Inga 🏳‍🌈 14 years ago
parent 240d648b38
commit bb19104ef5
  1. 1
      Common/TableManager.cs
  2. 1
      Common/actions/ChangeSet.cs
  3. 62
      Common/dataobjects/Post.cs
  4. 18
      Common/dataobjects/Punishment.cs
  5. 96
      Common/dataobjects/PunishmentLayerChange.cs
  6. 5
      IISMainHandler/handlers/request/PunishHandler.cs
  7. 2
      IISMainHandler/handlers/response/PunishHandler.cs
  8. 16
      templates/Full/PostPunish.xslt
  9. 13
      templates/Full/elems/PostInfo.xslt
  10. 15
      templates/Lite/PostPunish.xslt
  11. 13
      templates/Lite/elems/PostInfo.xslt

@ -22,6 +22,7 @@ namespace FLocal.Common {
dataobjects.Post.TableSpec.instance,
dataobjects.PostLayer.TableSpec.instance,
dataobjects.Punishment.TableSpec.instance,
dataobjects.PunishmentLayerChange.TableSpec.instance,
dataobjects.PunishmentTransfer.TableSpec.instance,
dataobjects.PunishmentType.TableSpec.instance,
dataobjects.QuickLink.TableSpec.instance,

@ -37,6 +37,7 @@ namespace FLocal.Common.actions {
dataobjects.Moderator.TableSpec.TABLE,
dataobjects.Punishment.TableSpec.TABLE,
dataobjects.PunishmentTransfer.TableSpec.TABLE,
dataobjects.PunishmentLayerChange.TableSpec.TABLE,
dataobjects.Session.TableSpec.TABLE,
}
);

@ -360,7 +360,7 @@ namespace FLocal.Common.dataobjects {
}
private readonly object Punish_Locker = new object();
public void Punish(Account account, PunishmentType type, string comment, PunishmentTransfer.NewTransferInfo? transferInfo) {
public void Punish(Account account, PunishmentType type, string comment, PunishmentTransfer.NewTransferInfo? transferInfo, PunishmentLayerChange.NewLayerChangeInfo? layerChangeInfo) {
if(string.IsNullOrEmpty(comment)) throw new FLocalException("Comment is empty");
@ -386,13 +386,59 @@ namespace FLocal.Common.dataobjects {
)
);
InsertChange transferInsert = null;
InsertChange layerChangeInsert = null;
if(layerChangeInfo.HasValue) {
var _layerChangeInfo = layerChangeInfo.Value;
if(_layerChangeInfo.newLayer.name == PostLayer.NAME_HIDDEN) throw new FLocalException("You cannot hide posts");
layerChangeInsert = new InsertChange(
PunishmentLayerChange.TableSpec.instance,
new Dictionary<string,AbstractFieldValue> {
{ PunishmentLayerChange.TableSpec.FIELD_OLDLAYERID, new ScalarFieldValue(this.layerId.ToString()) },
{ PunishmentLayerChange.TableSpec.FIELD_NEWLAYERID, new ScalarFieldValue(_layerChangeInfo.newLayerId.ToString()) },
{ PunishmentLayerChange.TableSpec.FIELD_ISSUBTHREADCHANGE, new ScalarFieldValue(_layerChangeInfo.isSubthreadChange.ToDBString()) },
}
);
changes.Union(layerChangeInsert);
List<Post> postsAffected;
if(_layerChangeInfo.isSubthreadChange) {
postsAffected = this.ToSequence(post => post.subPosts).OrderBy(post => post.id).ToList();
} else {
postsAffected = new List<Post>();
postsAffected.Add(this);
}
changes = changes.Union(
from post in postsAffected
select (AbstractChange)new UpdateChange(
Post.TableSpec.instance,
new Dictionary<string,AbstractFieldValue> {
{ Post.TableSpec.FIELD_LAYERID, new ScalarFieldValue(_layerChangeInfo.newLayerId.ToString()) },
},
post.id
)
);
}
InsertChange transferInsert = null;
if(transferInfo.HasValue) {
var _transferInfo = transferInfo.Value;
transferInsert = new InsertChange(
PunishmentTransfer.TableSpec.instance,
new Dictionary<string,AbstractFieldValue> {
{ PunishmentTransfer.TableSpec.FIELD_OLDBOARDID, new ScalarFieldValue(this.thread.boardId.ToString()) },
{ PunishmentTransfer.TableSpec.FIELD_NEWBOARDID, new ScalarFieldValue(_transferInfo.newBoardId.ToString()) },
{ PunishmentTransfer.TableSpec.FIELD_ISSUBTHREADTRANSFER, new ScalarFieldValue(_transferInfo.isSubthreadTransfer.ToDBString()) },
{ PunishmentTransfer.TableSpec.FIELD_OLDPARENTPOSTID, new ScalarFieldValue(this.parentPostId.HasValue ? this.parentPostId.ToString() : null) },
}
);
changes = changes.Union(transferInsert);
Post lastAffectedPost;
int totalAffectedPosts;
@ -493,17 +539,6 @@ namespace FLocal.Common.dataobjects {
)
);
transferInsert = new InsertChange(
PunishmentTransfer.TableSpec.instance,
new Dictionary<string,AbstractFieldValue> {
{ PunishmentTransfer.TableSpec.FIELD_OLDBOARDID, new ScalarFieldValue(this.thread.boardId.ToString()) },
{ PunishmentTransfer.TableSpec.FIELD_NEWBOARDID, new ScalarFieldValue(_transferInfo.newBoardId.ToString()) },
{ PunishmentTransfer.TableSpec.FIELD_ISSUBTHREADTRANSFER, new ScalarFieldValue(_transferInfo.isSubthreadTransfer.ToDBString()) },
{ PunishmentTransfer.TableSpec.FIELD_OLDPARENTPOSTID, new ScalarFieldValue(this.parentPostId.HasValue ? this.parentPostId.ToString() : null) },
}
);
changes = changes.Union(transferInsert);
changes = changes.Union(
new UpdateChange(
TableSpec.instance,
@ -548,6 +583,7 @@ namespace FLocal.Common.dataobjects {
{ Punishment.TableSpec.FIELD_COMMENT, new ScalarFieldValue(comment) },
{ Punishment.TableSpec.FIELD_EXPIRES, new ScalarFieldValue(DateTime.Now.Add(type.timeSpan).ToUTCString()) },
{ Punishment.TableSpec.FIELD_TRANSFERID, (transferInsert != null) ? (AbstractFieldValue)new ReferenceFieldValue(transferInsert) : (AbstractFieldValue)new ScalarFieldValue(null) },
{ Punishment.TableSpec.FIELD_LAYERCHANGEID, (layerChangeInsert != null) ? (AbstractFieldValue)new ReferenceFieldValue(layerChangeInsert) : (AbstractFieldValue)new ScalarFieldValue(null) },
}
)
);

@ -23,6 +23,7 @@ namespace FLocal.Common.dataobjects {
public const string FIELD_COMMENT = "Comment";
public const string FIELD_EXPIRES = "Expires";
public const string FIELD_TRANSFERID = "TransferId";
public const string FIELD_LAYERCHANGEID = "LayerChangeId";
public static readonly TableSpec instance = new TableSpec();
public string name { get { return TABLE; } }
public string idName { get { return FIELD_ID; } }
@ -141,6 +142,19 @@ namespace FLocal.Common.dataobjects {
}
}
private int? _layerChangeId;
public int? layerChangeId {
get {
this.LoadIfNotLoaded();
return this._layerChangeId;
}
}
public PunishmentLayerChange layerChange {
get {
return PunishmentLayerChange.LoadById(this.layerChangeId.Value);
}
}
protected override void doFromHash(Dictionary<string, string> data) {
this._postId = int.Parse(data[TableSpec.FIELD_POSTID]);
this._ownerId = int.Parse(data[TableSpec.FIELD_OWNERID]);
@ -152,6 +166,7 @@ namespace FLocal.Common.dataobjects {
this._comment = data[TableSpec.FIELD_COMMENT];
this._expires = Util.ParseDateTimeFromTimestamp(data[TableSpec.FIELD_EXPIRES]).Value;
this._transferId = Util.ParseInt(data[TableSpec.FIELD_TRANSFERID]);
this._layerChangeId = Util.ParseInt(data[TableSpec.FIELD_LAYERCHANGEID]);
}
public XElement exportToXml(UserContext context) {
@ -165,7 +180,8 @@ namespace FLocal.Common.dataobjects {
new XElement("isWithdrawed", this.isWithdrawed.ToPlainString()),
new XElement("comment", this.comment),
new XElement("expires", this.expires),
this.transferId.HasValue ? this.transfer.exportToXml(context) : null
this.transferId.HasValue ? this.transfer.exportToXml(context) : null,
this.layerChangeId.HasValue ? this.layerChange.exportToXml(context) : null
);
}

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using FLocal.Core;
using FLocal.Core.DB;
using FLocal.Core.DB.conditions;
namespace FLocal.Common.dataobjects {
public class PunishmentLayerChange : SqlObject<PunishmentLayerChange> {
public struct NewLayerChangeInfo {
public readonly int newLayerId;
public PostLayer newLayer {
get {
return PostLayer.LoadById(this.newLayerId);
}
}
public readonly bool isSubthreadChange;
public NewLayerChangeInfo(PostLayer newLayer, bool isSubthreadChange) {
this.newLayerId = newLayer.id;
this.isSubthreadChange = isSubthreadChange;
}
}
public class TableSpec : ISqlObjectTableSpec {
public const string TABLE = "PunishmentLayerChanges";
public const string FIELD_ID = "Id";
public const string FIELD_OLDLAYERID = "OldLayerId";
public const string FIELD_NEWLAYERID = "NewLayerId";
public const string FIELD_ISSUBTHREADCHANGE = "IsSubthreadChange";
public static readonly TableSpec instance = new TableSpec();
public string name { get { return TABLE; } }
public string idName { get { return FIELD_ID; } }
public void refreshSqlObject(int id) { Refresh(id); }
}
protected override ISqlObjectTableSpec table { get { return TableSpec.instance; } }
private int _oldLayerId;
public int oldLayerId {
get {
this.LoadIfNotLoaded();
return this._oldLayerId;
}
}
public PostLayer oldLayer {
get {
return PostLayer.LoadById(this.oldLayerId);
}
}
private int _newLayerId;
public int newLayerId {
get {
this.LoadIfNotLoaded();
return this._newLayerId;
}
}
public PostLayer newLayer {
get {
return PostLayer.LoadById(this.newLayerId);
}
}
private bool _isSubthreadChange;
public bool isSubthreadChange {
get {
this.LoadIfNotLoaded();
return this._isSubthreadChange;
}
}
protected override void doFromHash(Dictionary<string, string> data) {
this._oldLayerId = int.Parse(data[TableSpec.FIELD_OLDLAYERID]);
this._newLayerId = int.Parse(data[TableSpec.FIELD_NEWLAYERID]);
this._isSubthreadChange = Util.string2bool(data[TableSpec.FIELD_ISSUBTHREADCHANGE]);
}
public XElement exportToXml(UserContext context) {
return new XElement("layerChange",
new XElement("id", this.id),
new XElement("oldLayer", this.oldLayer.exportToXml(context)),
new XElement("newLayer", this.newLayer.exportToXml(context)),
new XElement("isSubthreadChange", this.isSubthreadChange.ToPlainString())
);
}
}
}

@ -26,6 +26,11 @@ namespace FLocal.IISHandler.handlers.request {
?
(PunishmentTransfer.NewTransferInfo?)new PunishmentTransfer.NewTransferInfo(Board.LoadById(int.Parse(context.httprequest.Form["transfer_boardId"])), context.httprequest.Form["transfer_subThread"] == "transfer_subThread")
:
null,
(context.httprequest.Form["layerChange"] == "layerChange")
?
(PunishmentLayerChange.NewLayerChangeInfo?)new PunishmentLayerChange.NewLayerChangeInfo(PostLayer.LoadById(int.Parse(context.httprequest.Form["layerChange_layerId"])), context.httprequest.Form["layerChange_subThread"] == "layerChange_subThread")
:
null
);

@ -28,7 +28,7 @@ namespace FLocal.IISHandler.handlers.response {
post.thread.exportToXml(context),
post.exportToXml(context),
new XElement("layers",
from layer in PostLayer.allLayers select layer.exportToXml(context)
from layer in PostLayer.allLayers where layer.name != PostLayer.NAME_HIDDEN select layer.exportToXml(context)
),
new XElement("categories",
from category in Category.allCategories select

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="elems\Main.xslt"/>
<xsl:import href="elems\TextEditor.xslt"/>
<xsl:template name="specificTitle">
<xsl:text>Ìîäåðèðîâàíèå ñîîáùåíèÿ - </xsl:text>
<xsl:value-of select="post/title"/>
@ -44,6 +45,21 @@
<xsl:text> ñî âñåìè îòâåòàìè</xsl:text>
</label>
<br/>
<input type="checkbox" name="layerChange" value="layerChange" id="LayerChange"/>
<label for="LayerChange">
<xsl:text> Èçìåíèòü ñëîé</xsl:text>
</label>
<select name="layerChange_layerId">
<option value="-1">Âûáåðèòå ñëîé</option>
<xsl:apply-templates select="layers/layer">
<xsl:with-param name="defaultLayerId"><xsl:value-of select="post/layerId"/></xsl:with-param>
</xsl:apply-templates>
</select>
<input type="checkbox" name="layerChange_subThread" value="layerChange_subThread" id="LayerChange_SubThread"/>
<label for="LayerChange_SubThread">
<xsl:text> ñî âñåìè îòâåòàìè</xsl:text>
</label>
<br/>
<br/>
<xsl:text>Êîììåíòàðèé: </xsl:text>
<br/>

@ -220,6 +220,19 @@
</a>
<br/>
</xsl:if>
<xsl:if test="layerChange">
<xsl:choose>
<xsl:when test="layerChange/isSubthreadChange='true'">
<xsl:text>Ñëîé ïîäâåòêè áûë èçìåí¸í</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Ñëîé ñîîáùåíèÿ áûë èçìåí¸í</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text> ñ </xsl:text>
<xsl:value-of select="layerChange/oldLayer/layer/name"/>
<br/>
</xsl:if>
<br/>
</font>
</td>

@ -40,6 +40,21 @@
<xsl:text> ńî âńĺěč îňâĺňŕěč</xsl:text>
</label>
<br/>
<input type="checkbox" name="layerChange" value="layerChange" id="LayerChange"/>
<label for="LayerChange">
<xsl:text> Èçìåíèòü ñëîé</xsl:text>
</label>
<select name="layerChange_layerId">
<option value="-1">Âûáåðèòå ñëîé</option>
<xsl:apply-templates select="layers/layer">
<xsl:with-param name="defaultLayerId"><xsl:value-of select="post/layerId"/></xsl:with-param>
</xsl:apply-templates>
</select>
<input type="checkbox" name="layerChange_subThread" value="layerChange_subThread" id="LayerChange_SubThread"/>
<label for="LayerChange_SubThread">
<xsl:text> ñî âñåìè îòâåòàìè</xsl:text>
</label>
<br/>
<br/>
<xsl:text>Ęîěěĺíňŕđčé: </xsl:text>
<br/>

@ -123,6 +123,19 @@
</a>
<br/>
</xsl:if>
<xsl:if test="layerChange">
<xsl:choose>
<xsl:when test="layerChange/isSubthreadTransfer='true'">
<xsl:text>Ñëîé ïîäâåòêè áûë èçìåí¸í</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Ñëîé ñîîáùåíèÿ áûë èçìåí¸í</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text> ñ </xsl:text>
<xsl:value-of select="layerChange/oldLayer/layer/name"/>
<br/>
</xsl:if>
<br/>
</font>
</td>

Loading…
Cancel
Save