diff --git a/Common/TableManager.cs b/Common/TableManager.cs index 523f437..82d5724 100644 --- a/Common/TableManager.cs +++ b/Common/TableManager.cs @@ -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, diff --git a/Common/actions/ChangeSet.cs b/Common/actions/ChangeSet.cs index 9d8531d..d8c0b07 100644 --- a/Common/actions/ChangeSet.cs +++ b/Common/actions/ChangeSet.cs @@ -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, } ); diff --git a/Common/dataobjects/Post.cs b/Common/dataobjects/Post.cs index 5166546..3da57e2 100644 --- a/Common/dataobjects/Post.cs +++ b/Common/dataobjects/Post.cs @@ -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 { + { 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 postsAffected; + if(_layerChangeInfo.isSubthreadChange) { + postsAffected = this.ToSequence(post => post.subPosts).OrderBy(post => post.id).ToList(); + } else { + postsAffected = new List(); + postsAffected.Add(this); + } + + changes = changes.Union( + from post in postsAffected + select (AbstractChange)new UpdateChange( + Post.TableSpec.instance, + new Dictionary { + { 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 { + { 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 { - { 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) }, } ) ); diff --git a/Common/dataobjects/Punishment.cs b/Common/dataobjects/Punishment.cs index 7ed2722..c4c5250 100644 --- a/Common/dataobjects/Punishment.cs +++ b/Common/dataobjects/Punishment.cs @@ -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 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 ); } diff --git a/Common/dataobjects/PunishmentLayerChange.cs b/Common/dataobjects/PunishmentLayerChange.cs new file mode 100644 index 0000000..7bd4479 --- /dev/null +++ b/Common/dataobjects/PunishmentLayerChange.cs @@ -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 { + + 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 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()) + ); + } + + } +} diff --git a/IISMainHandler/handlers/request/PunishHandler.cs b/IISMainHandler/handlers/request/PunishHandler.cs index 88e853c..00f2ea2 100644 --- a/IISMainHandler/handlers/request/PunishHandler.cs +++ b/IISMainHandler/handlers/request/PunishHandler.cs @@ -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 ); diff --git a/IISMainHandler/handlers/response/PunishHandler.cs b/IISMainHandler/handlers/response/PunishHandler.cs index 4729afa..3dba876 100644 --- a/IISMainHandler/handlers/response/PunishHandler.cs +++ b/IISMainHandler/handlers/response/PunishHandler.cs @@ -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 diff --git a/templates/Full/PostPunish.xslt b/templates/Full/PostPunish.xslt index 39ddbbb..a02df30 100644 --- a/templates/Full/PostPunish.xslt +++ b/templates/Full/PostPunish.xslt @@ -1,6 +1,7 @@ + Модерирование сообщения - @@ -44,6 +45,21 @@ со всеми ответами
+ + + + + +

Комментарий:
diff --git a/templates/Full/elems/PostInfo.xslt b/templates/Full/elems/PostInfo.xslt index c8dc5ac..96217fa 100644 --- a/templates/Full/elems/PostInfo.xslt +++ b/templates/Full/elems/PostInfo.xslt @@ -220,6 +220,19 @@
+ + + + Слой подветки был изменён + + + Слой сообщения был изменён + + + с + +
+

diff --git a/templates/Lite/PostPunish.xslt b/templates/Lite/PostPunish.xslt index 7278a32..d461271 100644 --- a/templates/Lite/PostPunish.xslt +++ b/templates/Lite/PostPunish.xslt @@ -40,6 +40,21 @@ со всеми ответами
+ + + + + +

Комментарий:
diff --git a/templates/Lite/elems/PostInfo.xslt b/templates/Lite/elems/PostInfo.xslt index 33c1e2e..6ca9259 100644 --- a/templates/Lite/elems/PostInfo.xslt +++ b/templates/Lite/elems/PostInfo.xslt @@ -123,6 +123,19 @@
+ + + + Слой подветки был изменён + + + Слой сообщения был изменён + + + с + +
+