/// <summary> /// GroupEntity转换成<see cref="Lucene.Net.Documents.Document"/> /// </summary> /// <param name="GroupEntity">群组实体</param> /// <returns>Lucene.Net.Documents.Document</returns> public static Document Convert(GroupEntity group) { Document doc = new Document(); //索引群组基本信息 doc.Add(new Field(GroupIndexDocument.GroupId, group.GroupId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(GroupIndexDocument.GroupName, group.GroupName, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(GroupIndexDocument.Description, group.Description, Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field(GroupIndexDocument.IsPublic, group.IsPublic==true ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(GroupIndexDocument.AreaCode, group.AreaCode, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(GroupIndexDocument.UserId, group.UserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(GroupIndexDocument.AuditStatus, ((int)group.AuditStatus).ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(GroupIndexDocument.DateCreated, DateTools.DateToString(group.DateCreated, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(GroupIndexDocument.MemberCount,group.MemberCount.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(GroupIndexDocument.GrowthValue, group.GrowthValue.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); if (group.Category != null) { doc.Add(new Field(GroupIndexDocument.CategoryName, group.Category.CategoryName, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(GroupIndexDocument.CategoryId, group.Category.CategoryId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); } //索引群组tag foreach (string tagName in group.TagNames) { doc.Add(new Field(GroupIndexDocument.Tag, tagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } return doc; }
/// <summary> /// 删除Logo /// </summary> /// <param name="recommendId">群组Id</param> public void DeleteLogo(long groupId) { LogoService logoService = new LogoService(TenantTypeIds.Instance().Group()); logoService.DeleteLogo(groupId); GroupEntity group = Get(groupId); if (group == null) { return; } group.Logo = string.Empty; groupRepository.Update(group); }
/// <summary> /// 获取群组所有成员用户Id集合(用于推送动态) /// </summary> /// <param name="groupId">群组Id</param> /// <returns></returns> public IEnumerable <long> GetUserIdsOfGroup(long groupId) { GroupEntity group = groupRepository.Get(groupId); if (group == null) { return(new List <long>()); } //不必缓存 IEnumerable <long> userIds = groupMemberRepository.GetUserIdsOfGroup(groupId); var list = userIds.ToList(); list.Add(group.UserId); return(list); }
/// <summary> /// 贴吧所在呈现区域拥有者自动创建贴吧事件 /// </summary> /// <param name="sender">群组实体</param> /// <param name="eventArgs">事件参数</param> void AutoMaintainBarSectionModule_After(GroupEntity sender, CommonEventArgs eventArgs) { BarSectionService barSectionService = new BarSectionService(); if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { BarSection barSection = BarSection.New(); barSection.TenantTypeId = TenantTypeIds.Instance().Group(); barSection.SectionId = sender.GroupId; barSection.OwnerId = sender.GroupId; barSection.UserId = sender.UserId; barSection.Name = sender.GroupName; 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.GroupId); barSection.UserId = sender.UserId; barSection.Name = sender.GroupName; 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.GroupId); 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.GroupId); } }
/// <summary> /// 群组实体 /// </summary> public static GroupEntity New() { GroupEntity group = new GroupEntity() { GroupName = string.Empty, Description = string.Empty, Logo = string.Empty, ThemeAppearance = string.Empty, DateCreated = DateTime.UtcNow, IP = WebUtility.GetIP(), Announcement = string.Empty, MemberCount = 1 }; return(group); }
/// <summary> /// 将数据库中的信息转换成EditModel实体 /// </summary> /// <param name="groupEntity"></param> /// <returns></returns> public static GroupEditModel AsEditModel(this GroupEntity groupEntity) { return(new GroupEditModel { GroupId = groupEntity.GroupId, IsPublic = groupEntity.IsPublic, GroupName = groupEntity.GroupName, GroupKey = groupEntity.GroupKey, 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 }); }
/// <summary> /// 是否具有管理Group的权限 /// </summary> /// <param name="Group"></param> /// <returns></returns> public static bool Group_Manage(this Authorizer authorizer, GroupEntity group) { if (group == null) { return(false); } IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return(false); } if (authorizer.IsAdministrator(GroupConfig.Instance().ApplicationId)) { return(true); } if (currentUser.IsContentAdministrator()) { return(true); } //群主 if (group.UserId == currentUser.UserId) { return(true); } GroupService groupService = new GroupService(); //群管理员 if (groupService.IsManager(group.GroupId, currentUser.UserId)) { return(true); } return(false); }
/// <summary> /// 是否具有浏览群组的权限 /// </summary> /// <param name="group"></param> /// <returns></returns> public static bool Group_View(this Authorizer authorizer, GroupEntity group) { if (group == null) { return(false); } if (group.AuditStatus == AuditStatus.Success) { if (group.IsPublic) { return(true); } if (UserContext.CurrentUser == null) { return(false); } if (authorizer.Group_Manage(group)) { return(true); } GroupService groupService = new GroupService(); if (groupService.IsMember(group.GroupId, UserContext.CurrentUser.UserId)) { return(true); } } if (authorizer.IsAdministrator(GroupConfig.Instance().ApplicationId)) { return(true); } return(false); }
/// <summary> /// 创建群组 /// </summary> /// <param name="userId">当前操作人</param> /// <param name="group"><see cref="GroupEntity"/></param> /// <param name="logoFile">群组标识图</param> /// <returns>创建成功返回true,失败返回false</returns> public bool Create(long userId, GroupEntity group) { //设计要点 //1、使用AuditService设置审核状态; //2、需要触发的事件参见《设计说明书-日志》 //3、单独调用标签服务设置标签 //4、使用 IdGenerator.Next() 生成GroupId EventBus<GroupEntity>.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<GroupEntity>.Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus<GroupEntity, AuditEventArgs>.Instance().OnAfter(group, new AuditEventArgs(null, group.AuditStatus)); //用户的创建群组数+1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedGroupCount(), 1); } return id > 0; }
/// <summary> /// 转换成groupEntity类型 /// </summary> /// <returns></returns> public GroupEntity AsGroupEntity() { CategoryService categoryService = new CategoryService(); GroupEntity groupEntity = null; //创建群组 if (this.GroupId == 0) { groupEntity = GroupEntity.New(); groupEntity.UserId = UserContext.CurrentUser.UserId; groupEntity.DateCreated = DateTime.UtcNow; groupEntity.GroupKey = this.GroupKey; } //编辑群组 else { GroupService groupService = new GroupService(); groupEntity = groupService.Get(this.GroupId); } groupEntity.IsPublic = this.IsPublic; groupEntity.GroupName = this.GroupName; if (Logo != null) { groupEntity.Logo = this.Logo; } groupEntity.Description = Formatter.FormatMultiLinePlainTextForStorage(this.Description == null ? string.Empty : this.Description, true); groupEntity.AreaCode = this.AreaCode ?? string.Empty; groupEntity.JoinWay = this.JoinWay; groupEntity.EnableMemberInvite = this.EnableMemberInvite; groupEntity.IsDynamicPermission = this.IsDynamicPermission; if (JoinWay == JoinWay.ByQuestion) { groupEntity.Question = this.Question; groupEntity.Answer = this.Answer; } return(groupEntity); }
/// <summary> /// 删除群组 /// </summary> /// <param name="groupId">群组Id</param> public void Delete(long groupId) { //设计要点 //1、需要删除:群组成员、群组申请、Logo; GroupEntity group = groupRepository.Get(groupId); if (group == null) { return; } CategoryService categoryService = new CategoryService(); categoryService.ClearCategoriesFromItem(groupId, null, TenantTypeIds.Instance().Group()); EventBus <GroupEntity> .Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Delete())); int affectCount = groupRepository.Delete(group); if (affectCount > 0) { //删除访客记录 new VisitService(TenantTypeIds.Instance().Group()).CleanByToObjectId(groupId); //用户的创建群组数-1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedGroupCount(), -1); //删除Logo LogoService logoService = new LogoService(TenantTypeIds.Instance().Group()); logoService.DeleteLogo(groupId); //删除群组下的成员 DeleteMembersByGroupId(groupId); EventBus <GroupEntity> .Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Delete())); EventBus <GroupEntity, AuditEventArgs> .Instance().OnAfter(group, new AuditEventArgs(group.AuditStatus, null)); } }
/// <summary> /// 是否具有邀请好友加入群组的权限 /// </summary> /// <param name="group"></param> /// <returns></returns> public static bool Group_Invite(this Authorizer authorizer, GroupEntity group) { if (group == null) { return(false); } if (UserContext.CurrentUser == null) { return(false); } GroupService groupService = new GroupService(); if (authorizer.Group_Manage(group)) { return(true); } if (group.EnableMemberInvite && groupService.IsMember(group.GroupId, UserContext.CurrentUser.UserId)) { return(true); } return(false); }
/// <summary> /// 检测用户在群组中属于什么角色 /// </summary> /// <param name="groupId">群组Id</param> /// <param name="userId">用户Id</param> /// <returns><see cref="GroupMemberRole"/></returns> private GroupMemberRole GetGroupMemberRole(long groupId, long userId) { //设计要点: //1、需要缓存,并维护缓存的即时性 GroupMember member = groupMemberRepository.GetMember(groupId, userId); if (member == null) { GroupEntity group = groupRepository.Get(groupId); if (group != null && group.UserId == userId) { return(GroupMemberRole.Owner); } return(GroupMemberRole.None); } if (member.IsManager) { return(GroupMemberRole.Manager); } else { return(GroupMemberRole.Member); } }
/// <summary> /// 发送加入群组邀请 /// </summary> /// <param name="group"><see cref="GroupEntity"/></param> /// <param name="sender">发送人</param> /// <param name="userIds">邀请接收人</param> /// <param name="remark">附言</param> public void SendInvitations(GroupEntity group, IUser sender, string remark, IEnumerable <long> userIds) { //调用InvitationService的发送请求的方法 InvitationService invitationService = new InvitationService(); foreach (var userId in userIds) { if (!IsMember(group.GroupId, userId)) { Invitation invitation = Invitation.New(); invitation.ApplicationId = GroupConfig.Instance().ApplicationId; invitation.InvitationTypeKey = InvitationTypeKeys.Instance().InviteJoinGroup(); invitation.UserId = userId; invitation.SenderUserId = sender.UserId; invitation.Sender = sender.DisplayName; invitation.SenderUrl = SiteUrls.Instance().SpaceHome(sender.UserId); invitation.RelativeObjectId = group.GroupId; invitation.RelativeObjectName = group.GroupName; invitation.RelativeObjectUrl = SiteUrls.Instance().GroupHome(group.GroupKey); invitation.Remark = remark; invitationService.Create(invitation); } } }
/// <summary> /// 是否具有浏览群组的权限 /// </summary> /// <param name="group"></param> /// <returns></returns> public static bool Group_View(this Authorizer authorizer, GroupEntity group) { if (group == null) return false; if (group.AuditStatus == AuditStatus.Success) { if (group.IsPublic) return true; if (UserContext.CurrentUser == null) return false; if (authorizer.Group_Manage(group)) return true; GroupService groupService = new GroupService(); if (groupService.IsMember(group.GroupId, UserContext.CurrentUser.UserId)) return true; } if (authorizer.IsAdministrator(GroupConfig.Instance().ApplicationId)) return true; return false; }
/// <summary> /// 群组增量索引 /// </summary> private void GroupEntity_After(GroupEntity group, CommonEventArgs eventArgs) { if (group == null) { return; } if (groupSearcher == null) { groupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.CODE); } //添加索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { groupSearcher.Insert(group); } //删除索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { groupSearcher.Delete(group.GroupId); } //更新索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { groupSearcher.Update(group); } }
/// <summary> /// 添加索引 /// </summary> /// <param name="GroupEntity">待添加的群组</param> public void Insert(GroupEntity group) { Insert(new GroupEntity[] { group }); }
/// <summary> /// 更新索引 /// </summary> /// <param name="GroupEntity">待更新的群组</param> public void Update(GroupEntity group) { Document doc = GroupIndexDocument.Convert(group); searchEngine.Update(doc, group.GroupId.ToString(), GroupIndexDocument.GroupId); }
/// <summary> /// 群组实体 /// </summary> public static GroupEntity New() { GroupEntity group = new GroupEntity() { GroupName = string.Empty, Description = string.Empty, Logo = string.Empty, ThemeAppearance = string.Empty, DateCreated = DateTime.UtcNow, IP = WebUtility.GetIP(), Announcement = string.Empty, MemberCount = 1 }; return group; }
/// <summary> /// 是否拥有删除群组成员的权限 /// </summary> /// <param name="authorizer"></param> /// <param name="group"></param> /// <param name="userId">被删除的用户Id</param> /// <returns>是否拥有删除群组成员的权限</returns> public static bool Group_DeleteMember(this Authorizer authorizer, GroupEntity 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(GroupConfig.Instance().ApplicationId)) return true; GroupService groupService = new GroupService(); //群管理员 if (groupService.IsManager(group.GroupId, currentUser.UserId) && !groupService.IsManager(group.GroupId, userId)) { return true; } return false; }
private WebimRoom Mapping(GroupEntity e) { string gid = e.GroupId.ToString(); WebimRoom room = new WebimRoom(gid, e.GroupName); room.AllCount = e.MemberCount; room.Avatar = SiteUrls.Instance().LogoUrl(e.Logo, TenantTypeIds.Instance().Group(), ImageSizeTypeKeys.Instance().Small()); room.Url = SiteUrls.Instance().GroupHome(e.GroupId); return room; }
/// <summary> /// 删除群组是删除贴吧相关的 /// </summary> /// <param name="group"></param> /// <param name="eventArgs"></param> private void DeleteGroup_Before(GroupEntity group, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { BarPostService barPostService = new BarPostService(); BarThreadService barThreadService = new BarThreadService(); PagingDataSet<BarThread> barThreads = barThreadService.Gets(group.GroupId); new BarSectionService().Delete(group.GroupId); barThreadService.DeletesBySectionId(group.GroupId); foreach (var barThread in barThreads) { barPostService.DeletesByThreadId(barThread.ThreadId); } } }
private void AuthorizeCore(AuthorizationContext filterContext) { string spaceKey = UserContext.CurrentSpaceKey(filterContext); if (string.IsNullOrEmpty(spaceKey)) { throw new ExceptionFacade("spaceKey为null"); } GroupService groupService = new GroupService(); GroupEntity group = groupService.Get(spaceKey); if (group == null) { throw new ExceptionFacade("找不到当前群组"); } IUser currentUser = UserContext.CurrentUser; //判断访问群组权限 if (!new Authorizer().Group_View(group)) { if (currentUser == null) { filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true)); } else { if (group.AuditStatus != AuditStatus.Success) { filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel { Title = "无权访问群组!", Body = "该群组还没有通过审核,所以不能访问!", StatusMessageType = StatusMessageType.Error }, filterContext.HttpContext.Request.RawUrl) /* 跳向无权访问页 */); } else { filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel { Title = "无权访问群组!", Body = "你没有访问该群组的权限", StatusMessageType = StatusMessageType.Error }, filterContext.HttpContext.Request.RawUrl) /* 跳向无权访问页 */); } } return; } //判断该用户是否有访问该群组管理页面的权限 if (!RequireManager) { return; } //匿名用户要求先登录跳转 if (currentUser == null) { filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true)); return; } if (new Authorizer().Group_Manage(group)) { return; } filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel { Title = "无权访问", Body = "您无权访问此页面,只有群主或管理员才能访问", StatusMessageType = Tunynet.Mvc.StatusMessageType.Error }) /* 跳向无权访问页 */); }
/// <summary> /// 更新群组 /// </summary> /// <param name="userId">当前操作人</param> /// <param name="group"><see cref="GroupEntity"/></param> /// <param name="logoFile">群组标识图</param> public void Update(long userId, GroupEntity group) { EventBus<GroupEntity>.Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Update())); auditService.ChangeAuditStatusForUpdate(userId, group); groupRepository.Update(group); EventBus<GroupEntity>.Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Update())); }
/// <summary> /// 是否具有设置群管理员的权限 /// </summary> /// <param name="authorizer"></param> /// <param name="group"></param> /// <returns></returns> public static bool Group_SetManager(this Authorizer authorizer, GroupEntity 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(GroupConfig.Instance().ApplicationId)) return true; return false; }
/// <summary> /// 发送加入群组邀请 /// </summary> /// <param name="group"><see cref="GroupEntity"/></param> /// <param name="sender">发送人</param> /// <param name="userIds">邀请接收人</param> /// <param name="remark">附言</param> public void SendInvitations(GroupEntity group, IUser sender, string remark, IEnumerable<long> userIds) { //调用InvitationService的发送请求的方法 InvitationService invitationService = new InvitationService(); foreach (var userId in userIds) { if (!IsMember(group.GroupId, userId)) { Invitation invitation = Invitation.New(); invitation.ApplicationId = GroupConfig.Instance().ApplicationId; invitation.InvitationTypeKey = InvitationTypeKeys.Instance().InviteJoinGroup(); invitation.UserId = userId; invitation.SenderUserId = sender.UserId; invitation.Sender = sender.DisplayName; invitation.SenderUrl = SiteUrls.Instance().SpaceHome(sender.UserId); invitation.RelativeObjectId = group.GroupId; invitation.RelativeObjectName = group.GroupName; invitation.RelativeObjectUrl = SiteUrls.Instance().GroupHome(group.GroupKey); invitation.Remark = remark; invitationService.Create(invitation); } } }
/// <summary> /// 是否具有邀请好友加入群组的权限 /// </summary> /// <param name="group"></param> /// <returns></returns> public static bool Group_Invite(this Authorizer authorizer, GroupEntity group) { if (group == null) return false; if (UserContext.CurrentUser == null) return false; GroupService groupService = new GroupService(); if (authorizer.Group_Manage(group)) return true; if (group.EnableMemberInvite && groupService.IsMember(group.GroupId, UserContext.CurrentUser.UserId)) return true; return false; }