示例#1
0
        /// <summary>
        /// 创建专题
        /// </summary>
        /// <param name="userId">当前操作人</param>
        /// <param name="group"><see cref="TopicEntity"/></param>
        /// <param name="logoFile">专题标识图</param>
        /// <returns>创建成功返回true,失败返回false</returns>
        public bool Create(long userId, TopicEntity group)
        {
            //设计要点
            //1、使用AuditService设置审核状态;
            //2、需要触发的事件参见《设计说明书-日志》
            //3、单独调用标签服务设置标签
            //4、使用 IdGenerator.Next() 生成TopicId
            EventBus <TopicEntity> .Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            auditService.ChangeAuditStatusForCreate(userId, group);
            long id = 0;

            long.TryParse(groupRepository.Insert(group).ToString(), out id);

            if (id > 0)
            {
                EventBus <TopicEntity> .Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <TopicEntity, AuditEventArgs> .Instance().OnAfter(group, new AuditEventArgs(null, group.AuditStatus));

                //用户的创建专题数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedTopicCount(), 1);
            }
            return(id > 0);
        }
示例#2
0
        /// <summary>
        /// 批准/不批准专题
        /// </summary>
        /// <param name="groupId">待被更新的专题Id</param>
        /// <param name="isApproved">是否通过审核</param>
        public void Approve(long groupId, bool isApproved)
        {
            //设计要点
            //1、审核状态未变化不用进行任何操作;
            //2、需要触发的事件参见《设计说明书-专题》;

            TopicEntity group = groupRepository.Get(groupId);

            AuditStatus newAuditStatus = isApproved ? AuditStatus.Success : AuditStatus.Fail;

            if (group.AuditStatus == newAuditStatus)
            {
                return;
            }

            AuditStatus oldAuditStatus = group.AuditStatus;

            group.AuditStatus = newAuditStatus;
            groupRepository.Update(group);

            string operationType = isApproved ? EventOperationType.Instance().Approved() : EventOperationType.Instance().Disapproved();

            EventBus <TopicEntity> .Instance().OnAfter(group, new CommonEventArgs(operationType));

            EventBus <TopicEntity, AuditEventArgs> .Instance().OnAfter(group, new AuditEventArgs(oldAuditStatus, newAuditStatus));
        }
示例#3
0
        /// <summary>
        /// 是否具有设置群管理员的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public static bool Topic_SetManager(this Authorizer authorizer, TopicEntity group)
        {
            if (group == null)
            {
                return(false);
            }

            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            //群主
            if (group.UserId == currentUser.UserId)
            {
                return(true);
            }

            if (authorizer.IsAdministrator(TopicConfig.Instance().ApplicationId))
            {
                return(true);
            }

            return(false);
        }
示例#4
0
        /// <summary>
        /// 是否拥有删除专题成员的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="group"></param>
        /// <param name="userId">被删除的用户Id</param>
        /// <returns>是否拥有删除专题成员的权限</returns>
        public static bool Topic_DeleteMember(this Authorizer authorizer, TopicEntity group, long userId)
        {
            if (group == null)
            {
                return(false);
            }

            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            //群主
            if (group.UserId == currentUser.UserId)
            {
                return(true);
            }

            if (authorizer.IsAdministrator(TopicConfig.Instance().ApplicationId))
            {
                return(true);
            }
            TopicService groupService = new TopicService();

            //群管理员
            if (groupService.IsManager(group.TopicId, currentUser.UserId) && !groupService.IsManager(group.TopicId, userId))
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// 获取用户当前选中的皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、专题Id)</param>
        /// <returns></returns>
        public string GetThemeAppearance(long ownerId)
        {
            var         topicService = new TopicService();
            TopicEntity topic        = topicService.Get(ownerId);

            if (topic == null)
            {
                return(string.Empty);
            }
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfExtension.TopicSpace);

            if (pa != null && !pa.EnableThemes)
            {
                return(pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey);
            }

            if (topic.IsUseCustomStyle)
            {
                return("Default,Default");
            }
            else if (!string.IsNullOrEmpty(topic.ThemeAppearance))
            {
                var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, topic.ThemeAppearance);
                if (appearance != null)
                {
                    return(topic.ThemeAppearance);
                }
            }

            if (pa != null)
            {
                return(pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey);
            }
            return(string.Empty);
        }
