private static void checkFlags(string delta_flags, string[] allowed_meta_titles, params string[] allowed_flags) { if (delta_flags.Length > 0) { if (delta_flags[0] != SandFlags.FLAGS_SEPARATOR || delta_flags[delta_flags.Length - 1] != SandFlags.FLAGS_SEPARATOR) { Util.ThrowBadRequestException("Flags格式不正確。"); } if (!SandFlags.CheckWithinAllowed(delta_flags, allowed_flags, allowed_meta_titles)) { Util.ThrowBadRequestException("未允許的Flags。"); } } }
public ActionResult ControlLetter(string board_id, string discussion_id, string letter_id, string delta_flags, string reason) { if (!Util.IsAjaxRequest(Request)) { Util.ThrowBadRequestException("Not ajax post."); } object ret_obj = Warehouse.RateLimiter.Validate(CarryType.ControlLetter); if (ret_obj != null) { return(Json(ret_obj)); } checkControlFlags(delta_flags, letter_id == SandId.HEADING_LETTER_ID); if (reason.Length > 500 * HeartsConfiguration.LENGTH_CHECK_MARGIN /*counting into foreword*/) { Util.ThrowBadRequestException("理由長度過長。"); } ControlHistory mh = DiscussionLoadStore.ControlLetter(board_id, discussion_id, letter_id, delta_flags); if (letter_id == SandId.HEADING_LETTER_ID) { delta_flags = SandFlags.Remove(delta_flags, SandFlags.MT_REPORT); DiscussionListStore.OperateFlags(board_id, discussion_id, new FlagMergeOperation(delta_flags)); } if (mh.ReportCount != 0) { DiscussionListStore.OperateFlags(board_id, discussion_id, new FlagOperation { type = FlagOperation.Type.Add, MetaTitle = SandFlags.MT_REPORT, N = mh.ReportCount }); } int id_num = SandId.ExtractIdNumber(letter_id); string remark_delta_flags = SandFlags.Add(string.Empty, SandFlags.MT_REPLY_TO, id_num); string remark_letter_id = DiscussionLoadStore.CreateLetter(board_id, discussion_id, null, reason, Subtype.d, remark_delta_flags, null); // while deleting/undeleting discussion, the remark_delta_flags is ,r0, and will be removed. return(Json(new { ok = true })); }