/// <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); }
/// <summary> /// 获取接收人UserId集合 /// </summary> /// <param name="activityService">动态业务逻辑类</param> /// <param name="activity">动态</param> /// <returns></returns> IEnumerable<long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity) { TopicService groupService = new TopicService(); IEnumerable<long> userIds = groupService.GetUserIdsOfTopic(activity.OwnerId); bool isPublic = false; var group = groupService.Get(activity.OwnerId); if (group != null) isPublic = group.IsPublic; if (userIds == null) return new List<long>(); return userIds.Where(n => IsReceiveActivity(activityService, isPublic, n, activity)); }
/// <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); }
/// <summary> /// 获取接收人UserId集合 /// </summary> /// <param name="activityService">动态业务逻辑类</param> /// <param name="activity">动态</param> /// <returns></returns> IEnumerable <long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity) { TopicService groupService = new TopicService(); IEnumerable <long> userIds = groupService.GetUserIdsOfTopic(activity.OwnerId); bool isPublic = false; var group = groupService.Get(activity.OwnerId); if (group != null) { isPublic = group.IsPublic; } if (userIds == null) { return(new List <long>()); } return(userIds.Where(n => IsReceiveActivity(activityService, isPublic, n, activity))); }
/// <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); }
/// <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; }
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="sender"></param> /// <param name="eventArgs"></param> private void TopicMemberApplyNoticeModule_After(TopicMemberApply sender, CommonEventArgs eventArgs) { TopicService groupService = new TopicService(); TopicEntity entity = groupService.Get(sender.TopicId); if (entity == null) return; User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId); if (senderUser == null) return; InvitationService invitationService = new InvitationService(); Invitation invitation; NoticeService noticeService = DIContainer.Resolve<NoticeService>(); Notice notice; if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { if (sender.ApplyStatus == TopicMemberApplyStatus.Pending) { List<long> toUserIds = new List<long>(); toUserIds.Add(entity.UserId); toUserIds.AddRange(entity.TopicManagers.Select(n => n.UserId)); foreach (var toUserId in toUserIds) { //申请加入专题的请求 if (!groupService.IsMember(sender.TopicId, sender.UserId)) { invitation = Invitation.New(); invitation.ApplicationId = TopicConfig.Instance().ApplicationId; invitation.InvitationTypeKey = InvitationTypeKeys.Instance().ApplyJoinTopic(); invitation.UserId = toUserId; invitation.SenderUserId = sender.UserId; invitation.Sender = senderUser.DisplayName; invitation.SenderUrl = SiteUrls.Instance().SpaceHome(sender.UserId); invitation.RelativeObjectId = sender.TopicId; invitation.RelativeObjectName = entity.TopicName; invitation.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey)); invitation.Remark = sender.ApplyReason; invitationService.Create(invitation); } } } } string noticeTemplateName = string.Empty; if (eventArgs.EventOperationType == EventOperationType.Instance().Approved()) { if (sender.ApplyStatus == TopicMemberApplyStatus.Approved) { noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyApproved(); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { if (sender.ApplyStatus == TopicMemberApplyStatus.Disapproved) { noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyDisapproved(); } } if (string.IsNullOrEmpty(noticeTemplateName)) return; notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = TopicConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); //notice.LeadingActorUserId = UserContext.CurrentUser.UserId; //notice.LeadingActor = UserContext.CurrentUser.DisplayName; //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(UserContext.CurrentUser.UserId)); notice.RelativeObjectId = sender.TopicId; notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey)); notice.TemplateName = noticeTemplateName; noticeService.Create(notice); }
/// <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); }
/// <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; }
/// <summary> /// 通知处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void TopicMemberNoticeModule_After(TopicMember sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType != EventOperationType.Instance().Delete() && eventArgs.EventOperationType != EventOperationType.Instance().Create() && sender != null) return; TopicService groupService = new TopicService(); TopicEntity entity = groupService.Get(sender.TopicId); if (entity == null) return; User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId); if (senderUser == null) return; NoticeService noticeService = DIContainer.Resolve<NoticeService>(); Notice notice; List<long> toUserIds = new List<long>(); toUserIds.Add(entity.UserId); toUserIds.AddRange(entity.TopicManagers.Select(n => n.UserId)); //删除专题成员通知群管理员 if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { foreach (var toUserId in toUserIds) { if (toUserId == sender.UserId) continue; notice = Notice.New(); notice.UserId = toUserId; notice.ApplicationId = TopicConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActorUserId = sender.UserId; notice.LeadingActor = senderUser.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId)); notice.RelativeObjectId = sender.TopicId; notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey)); notice.TemplateName = NoticeTemplateNames.Instance().MemberQuit(); noticeService.Create(notice); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) //添加群成员时向群管理员发送通知 { foreach (var toUserId in toUserIds) { if (toUserId == sender.UserId) continue; notice = Notice.New(); notice.UserId = toUserId; notice.ApplicationId = TopicConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActorUserId = sender.UserId; notice.LeadingActor = senderUser.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId)); notice.RelativeObjectId = sender.TopicId; notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey)); notice.TemplateName = NoticeTemplateNames.Instance().MemberJoin(); noticeService.Create(notice); } //向加入者发送通知 //notice = Notice.New(); //notice.UserId = sender.UserId; //notice.ApplicationId = TopicConfig.Instance().ApplicationId; //notice.TypeId = NoticeTypeIds.Instance().Hint(); //notice.LeadingActorUserId = sender.UserId; //notice.LeadingActor = senderUser.DisplayName; //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId)); //notice.RelativeObjectId = sender.TopicId; //notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64); //notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey)); //notice.TemplateName = NoticeTemplateNames.Instance().MemberApplyApproved(); //noticeService.Create(notice); } }
/// <summary> /// 设置/取消管理员通知处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void SetManagerNoticeEventModule_After(TopicMember sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType != EventOperationType.Instance().SetTopicManager() && eventArgs.EventOperationType != EventOperationType.Instance().CancelTopicManager()) return; TopicService groupService = new TopicService(); TopicEntity entity = groupService.Get(sender.TopicId); if (entity == null) return; User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId); if (senderUser == null) return; NoticeService noticeService = DIContainer.Resolve<NoticeService>(); Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = TopicConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActorUserId = 0; notice.LeadingActor = string.Empty; notice.LeadingActorUrl = string.Empty; notice.RelativeObjectId = sender.TopicId; notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey)); if (eventArgs.EventOperationType == EventOperationType.Instance().SetTopicManager()) { notice.TemplateName = NoticeTemplateNames.Instance().SetTopicManager(); } else { notice.TemplateName = NoticeTemplateNames.Instance().CannelTopicManager(); } noticeService.Create(notice); }
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 }) /* 跳向无权访问页 */); }