示例#6
0
        /// <summary>
        /// TopicEntity转换成<see cref="Lucene.Net.Documents.Document"/>
        /// </summary>
        /// <param name="TopicEntity">专题实体</param>
        /// <returns>Lucene.Net.Documents.Document</returns>
        public static Document Convert(TopicEntity group)
        {
            Document doc = new Document();

            //索引专题基本信息
            doc.Add(new Field(TopicIndexDocument.TopicId, group.TopicId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.TopicName, group.TopicName, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field(TopicIndexDocument.Description, group.Description, Field.Store.NO, Field.Index.ANALYZED));
            doc.Add(new Field(TopicIndexDocument.IsPublic, group.IsPublic == true ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.AreaCode, group.AreaCode, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.UserId, group.UserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.AuditStatus, ((int)group.AuditStatus).ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.DateCreated, DateTools.DateToString(group.DateCreated, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.MemberCount, group.MemberCount.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.GrowthValue, group.GrowthValue.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            if (group.Category != null)
            {
                doc.Add(new Field(TopicIndexDocument.CategoryName, group.Category.CategoryName, Field.Store.YES, Field.Index.ANALYZED));
                doc.Add(new Field(TopicIndexDocument.CategoryId, group.Category.CategoryId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            }

            //索引专题tag
            foreach (string tagName in group.TagNames)
            {
                doc.Add(new Field(TopicIndexDocument.Tag, tagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED));
            }

            return(doc);
        }
        /// <summary>
        /// TopicEntity转换成<see cref="Lucene.Net.Documents.Document"/>
        /// </summary>
        /// <param name="TopicEntity">专题实体</param>
        /// <returns>Lucene.Net.Documents.Document</returns>
        public static Document Convert(TopicEntity group)
        {
            Document doc = new Document();

            //索引专题基本信息
            doc.Add(new Field(TopicIndexDocument.TopicId, group.TopicId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.TopicName, group.TopicName, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field(TopicIndexDocument.Description, group.Description, Field.Store.NO, Field.Index.ANALYZED));
            doc.Add(new Field(TopicIndexDocument.IsPublic, group.IsPublic==true ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.AreaCode, group.AreaCode, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.UserId, group.UserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.AuditStatus, ((int)group.AuditStatus).ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.DateCreated, DateTools.DateToString(group.DateCreated, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.MemberCount,group.MemberCount.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TopicIndexDocument.GrowthValue, group.GrowthValue.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            if (group.Category != null)
            {
                doc.Add(new Field(TopicIndexDocument.CategoryName, group.Category.CategoryName, Field.Store.YES, Field.Index.ANALYZED));
                doc.Add(new Field(TopicIndexDocument.CategoryId, group.Category.CategoryId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));

            }

            //索引专题tag
            foreach (string tagName in group.TagNames)
            {
                doc.Add(new Field(TopicIndexDocument.Tag, tagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED));
            }

            return doc;
        }
示例#8
0
        /// <summary>
        /// 更换群主
        /// </summary>
        /// <param name="groupId">专题Id</param>
        /// <param name="newOwnerUserId">新群主UserId</param>
        public void ChangeTopicOwner(long groupId, long newOwnerUserId)
        {
            //更换群主后,原群主转换成专题成员,如果新群主是专题成员则从成员中移除
            TopicEntity group          = groupRepository.Get(groupId);
            long        oldOwnerUserId = group.UserId;

            group.UserId = newOwnerUserId;
            groupRepository.ChangeTopicOwner(groupId, newOwnerUserId);

            //原群主的专题数-1,加入专题数+1
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().CreatedTopicCount(), -1);
            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().JoinedTopicCount(), 1);

            //原群主转换成专题成员
            TopicMember TopicMember = TopicMember.New();

            TopicMember.TopicId = groupId;
            TopicMember.UserId  = oldOwnerUserId;
            TopicMemberRepository.Insert(TopicMember);

            //新群主的专题数+1,加入专题数-1
            ownerDataService.Change(newOwnerUserId, OwnerDataKeys.Instance().CreatedTopicCount(), 1);

            //如果新群主是专题成员则从成员中移除
            if (IsMember(groupId, newOwnerUserId))
            {
                DeleteTopicMember(groupId, newOwnerUserId);
            }
        }
示例#9
0
        /// <summary>
        /// 更新专题公告
        /// </summary>
        /// <param name="groupId">专题Id</param>
        /// <param name="announcement">公告内容</param>
        public void UpdateAnnouncement(long groupId, string announcement)
        {
            TopicEntity group = groupRepository.Get(groupId);

            if (group == null)
            {
                return;
            }
            group.Announcement = announcement;
            groupRepository.Update(group);
        }
示例#10
0
        /// <summary>
        /// 更新专题
        /// </summary>
        /// <param name="userId">当前操作人</param>
        /// <param name="group"><see cref="TopicEntity"/></param>
        /// <param name="logoFile">专题标识图</param>
        public void Update(long userId, TopicEntity group)
        {
            EventBus <TopicEntity> .Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Update()));

            auditService.ChangeAuditStatusForUpdate(userId, group);
            groupRepository.Update(group);



            EventBus <TopicEntity> .Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Update()));
        }
示例#11
0
 /// <summary>
 /// 上传Logo
 /// </summary>
 /// <param name="groupId">专题Id</param>
 /// <param name="stream">Logo文件流</param>
 public void UploadLogo(long groupId, Stream stream)
 {
     //按现在设计应该用LogoService,但是感觉LogoService没什么必要(重构Logo/Image直连后再定)
     if (stream != null)
     {
         TopicEntity group       = this.Get(groupId);
         LogoService logoService = new LogoService(TenantTypeIds.Instance().Topic());
         group.Logo = logoService.UploadLogo(groupId, stream);
         groupRepository.Update(group);
         EventBus <TopicEntity> .Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Update()));
     }
 }
        /// <summary>
        /// 更新皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、专题Id)</param>
        /// <param name="isUseCustomStyle">是否使用自定义皮肤</param>
        /// <param name="themeAppearance">themeKey与appearanceKey用逗号关联</param>
        public void ChangeThemeAppearance(long ownerId, bool isUseCustomStyle, string themeAppearance)
        {
            var         topicService = new TopicService();
            TopicEntity topic        = topicService.Get(ownerId);

            if (topic == null)
            {
                throw new ExceptionFacade("找不到专题");
            }

            new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfExtension.TopicSpace, topic.IsUseCustomStyle ? string.Empty : topic.ThemeAppearance, isUseCustomStyle ? string.Empty : themeAppearance);
            new TopicService().ChangeThemeAppearance(ownerId, isUseCustomStyle, themeAppearance);
        }
示例#13
0
        /// <summary>
        /// 删除Logo
        /// </summary>
        /// <param name="recommendId">专题Id</param>
        public void DeleteLogo(long groupId)
        {
            LogoService logoService = new LogoService(TenantTypeIds.Instance().Topic());

            logoService.DeleteLogo(groupId);
            TopicEntity group = Get(groupId);

            if (group == null)
            {
                return;
            }
            group.Logo = string.Empty;
            groupRepository.Update(group);
        }
示例#14
0
        /// <summary>
        /// 获取专题所有成员用户Id集合(用于推送动态)
        /// </summary>
        /// <param name="groupId">专题Id</param>
        /// <returns></returns>
        public IEnumerable <long> GetUserIdsOfTopic(long groupId)
        {
            TopicEntity group = groupRepository.Get(groupId);

            if (group == null)
            {
                return(new List <long>());
            }
            //不必缓存
            IEnumerable <long> userIds = TopicMemberRepository.GetUserIdsOfTopic(groupId);
            var list = userIds.ToList();

            list.Add(group.UserId);
            return(list);
        }
示例#15
0
        /// <summary>
        /// 专题实体
        /// </summary>
        public static TopicEntity New()
        {
            TopicEntity topic = new TopicEntity()
            {
                TopicName       = string.Empty,
                Description     = string.Empty,
                Logo            = string.Empty,
                ThemeAppearance = string.Empty,
                DateCreated     = DateTime.UtcNow,
                IP           = WebUtility.GetIP(),
                Announcement = string.Empty,
                MemberCount  = 1
            };

            return(topic);
        }
        /// <summary>
        /// 专题实体
        /// </summary>
        public static TopicEntity New()
        {
            TopicEntity topic = new TopicEntity()
            {
                TopicName = string.Empty,
                Description = string.Empty,
                Logo = string.Empty,
                ThemeAppearance = string.Empty,
                DateCreated = DateTime.UtcNow,
                IP = WebUtility.GetIP(),
                Announcement = string.Empty,
                MemberCount = 1


            };
            return topic;
        }
        /// <summary>
        /// 是否具有设置群管理员的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public static bool Topic_SetManager(this Authorizer authorizer, TopicEntity group)
        {
            if (group == null)
                return false;

            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return false;

            //群主
            if (group.UserId == currentUser.UserId)
                return true;

            if (authorizer.IsAdministrator(TopicConfig.Instance().ApplicationId))
                return true;

            return false;
        }
示例#18
0
 /// <summary>
 /// 将数据库中的信息转换成EditModel实体
 /// </summary>
 /// <param name="groupEntity"></param>
 /// <returns></returns>
 public static TopicEditModel AsEditModel(this TopicEntity groupEntity)
 {
     return(new TopicEditModel
     {
         TopicId = groupEntity.TopicId,
         IsPublic = groupEntity.IsPublic,
         TopicName = groupEntity.TopicName,
         TopicKey = groupEntity.TopicKey,
         Logo = groupEntity.Logo,
         Description = Formatter.FormatMultiLinePlainTextForEdit(groupEntity.Description, true),
         AreaCode = groupEntity.AreaCode,
         JoinWay = groupEntity.JoinWay,
         EnableMemberInvite = groupEntity.EnableMemberInvite,
         CategoryId = groupEntity.Category == null ? 0 : groupEntity.Category.CategoryId,
         Question = groupEntity.Question,
         Answer = groupEntity.Answer
     });
 }
示例#19
0
        /// <summary>
        /// 转换成groupEntity类型
        /// </summary>
        /// <returns></returns>
        public TopicEntity AsTopicEntity()
        {
            CategoryService categoryService = new CategoryService();
            TopicEntity     topicEntity     = null;

            //创建专题
            if (this.TopicId == 0)
            {
                topicEntity             = TopicEntity.New();
                topicEntity.UserId      = UserContext.CurrentUser.UserId;
                topicEntity.DateCreated = DateTime.UtcNow;
                topicEntity.TopicKey    = this.TopicKey;
            }
            //编辑专题
            else
            {
                TopicService topicService = new TopicService();
                topicEntity = topicService.Get(this.TopicId);
            }
            topicEntity.IsPublic  = this.IsPublic;
            topicEntity.TopicName = this.TopicName;
            if (Logo != null)
            {
                topicEntity.Logo = this.Logo;
            }
            topicEntity.Description        = Formatter.FormatMultiLinePlainTextForStorage(this.Description == null ? string.Empty : this.Description, true);
            topicEntity.AreaCode           = this.AreaCode ?? string.Empty;
            topicEntity.JoinWay            = this.JoinWay;
            topicEntity.EnableMemberInvite = this.EnableMemberInvite;
            //topickey 去掉空格,变为小写字母
            topicEntity.TopicKey = this.TopicKey.ToLower().Replace(" ", "-");

            if (JoinWay == TopicJoinWay.ByQuestion)
            {
                topicEntity.Question = this.Question;
                topicEntity.Answer   = this.Answer;
            }
            return(topicEntity);
        }
示例#20
0
        /// <summary>
        /// 是否具有浏览专题的权限
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        public static bool Topic_View(this Authorizer authorizer, TopicEntity topic)
        {
            if (topic == null)
            {
                return(false);
            }

            if (topic.AuditStatus == AuditStatus.Success)
            {
                if (topic.IsPublic)
                {
                    return(true);
                }

                if (UserContext.CurrentUser == null)
                {
                    return(false);
                }

                if (authorizer.Topic_Manage(topic))
                {
                    return(true);
                }

                TopicService groupService = new TopicService();
                if (groupService.IsMember(topic.TopicId, UserContext.CurrentUser.UserId))
                {
                    return(true);
                }
            }

            if (authorizer.IsAdministrator(TopicConfig.Instance().ApplicationId))
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// 创建专题
        /// </summary>
        /// <param name="userId">当前操作人</param>
        /// <param name="group"><see cref="TopicEntity"/></param>
        /// <param name="logoFile">专题标识图</param>
        /// <returns>创建成功返回true,失败返回false</returns>
        public bool Create(long userId, TopicEntity group)
        {
            //设计要点
            //1、使用AuditService设置审核状态;
            //2、需要触发的事件参见《设计说明书-日志》     
            //3、单独调用标签服务设置标签
            //4、使用 IdGenerator.Next() 生成TopicId
            EventBus<TopicEntity>.Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Create()));
            //设置审核状态
            auditService.ChangeAuditStatusForCreate(userId, group);
            long id = 0;
            long.TryParse(topicRepository.Insert(group).ToString(), out id);

            if (id > 0)
            {
                EventBus<TopicEntity>.Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Create()));
                EventBus<TopicEntity, AuditEventArgs>.Instance().OnAfter(group, new AuditEventArgs(null, group.AuditStatus));
                //用户的创建专题数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedTopicCount(), 1);
            }
            return id > 0;
        }
