/// <summary> /// 是否具有编辑BarThread的权限 /// </summary> /// <param name="threadId"></param> /// <returns></returns> public static bool BarThread_Edit(this Authorizer authorizer, BarThread thread) { if (thread == null) return false; BarSection section = thread.BarSection; if (section != null && section.AuditStatus == AuditStatus.Success) { if (UserContext.CurrentUser == null) return false; if (thread.UserId == UserContext.CurrentUser.UserId) return true; } BarSectionService barSectionService = new BarSectionService(); if (authorizer.BarSection_Manage(barSectionService.Get(thread.SectionId))) return true; return false; }
/// <summary> /// 是否具有管理BarThread的权限 /// </summary> /// <param name="threadId"></param> /// <returns></returns> public static bool BarThread_Manage(this Authorizer authorizer, BarThread thread) { if (thread == null) return false; BarSectionService barSectionService = new BarSectionService(); return authorizer.BarSection_Manage(barSectionService.Get(thread.SectionId)); }
/// <summary> /// 是否具有评分的权限 /// </summary> /// <returns></returns> public static bool BarRating(this Authorizer authorizer, BarThread thread, out string errorMessage) { BarSettings barSettings = DIContainer.Resolve<ISettingsManager<BarSettings>>().Get(); errorMessage = "没有找到对应的帖子"; if (thread == null) return false; errorMessage = "您还没有登录"; IUser currentUser = UserContext.CurrentUser; if (currentUser == null) return false; if (thread.UserId == currentUser.UserId) { errorMessage = "您不可以给自己的帖子评分哦"; return false; } BarRatingService barRatingService = new BarRatingService(); //是否已经评过分 errorMessage = "您已经评论过此贴"; if (barRatingService.IsRated(currentUser.UserId, thread.ThreadId)) return false; errorMessage = "您的剩余积分不够了哦"; if (barRatingService.GetUserTodayRatingSum(UserContext.CurrentUser.UserId) + barSettings.ReputationPointsMinValue > barSettings.UserReputationPointsPerDay) return false; ISettingsManager<BarSettings> barSettingsManager = DIContainer.Resolve<ISettingsManager<BarSettings>>(); BarSettings barSetting = barSettingsManager.Get(); BarSectionService barSectionService = new BarSectionService(); var barSection = barSectionService.Get(thread.SectionId); if (barSection == null) return false; if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar()) { errorMessage = "此帖吧仅允许关注的用户评分哦"; if (barSetting.OnlyFollowerCreatePost) { SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection()); return subscribeService.IsSubscribed(thread.SectionId, currentUser.UserId); } } else { if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId)) return true; } errorMessage = "站点没有开启帖子评分"; if (!barSetting.EnableRating) return false; return true; }
/// <summary> /// 是否具有删除BarThread的权限 /// </summary> /// <param name="threadId"></param> /// <returns></returns> public static bool BarThread_Delete(this Authorizer authorizer, BarThread thread) { return authorizer.BarThread_Edit(thread); }
/// <summary> /// 动态处理程序 /// </summary> /// <param name="barThread"></param> /// <param name="eventArgs"></param> private void BarThreadActivityModule_After(BarThread barThread, AuditEventArgs eventArgs) { //1、通过审核的内容才生成动态;(不满足) //2、把通过审核的内容设置为未通过审核或者删除内容,需要移除动态;(不满足) //3、把未通过审核的内容通过审核,需要添加动态; (不满足) //4、详见动态需求说明 //生成动态 ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //生成动态 { if (barThread.BarSection == null) return; var barUrlGetter = BarUrlGetterFactory.Get(barThread.TenantTypeId); if (barUrlGetter == null) return; //生成Owner为帖吧的动态 Activity actvityOfBar = Activity.New(); actvityOfBar.ActivityItemKey = ActivityItemKeys.Instance().CreateBarThread(); actvityOfBar.ApplicationId = BarConfig.Instance().ApplicationId; AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().BarThread()); IEnumerable<Attachment> attachments = attachmentService.GetsByAssociateId(barThread.ThreadId); if (attachments != null && attachments.Any(n => n.MediaType == MediaType.Image)) actvityOfBar.HasImage = true; actvityOfBar.IsOriginalThread = true; actvityOfBar.IsPrivate = false; actvityOfBar.UserId = barThread.UserId; actvityOfBar.ReferenceId = 0;//没有涉及到的实体 actvityOfBar.ReferenceTenantTypeId = string.Empty; actvityOfBar.SourceId = barThread.ThreadId; actvityOfBar.TenantTypeId = TenantTypeIds.Instance().BarThread(); actvityOfBar.OwnerId = barThread.SectionId; actvityOfBar.OwnerName = barThread.BarSection.Name; actvityOfBar.OwnerType = barUrlGetter.ActivityOwnerType; activityService.Generate(actvityOfBar, false); if (!barUrlGetter.IsPrivate(barThread.SectionId)) { //生成Owner为用户的动态 Activity actvityOfUser = Activity.New(); actvityOfUser.ActivityItemKey = actvityOfBar.ActivityItemKey; actvityOfUser.ApplicationId = actvityOfBar.ApplicationId; actvityOfUser.HasImage = actvityOfBar.HasImage; actvityOfUser.HasMusic = actvityOfBar.HasMusic; actvityOfUser.HasVideo = actvityOfBar.HasVideo; actvityOfUser.IsOriginalThread = actvityOfBar.IsOriginalThread; actvityOfUser.IsPrivate = actvityOfBar.IsPrivate; actvityOfUser.UserId = actvityOfBar.UserId; actvityOfUser.ReferenceId = actvityOfBar.ReferenceId; actvityOfUser.SourceId = actvityOfBar.SourceId; actvityOfUser.TenantTypeId = actvityOfBar.TenantTypeId; actvityOfUser.OwnerId = barThread.UserId; actvityOfUser.OwnerName = barThread.User.DisplayName; actvityOfUser.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(actvityOfUser, false); } } else if (auditDirection == false) //删除动态 { activityService.DeleteSource(TenantTypeIds.Instance().BarThread(), barThread.ThreadId); } }
/// <summary> /// 是否拥有平分的权限 /// </summary> /// <param name="authorizer"></param> /// <param name="thread">被评分的帖子</param> /// <returns>是否允许评分</returns> public static bool BarRating(this Authorizer authorizer, BarThread thread) { string errorMessage; return authorizer.BarRating(thread, out errorMessage); }
/// <summary> /// 处理加精、置顶等操作 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void BarThreadPointModuleForManagerOperation_After(BarThread sender, CommonEventArgs eventArgs) { NoticeService noticeService = new NoticeService(); if (eventArgs.OperatorInfo == null) return; string pointItemKey = string.Empty; if (eventArgs.EventOperationType == EventOperationType.Instance().SetEssential()) { pointItemKey = PointItemKeys.Instance().EssentialContent(); if (sender.UserId > 0 && sender.UserId != eventArgs.OperatorInfo.OperatorUserId) { Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = BarConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = sender.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().ThreadDetail(sender.ThreadId)); notice.TemplateName = NoticeTemplateNames.Instance().ManagerSetEssential(); noticeService.Create(notice); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().SetSticky()) { pointItemKey = PointItemKeys.Instance().StickyContent(); if (sender.UserId > 0 && sender.UserId != eventArgs.OperatorInfo.OperatorUserId) { Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = BarConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = sender.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().ThreadDetail(sender.ThreadId)); notice.TemplateName = NoticeTemplateNames.Instance().ManagerSetSticky(); noticeService.Create(notice); } } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventArgs.EventOperationType), "帖子", sender.Subject); pointService.GenerateByRole(sender.UserId, pointItemKey, description); } }
/// <summary> /// 审核状态发生变化时处理积分 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void BarThreadPointModule_After(BarThread sender, AuditEventArgs eventArgs) { string pointItemKey = string.Empty; string eventOperationType = string.Empty; ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Bar_CreateThread(); if (eventArgs.OldAuditStatus == null) eventOperationType = EventOperationType.Instance().Create(); else eventOperationType = EventOperationType.Instance().Approved(); } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Bar_DeleteThread(); if (eventArgs.NewAuditStatus == null) eventOperationType = EventOperationType.Instance().Delete(); else eventOperationType = EventOperationType.Instance().Disapproved(); } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "帖子", sender.Subject); pointService.GenerateByRole(sender.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == sender.UserId); } }
/// <summary> /// 是否拥有平分的权限 /// </summary> /// <param name="authorizer"></param> /// <param name="thread">被评分的帖子</param> /// <returns>是否允许评分</returns> public static bool BarRating(this Authorizer authorizer, BarThread thread) { string errorMessage; return(authorizer.BarRating(thread, out errorMessage)); }
/// <summary> /// 是否具有评分的权限 /// </summary> /// <returns></returns> public static bool BarRating(this Authorizer authorizer, BarThread thread, out string errorMessage) { BarSettings barSettings = DIContainer.Resolve <IBarSettingsManager>().Get(); errorMessage = "没有找到对应的帖子"; if (thread == null) { return(false); } errorMessage = "您还没有登录"; IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return(false); } if (thread.UserId == currentUser.UserId) { errorMessage = "您不可以给自己的帖子评分哦"; return(false); } BarRatingService barRatingService = new BarRatingService(); //是否已经评过分 errorMessage = "您已经评论过此贴"; if (barRatingService.IsRated(currentUser.UserId, thread.ThreadId)) { return(false); } errorMessage = "您的剩余积分不够了哦"; if (barRatingService.GetUserTodayRatingSum(UserContext.CurrentUser.UserId) + barSettings.ReputationPointsMinValue > barSettings.UserReputationPointsPerDay) { return(false); } IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>(); BarSettings barSetting = barSettingsManager.Get(); BarSectionService barSectionService = new BarSectionService(); var barSection = barSectionService.Get(thread.SectionId); if (barSection == null) { return(false); } if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar()) { errorMessage = "此帖吧仅允许关注的用户评分哦"; if (barSetting.OnlyFollowerCreatePost) { SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection()); return(subscribeService.IsSubscribed(thread.SectionId, currentUser.UserId)); } } else { if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId)) { return(true); } } errorMessage = "站点没有开启帖子评分"; if (!barSetting.EnableRating) { return(false); } return(true); }
/// <summary> /// 是否具有删除BarThread的权限 /// </summary> /// <param name="threadId"></param> /// <returns></returns> public static bool BarThread_Delete(this Authorizer authorizer, BarThread thread) { return(authorizer.BarThread_Edit(thread)); }
/// <summary> /// 更新主题帖 /// </summary> /// <param name="thread">主题帖</param> /// <param name="userId">当前操作人</param> public void Update(BarThread thread, long userId) { EventBus<BarThread>.Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Update())); AuditStatus oldAuditStatus = thread.AuditStatus; auditService.ChangeAuditStatusForUpdate(userId, thread); barThreadRepository.Update(thread); EventBus<BarThread>.Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Update())); EventBus<BarThread, AuditEventArgs>.Instance().OnAfter(thread, new AuditEventArgs(oldAuditStatus, thread.AuditStatus)); }
/// <summary> /// 创建主题帖 /// </summary> /// <param name="thread">主题帖</param> public bool Create(BarThread thread) { BarSectionService barSectionService = new BarSectionService(); EventBus<BarThread>.Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态 auditService.ChangeAuditStatusForCreate(thread.UserId, thread); long id = 0; long.TryParse(barThreadRepository.Insert(thread).ToString(), out id); if (id > 0) { new AttachmentService(TenantTypeIds.Instance().BarThread()).ToggleTemporaryAttachments(thread.UserId, TenantTypeIds.Instance().BarThread(), id); BarSection barSection = barSectionService.Get(thread.SectionId); if (barSection != null) { //计数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().ThreadCount(), barSection.SectionId, barSection.UserId, 1, true); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, 1, true); if (thread.TenantTypeId == TenantTypeIds.Instance().Group()) { //群组内容计数+1 OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group()); groupOwnerDataService.Change(thread.SectionId, OwnerDataKeys.Instance().ThreadCount(), 1); } } if (thread.TenantTypeId == TenantTypeIds.Instance().Bar()) { //用户内容计数+1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(thread.UserId, OwnerDataKeys.Instance().ThreadCount(), 1); } AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BarThread()); atUserService.ResolveBodyForEdit(thread.GetBody(), thread.UserId, thread.ThreadId); EventBus<BarThread>.Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus<BarThread, AuditEventArgs>.Instance().OnAfter(thread, new AuditEventArgs(null, thread.AuditStatus)); } return id > 0; }
/// <summary> /// 新建实体时使用 /// </summary> public static BarThread New() { BarThread barThread = new BarThread() { Author = string.Empty, Subject = string.Empty, StickyDate = DateTime.UtcNow, HighlightStyle = string.Empty, HighlightDate = DateTime.UtcNow, IP = WebUtility.GetIP(), DateCreated = DateTime.UtcNow, LastModified = DateTime.UtcNow }; return barThread; }
/// <summary> /// 删除主题帖 /// </summary> /// <param name="threadId">主题帖Id</param> public void Delete(long threadId) { BarThread thread = barThreadRepository.Get(threadId); if (thread == null) { return; } EventBus <BarThread> .Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Delete())); BarSectionService barSectionService = new BarSectionService(); BarSection barSection = barSectionService.Get(thread.SectionId); if (barSection != null) { //帖子标签 TagService tagService = new TagService(TenantTypeIds.Instance().BarThread()); tagService.ClearTagsFromItem(threadId, barSection.SectionId); //帖子分类 CategoryService categoryService = new CategoryService(); categoryService.ClearCategoriesFromItem(threadId, barSection.SectionId, TenantTypeIds.Instance().BarThread()); } //删除回帖 BarPostService barPostService = new BarPostService(); barPostService.DeletesByThreadId(threadId); //删除推荐记录 RecommendService recommendService = new RecommendService(); recommendService.Delete(threadId, TenantTypeIds.Instance().BarThread()); int affectCount = barThreadRepository.Delete(thread); if (affectCount > 0) { //更新帖吧的计数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().ThreadCount(), barSection.SectionId, barSection.UserId, -1, true); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, -1, true); if (thread.TenantTypeId == TenantTypeIds.Instance().Group()) { //群组内容计数-1 OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group()); groupOwnerDataService.Change(thread.SectionId, OwnerDataKeys.Instance().ThreadCount(), -1); } else if (thread.TenantTypeId == TenantTypeIds.Instance().Bar()) { //用户内容计数-1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(thread.UserId, OwnerDataKeys.Instance().ThreadCount(), -1); } EventBus <BarThread> .Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Delete())); EventBus <BarThread, AuditEventArgs> .Instance().OnAfter(thread, new AuditEventArgs(thread.AuditStatus, null)); } //BarThread删除可能影响的: //1、附件 (看到了) //2、BarPost(看到了) //3、BarRating(看到了) //4、相关计数对象(看到了) //5、用户在应用中的数据(看到了) //6、@用户(看到了) }