public static void WriteForCrawler(TextWriter writer, DynamicTableEntity entity, bool summary_only, string link) { writer.WriteStartTag("section"); writer.WriteForCrawler("header", entity.RowKey); writer.WriteForCrawler("aside", entity["subtype"].StringValue); CreatorConverter.WriteForCrawler(writer, entity, CreatorConverter.Status.Creator); string whole_words = GetWholeWords(entity, summary_only); //HtmlUtil.WriteForCrawler(writer, "summary", entity["abstract"].StringValue); writer.WriteStartTag("summary"); if (link != null) { writer.WriteAnchor(link, whole_words); } else { writer.WriteRaw(whole_words); } writer.WriteEndTag("summary"); string flags = entity.GetFlags(); if (flags.Length != 0) { writer.WriteForCrawler("footer", flags); } CreatorConverter.WriteForCrawler(writer, entity, CreatorConverter.Status.LastEditor); writer.WriteEndTag("section"); }
private static int userLevel(string board_id, string discussion_id, DynamicTableEntity entity, bool is_discussion, bool is_undelete) { if (!is_undelete && !is_discussion && CreatorConverter.IsCurrentUserCreator(entity)) { return(99); } else if (IsSiteOwner()) { return(90); } else if (IsChairOwner(board_id)) { return(80); } else if (IsViceOwner(board_id)) { return(60); } else if (DiscussionLoadStore.IsCurrentUserDiscussionCreator(board_id, discussion_id)) { return(30); } else { return(20); } }
public static void LetterToJson(JsonTextWriter writer, DynamicTableEntity entity, bool summary_only) { writer.WritePropertyName(entity.RowKey); writer.WriteStartArray(); // Keep order writer.WriteValue(entity["subtype"].StringValue); CreatorConverter.EntityWrite(writer, entity, CreatorConverter.Status.Creator); writer.WriteValue(entity["abstract"].StringValue); string words = entity.GetString("words", string.Empty); // todo: should call GetWholeWords(). if (summary_only) { writer.WriteValue(words.Length); } else { writer.WriteValue(words); } writer.WriteValue(entity.GetFlags()); CreatorConverter.EntityWrite(writer, entity, CreatorConverter.Status.LastEditor); writer.WriteEndArray(); }
public static void SetBoardSetting(string board_id, string board_name) { TableResult result = Warehouse.BoardListTable.Execute(TableOperation.Retrieve(board_id, EMPTY_ROW_KEY)); DynamicTableEntity entity = (DynamicTableEntity)result.Result; // if (entity != null) // let it throw null reference exception. int ec = RevisionStore.IncreaseEditCount(entity); string partition_key = SandId.CombineId(Warehouse.BoardListTable.Name, board_id); RevisionStore.CreateHistory(entity, partition_key, ec, "boardname"); CreatorConverter.FillEntity(entity, CreatorConverter.Status.Editor, null); entity["boardname"].StringValue = board_name; Warehouse.BoardListTable.Execute(TableOperation.Replace(entity)); // Throws StorageException ((412) Precondition Failed) if the entity is modified in between. //don't work for child action. //HttpResponse.RemoveOutputCacheItem("/boardlist"); //List<string> selection_list = SelectionBoardListResult.GetSelectionList(board_id); //if (selection_list != null) //foreach (string selection_id in selection_list) //don't work for child action. //HttpResponse.RemoveOutputCacheItem("/discussionlist/" + selection_id); Warehouse.BsMapPond.Notify(); Warehouse.DiscussionListPond.Notify(board_id); Warehouse.BoardSettingPond.Notify(board_id); }
public static string /*board id*/ CreateBoard(string board_name) { int next_id = NextIdStore.Next(Warehouse.BoardListTable, null); string board_id = SandId.MakeBoardId(next_id); DynamicTableEntity entity = new DynamicTableEntity(board_id, EMPTY_ROW_KEY); entity["boardname"] = new EntityProperty(board_name); entity.OperateFlags(new FlagMergeOperation(SandFlags.MT_LOW_KEY + "1")); #if OLD entity["createtime"] = new EntityProperty(DateTime.Now); entity["creatoruid"] = new EntityProperty(WebSecurity.CurrentUserId); entity["creatormid"] = new EntityProperty(UserStore.CurrentUserMId); #else CreatorConverter.FillEntity(entity, CreatorConverter.Status.Editor, null); #endif Warehouse.BoardListTable.Execute(TableOperation.Insert(entity)); DiscussionListStore.CreateSkeleton(board_id); //don't work for child action. //HttpResponse.RemoveOutputCacheItem("/boardlist"); Warehouse.BsMapPond.Notify(); return(board_id); }
public static bool IsCurrentUserDiscussionCreator(string board_id, string discussion_id) { string partition_key = SandId.CombineId(board_id, discussion_id); TableResult result = Warehouse.DiscussionLoadTable.Execute(TableOperation.Retrieve(partition_key, SandId.HEADING_LETTER_ID)); DynamicTableEntity entity = (DynamicTableEntity)result.Result; return(CreatorConverter.IsCurrentUserCreator(entity)); }
public static void CheckPermanentDeleteRight(string board_id, string discussion_id, string letter_id, DynamicTableEntity entity) { bool is_discussion = letter_id == SandId.HEADING_LETTER_ID; if (is_discussion) { throw new ProgramLogicException(); } if (!CreatorConverter.IsCurrentUserCreator(entity)) { Util.ThrowUnauthorizedException("沒有刪除權限。只有原作者可以永久刪除留言。"); } }
public static void ModifyLetterFlags(DynamicTableEntity entity, string editor, string delta_flags) { entity.OperateFlags(new FlagMergeOperation(delta_flags)); // don't count into last edit for delete/report/permanent delete. if (editor != null) { CreatorConverter.FillEntity(entity, CreatorConverter.Status.LastEditor, editor); if (CreatorConverter.IsCurrentUserCreator(entity)) { CreatorConverter.ChangeNickname(entity, CreatorConverter.Status.Creator, editor); } } }
public static void CheckEditRight(string board_id, string discussion_id, DynamicTableEntity entity) { Subtype subtype = LetterConverter.GetSubtype(entity); if (subtype == Subtype.d) { Util.ThrowUnauthorizedException("不能編輯的類型。"); } if (!CreatorConverter.IsCurrentUserCreator(entity) && !DiscussionLoadStore.IsCurrentUserDiscussionCreator(board_id, discussion_id) && !IsBoardOwner(board_id)) { Util.ThrowUnauthorizedException("沒有編輯權限。只有副板主以上、串主、或原作者可以編輯。"); } }
private static void copyBoardListToSeparateTable() { string pkFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "boardlist1"); TableQuery query = new TableQuery().Where(pkFilter); foreach (DynamicTableEntity entity in Warehouse.SiteTable.ExecuteQuery(query)) { DynamicTableEntity new_entity = new DynamicTableEntity(entity.RowKey, ""); if (entity.RowKey != "!info1") { new_entity["boardname"] = entity["boardname"]; CreatorConverter.CopyEntity(entity, CreatorConverter.Status.Creator, new_entity, CreatorConverter.Status.Editor); Warehouse.BoardListTable.Execute(TableOperation.Insert(new_entity)); } } }
public static void CreateLetterEntity(DynamicTableEntity entity, string creator, string words, Subtype subtype, string delta_flags, string board_id, string discussion_id) { CreatorConverter.FillEntity(entity, CreatorConverter.Status.Creator, creator); entity["subtype"] = new EntityProperty(subtype.ToString()); #if OLD string flags = SandFlags.Merge("", delta_flags); if (flags.Length > 0) { entity["flags"] = new EntityProperty(flags); } #else entity.OperateFlags(new FlagMergeOperation(delta_flags)); #endif fillWords(entity, words, board_id, discussion_id); // must be after flags modification so that encrypt flag is correct. }
public static void SetBoardFlags(string board_id, string delta_flags) { TableResult result = Warehouse.BoardListTable.Execute(TableOperation.Retrieve(board_id, EMPTY_ROW_KEY)); DynamicTableEntity entity = (DynamicTableEntity)result.Result; int ec = RevisionStore.IncreaseEditCount(entity); string partition_key = SandId.CombineId(Warehouse.BoardListTable.Name, board_id); RevisionStore.CreateHistory(entity, partition_key, ec, "flags2"); CreatorConverter.FillEntity(entity, CreatorConverter.Status.Editor, null); entity.OperateFlags(new FlagMergeOperation(delta_flags)); Warehouse.BoardListTable.Execute(TableOperation.Replace(entity)); // Throws StorageException ((412) Precondition Failed) if the entity is modified in between. Warehouse.BoardSettingPond.Notify(board_id); }
public static void CopyLetterRevision(DynamicTableEntity letter_entity, DynamicTableEntity revision_entity, int version) { CreatorConverter.CopyEntity( letter_entity, version == 0 ? CreatorConverter.Status.Creator : CreatorConverter.Status.LastEditor, revision_entity, CreatorConverter.Status.Editor); EntityProperty ep; string words = letter_entity["abstract"].StringValue; if (letter_entity.Properties.TryGetValue("words", out ep)) { words += ep.StringValue; } revision_entity["words"] = new EntityProperty(words); revision_entity["flags2"] = new EntityProperty(letter_entity.GetString("flags2", null)); }
public static string /*selection id*/ CreateSelection(string selection_name) { int next_id = NextIdStore.Next(Warehouse.SelectionListTable, null); string selection_id = SandId.MakeSelectionId(next_id); DynamicTableEntity entity = new DynamicTableEntity(selection_id, EMPTY_ROW_KEY); entity["selectionname"] = new EntityProperty(selection_name); entity["boardlist"] = new EntityProperty(string.Empty); CreatorConverter.FillEntity(entity, CreatorConverter.Status.Editor, null); Warehouse.SelectionListTable.Execute(TableOperation.Insert(entity)); //don't work for child action. //HttpResponse.RemoveOutputCacheItem("/boardlist"); Warehouse.BsMapPond.Notify(); return(selection_id); }
public static void CreateHistory(DynamicTableEntity src_entity, string partition_key, int version, params string[] properties_to_copy) { DynamicTableEntity dst_entity = new DynamicTableEntity(partition_key, SandId.MakeRevisionId(version)); CreatorConverter.CopyEntity(src_entity, CreatorConverter.Status.Editor, dst_entity, CreatorConverter.Status.Editor); foreach (string property_name in properties_to_copy) { EntityProperty ep; if (src_entity.Properties.TryGetValue(property_name, out ep)) { dst_entity[property_name] = ep /*src_entity[property_name]*/; } } Warehouse.HistoryTable.Execute(TableOperation.Insert(dst_entity)); }
public static int CheckDeleteRight(string board_id, string discussion_id, string letter_id, DynamicTableEntity entity, bool is_undelete) { bool is_discussion = letter_id == SandId.HEADING_LETTER_ID; string cmd_name = is_undelete ? "復原" : "刪除"; int user_level = userLevel(board_id, discussion_id, entity, is_discussion, is_undelete); int required_level = is_discussion ? 50 : (is_undelete ? 30 : 20); if (user_level < required_level) { Util.ThrowUnauthorizedException("沒有" + cmd_name + (is_discussion ? "討論串" : "留言") + "權限。需要權限等級" + required_level + ",您的權限等級為" + user_level + "。"); } return(user_level); #if OLD if (is_undelete || is_discussion) { if (!IsBoardOwner(board_id)) { Util.ThrowUnauthorizedException("沒有" + cmd_name + "權限。只有板主可以" + cmd_name + (is_discussion ? "討論串" : "留言") + "。"); } } else { if (!CreatorConverter.IsCurrentUserCreator(entity) && !DiscussionLoadStore.IsCurrentUserDiscussionCreator(board_id, discussion_id) && !IsBoardOwner(board_id)) { // Util.ThrowUnauthorizedException("沒有刪除權限。只有板主、串主、或原作者可以刪除留言。"); } } #endif }