示例#22
0
        /// <summary>
        /// 删除专题
        /// </summary>
        /// <param name="groupId">专题Id</param>
        public void Delete(long groupId)
        {
            //设计要点
            //1、需要删除:专题成员、专题申请、Logo;
            TopicEntity group = groupRepository.Get(groupId);

            if (group == null)
            {
                return;
            }

            CategoryService categoryService = new CategoryService();

            categoryService.ClearCategoriesFromItem(groupId, null, TenantTypeIds.Instance().Topic());


            EventBus <TopicEntity> .Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Delete()));

            int affectCount = groupRepository.Delete(group);

            if (affectCount > 0)
            {
                //删除访客记录
                new VisitService(TenantTypeIds.Instance().Topic()).CleanByToObjectId(groupId);
                //用户的创建专题数-1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedTopicCount(), -1);
                //删除Logo
                LogoService logoService = new LogoService(TenantTypeIds.Instance().Topic());
                logoService.DeleteLogo(groupId);
                //删除专题下的成员
                DeleteMembersByTopicId(groupId);
                EventBus <TopicEntity> .Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Delete()));

                EventBus <TopicEntity, AuditEventArgs> .Instance().OnAfter(group, new AuditEventArgs(group.AuditStatus, null));
            }
        }
示例#23
0
        /// <summary>
        /// 发送加入专题邀请
        /// </summary>
        /// <param name="group"><see cref="TopicEntity"/></param>
        /// <param name="sender">发送人</param>
        /// <param name="userIds">邀请接收人</param>
        /// <param name="remark">附言</param>
        public void SendInvitations(TopicEntity group, IUser sender, string remark, IEnumerable <long> userIds)
        {
            //调用InvitationService的发送请求的方法
            InvitationService invitationService = new InvitationService();

            foreach (var userId in userIds)
            {
                if (!IsMember(group.TopicId, userId))
                {
                    Invitation invitation = Invitation.New();
                    invitation.ApplicationId      = TopicConfig.Instance().ApplicationId;
                    invitation.InvitationTypeKey  = InvitationTypeKeys.Instance().InviteJoinTopic();
                    invitation.UserId             = userId;
                    invitation.SenderUserId       = sender.UserId;
                    invitation.Sender             = sender.DisplayName;
                    invitation.SenderUrl          = SiteUrls.Instance().SpaceHome(sender.UserId);
                    invitation.RelativeObjectId   = group.TopicId;
                    invitation.RelativeObjectName = group.TopicName;
                    invitation.RelativeObjectUrl  = SiteUrls.Instance().TopicHome(group.TopicKey);
                    invitation.Remark             = remark;
                    invitationService.Create(invitation);
                }
            }
        }
