Exemple #1
0
 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);
     }
 }
Exemple #2
0
        public DiscussionSummary(string board_id, string discussion_id)
        {
            this.BoardId      = board_id;
            this.DiscussionId = discussion_id;

            DiscussionLoadStore.GetFirstLetters(board_id, discussion_id, 2, entity => AddLetter(entity));
            DiscussionLoadStore.GetLastLetters(board_id, discussion_id, REPLY_COUNT, entity => AddLetter(entity));                      // may duplicate with first 2.
        }
Exemple #3
0
        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("沒有編輯權限。只有副板主以上、串主、或原作者可以編輯。");
            }
        }
Exemple #4
0
        public static string /*discussion id*/ CreateDiscussion(string board_id, string creator, string words, string heading,
                                                                string delta_flags, HttpFileCollectionBase files, string heading_delta_flags)
        {
            string partition_key = board_id;

            int    next_id       = NextIdStore.Next(Warehouse.DiscussionListTable, partition_key);
            string discussion_id = SandId.MakeDiscussionId(next_id);

            DynamicTableEntity entity = new DynamicTableEntity(partition_key, discussion_id);

            entity["heading"] = new EntityProperty(/*DiscussionLoadRoll.RemoveForeMeta*/ (heading));
            entity.OperateFlags(new FlagMergeOperation(heading_delta_flags));

            Warehouse.DiscussionListTable.Execute(TableOperation.Insert(entity));

            DiscussionLoadStore.CreateSkeleton(board_id, discussion_id);
            DiscussionLoadStore.CreateLetter(board_id, discussion_id, creator, heading, Subtype.h, heading_delta_flags, null);
            DiscussionLoadStore.CreateLetter(board_id, discussion_id, creator, words, Subtype.s, delta_flags, files);

            Warehouse.DiscussionListPond.Get(board_id).AddDiscussion(entity);

            return(discussion_id);
        }
Exemple #5
0
        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
        }