示例#24
0
        /// <summary>
        /// 检测用户在专题中属于什么角色
        /// </summary>
        /// <param name="groupId">专题Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns><see cref="TopicMemberRole"/></returns>
        private TopicMemberRole GetTopicMemberRole(long groupId, long userId)
        {
            //设计要点:
            //1、需要缓存,并维护缓存的即时性
            TopicMember member = TopicMemberRepository.GetMember(groupId, userId);

            if (member == null)
            {
                TopicEntity group = groupRepository.Get(groupId);
                if (group != null && group.UserId == userId)
                {
                    return(TopicMemberRole.Owner);
                }
                return(TopicMemberRole.None);
            }
            if (member.IsManager)
            {
                return(TopicMemberRole.Manager);
            }
            else
            {
                return(TopicMemberRole.Member);
            }
        }
示例#25
0
        /// <summary>
        /// 是否具有邀请好友加入专题的权限
        /// </summary>
        /// <param name="group"></param>
        /// <returns></returns>
        public static bool Topic_Invite(this Authorizer authorizer, TopicEntity group)
        {
            if (group == null)
            {
                return(false);
            }
            if (UserContext.CurrentUser == null)
            {
                return(false);
            }

            TopicService groupService = new TopicService();

            if (authorizer.Topic_Manage(group))
            {
                return(true);
            }
            if (group.EnableMemberInvite && groupService.IsMember(group.TopicId, UserContext.CurrentUser.UserId))
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// 是否具有邀请好友加入专题的权限
        /// </summary>
        /// <param name="group"></param>
        /// <returns></returns>
        public static bool Topic_Invite(this Authorizer authorizer, TopicEntity group)
        {
            if (group == null)
                return false;
            if (UserContext.CurrentUser == null)
                return false;

            TopicService groupService = new TopicService();
            if (authorizer.Topic_Manage(group))
                return true;
            if (group.EnableMemberInvite && groupService.IsMember(group.TopicId, UserContext.CurrentUser.UserId))
                return true;

            return false;
        }
        /// <summary>
        /// 是否具有管理Topic的权限
        /// </summary>
        /// <param name="Topic"></param>
        /// <returns></returns>
        public static bool Topic_Manage(this Authorizer authorizer, TopicEntity group)
        {


            if (group == null)
                return false;

            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return false;

            if (authorizer.IsAdministrator(TopicConfig.Instance().ApplicationId))
                return true;

            if (currentUser.IsContentAdministrator())
                return true;

            //群主
            if (group.UserId == currentUser.UserId)
                return true;

            TopicService groupService = new TopicService();
            //群管理员
            if (groupService.IsManager(group.TopicId, currentUser.UserId))
                return true;

            return false;
        }
 /// <summary>
 /// 发送加入专题邀请
 /// </summary>
 /// <param name="group"><see cref="TopicEntity"/></param>
 /// <param name="sender">发送人</param>
 /// <param name="userIds">邀请接收人</param>
 /// <param name="remark">附言</param>
 public void SendInvitations(TopicEntity group, IUser sender, string remark, IEnumerable<long> userIds)
 {
     //调用InvitationService的发送请求的方法
     InvitationService invitationService = new InvitationService();
     foreach (var userId in userIds)
     {
         if (!IsMember(group.TopicId, userId))
         {
             Invitation invitation = Invitation.New();
             invitation.ApplicationId = TopicConfig.Instance().ApplicationId;
             invitation.InvitationTypeKey = InvitationTypeKeys.Instance().InviteJoinTopic();
             invitation.UserId = userId;
             invitation.SenderUserId = sender.UserId;
             invitation.Sender = sender.DisplayName;
             invitation.SenderUrl = SiteUrls.Instance().SpaceHome(sender.UserId);
             invitation.RelativeObjectId = group.TopicId;
             invitation.RelativeObjectName = group.TopicName;
             invitation.RelativeObjectUrl = SiteUrls.Instance().TopicHome(group.TopicKey);
             invitation.Remark = remark;
             invitationService.Create(invitation);
         }
     }
 }
 /// <summary>
 /// 添加索引
 /// </summary>
 /// <param name="TopicEntity">待添加的专题</param>
 public void Insert(TopicEntity group)
 {
     Insert(new TopicEntity[] { group });
 }
示例#30
0
        /// <summary>
        /// 更新索引
        /// </summary>
        /// <param name="TopicEntity">待更新的专题</param>
        public void Update(TopicEntity group)
        {
            Document doc = TopicIndexDocument.Convert(group);

            searchEngine.Update(doc, group.TopicId.ToString(), TopicIndexDocument.TopicId);
        }
示例#31
0
 /// <summary>
 /// 添加索引
 /// </summary>
 /// <param name="TopicEntity">待添加的专题</param>
 public void Insert(TopicEntity group)
 {
     Insert(new TopicEntity[] { group });
 }
 /// <summary>
 /// 更新索引
 /// </summary>
 /// <param name="TopicEntity">待更新的专题</param>
 public void Update(TopicEntity group)
 {
     Document doc = TopicIndexDocument.Convert(group);
     searchEngine.Update(doc, group.TopicId.ToString(), TopicIndexDocument.TopicId);
 }
        private void AuthorizeCore(AuthorizationContext filterContext)
        {
            string spaceKey = UserContext.CurrentSpaceKey(filterContext);

            if (string.IsNullOrEmpty(spaceKey))
            {
                throw new ExceptionFacade("spaceKey为null");
            }
            TopicService TopicService = new TopicService();
            TopicEntity  Topic        = TopicService.Get(spaceKey);

            if (Topic == null)
            {
                throw new ExceptionFacade("找不到当前专题");
            }

            IUser currentUser = UserContext.CurrentUser;



            //判断访问专题权限
            if (!DIContainer.Resolve <Authorizer>().Topic_View(Topic))
            {
                if (currentUser == null)
                {
                    filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                }
                else
                {
                    if (Topic.AuditStatus != AuditStatus.Success)
                    {
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                        {
                            Title             = "无权访问专题!",
                            Body              = "该专题还没有通过审核,所以不能访问!",
                            StatusMessageType = StatusMessageType.Hint
                        }, filterContext.HttpContext.Request.RawUrl) /* 跳向无权访问页 */);
                    }
                    else
                    {
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                        {
                            Title             = "无权访问专题!",
                            Body              = "你没有访问该专题的权限",
                            StatusMessageType = StatusMessageType.Hint
                        }, filterContext.HttpContext.Request.RawUrl) /* 跳向无权访问页 */);
                    }
                }
                return;
            }

            //判断该用户是否有访问该专题管理页面的权限
            if (!RequireManager)
            {
                return;
            }
            //匿名用户要求先登录跳转
            if (currentUser == null)
            {
                filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                return;
            }

            if (DIContainer.Resolve <Authorizer>().Topic_Manage(Topic))
            {
                return;
            }
            filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
            {
                Title             = "无权访问",
                Body              = "您无权访问此页面,只有群主或管理员才能访问",
                StatusMessageType = StatusMessageType.Hint
            }) /* 跳向无权访问页 */);
        }
        /// <summary>
        /// 是否具有浏览专题的权限
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        public static bool Topic_View(this Authorizer authorizer, TopicEntity topic)
        {
            if (topic == null)
                return false;

            if (topic.AuditStatus == AuditStatus.Success)
            {
                if (topic.IsPublic)
                    return true;

                if (UserContext.CurrentUser == null)
                    return false;

                if (authorizer.Topic_Manage(topic))
                    return true;

                TopicService groupService = new TopicService();
                if (groupService.IsMember(topic.TopicId, UserContext.CurrentUser.UserId))
                    return true;
            }

            if (authorizer.IsAdministrator(TopicConfig.Instance().ApplicationId))
                return true;

            return false;
        }
        /// <summary>
        /// 更新专题
        /// </summary>
        /// <param name="userId">当前操作人</param>
        /// <param name="topic"><see cref="TopicEntity"/></param>
        /// <param name="logoFile">专题标识图</param>
        public void Update(long userId, TopicEntity topic)
        {
            EventBus<TopicEntity>.Instance().OnBefore(topic, new CommonEventArgs(EventOperationType.Instance().Update()));
            auditService.ChangeAuditStatusForUpdate(userId, topic);
            topicRepository.Update(topic);



            EventBus<TopicEntity>.Instance().OnAfter(topic, new CommonEventArgs(EventOperationType.Instance().Update()));
        }
        void AutoMaintainBarSectionModule_After(TopicEntity sender, CommonEventArgs eventArgs)
        {
            BarSectionService barSectionService = new BarSectionService();
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {

                BarSection barSection = BarSection.New();

                barSection.TenantTypeId = TenantTypeIds.Instance().Topic();
                barSection.SectionId = sender.TopicId;
                barSection.OwnerId = sender.TopicId;
                barSection.UserId = sender.UserId;
                barSection.Name = sender.TopicName;
                barSection.IsEnabled = true;
                barSection.LogoImage = sender.Logo;
                barSection.ThreadCategoryStatus = ThreadCategoryStatus.NotForceEnabled;
                barSectionService.Create(barSection, sender.UserId, null, null);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Update())
            {
                BarSection barSection = barSectionService.Get(sender.TopicId);
                barSection.UserId = sender.UserId;
                barSection.Name = sender.TopicName;
                barSection.LogoImage = sender.Logo;

                IList<long> managerIds = null;
                if (barSection.SectionManagers != null)
                {
                    managerIds = barSection.SectionManagers.Select(n => n.UserId).ToList();
                }
                barSectionService.Update(barSection, sender.UserId, managerIds, null);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                BarSection barSection = barSectionService.Get(sender.TopicId);
                barSection.AuditStatus = sender.AuditStatus;
                IList<long> managerIds = null;
                if (barSection.SectionManagers != null)
                {
                    managerIds = barSection.SectionManagers.Select(n => n.UserId).ToList();
                }
                barSectionService.Update(barSection, sender.UserId, managerIds, null);
            }
            else
            {
                barSectionService.Delete(sender.TopicId);
            }
        }
        /// <summary>
        /// 专题增量索引
        /// </summary>
        private void TopicEntity_After(TopicEntity group, CommonEventArgs eventArgs)
        {
            if (group == null)
            {
                return;
            }

            if (groupSearcher == null)
            {
                groupSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE);
            }

            //添加索引
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                groupSearcher.Insert(group);
            }

            //删除索引
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                groupSearcher.Delete(group.TopicId);
            }

            //更新索引
            if (eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                groupSearcher.Update(group);
            }
        }