コード例 #1
0
 /// <summary>
 /// 获取接收人UserId集合
 /// </summary>
 /// <param name="activityService">动态业务逻辑类</param>
 /// <param name="ownerId">动态拥有者Id</param>
 /// <param name="userId">动态发布者Id</param>
 /// <param name="activityItemKey">动态项目标识</param>
 /// <returns></returns>
 IEnumerable<long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity)
 {
     SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BlogThread());
     IEnumerable<long> followerUserIds = subscribeService.GetUserIdsOfObject(activity.OwnerId);
     if (followerUserIds == null)
         return new List<long>();
     return followerUserIds.Where(n => IsReceiveActivity(activityService, n, activity));
 }
コード例 #2
0
ファイル: Authorizer.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 是否具有创建BarPost的权限
        /// </summary>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <returns></returns>
        public static bool BarPost_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            IUser currentUser = UserContext.CurrentUser;
            errorMessage = "没有权限回帖";
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);
            if (barSection == null)
                return false;

            if (barSection.AuditStatus != AuditStatus.Success)
            {
                errorMessage = "由于贴吧未经过审核,所以不允许发帖";
                return false;
            }

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreatePost()))
            {
                if (currentUser != null && currentUser.IsModerated)
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarPostDenied;
                return false;
            }

            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                //检查是否需要是关注用户才能发帖
                ISettingsManager<BarSettings> barSettingsManager = DIContainer.Resolve<ISettingsManager<BarSettings>>();
                BarSettings barSetting = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreatePost)
                {
                    if (currentUser == null)
                    {
                        errorMessage = "您需要先登录并关注此帖吧,才能回帖";
                        return false;
                    }
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    bool isSubscribed = subscribeService.IsSubscribed(sectionId, currentUser.UserId);
                    if (!isSubscribed)
                        errorMessage = "您需要先关注此帖吧,才能回帖";
                    return isSubscribed;
                }
            }
            else
            {
                if (authorizer.BarSection_Manage(barSection))
                    return true;
                bool isTenantMember = authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId);
                if (!isTenantMember)
                    errorMessage = "您需要先加入,才能回帖";
                return isTenantMember;
            }

            //站点设置是否启用了匿名发帖
            ISettingsManager<SiteSettings> siteSettingsManager = DIContainer.Resolve<ISettingsManager<SiteSettings>>();
            SiteSettings siteSettings = siteSettingsManager.Get();
            if (siteSettings.EnableAnonymousPosting)
                return true;

            if (currentUser == null)
            {
                errorMessage = "您必须先登录,才能回帖";
                return false;
            }
            return true;
        }
コード例 #3
0
ファイル: Authorizer.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 是否具有创建BarThread的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <param name="errorMessage">无权信息提示</param>
        /// <returns></returns>
        public static bool BarThread_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            errorMessage = string.Empty;
            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
            {
                errorMessage = "您需要先登录,才能发帖";
                return false;
            }
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);
            if (barSection == null)
            {
                errorMessage = "贴吧不存在";
                return false;
            }

            if (authorizer.BarSection_Manage(barSection))
                return true;

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreateThread()))
            {
                if (currentUser.IsModerated)
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarThreadDenied;
                return false;
            }
            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                ISettingsManager<BarSettings> barSettingsManager = DIContainer.Resolve<ISettingsManager<BarSettings>>();
                BarSettings barSetting = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreateThread)
                {
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    if (subscribeService.IsSubscribed(sectionId, currentUser.UserId))
                        return true;
                    else
                    {
                        errorMessage = "您需要先关注此帖吧,才能发帖";
                        return false;
                    }
                }
                else
                    return true;
            }
            else
            {
                if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId))
                    return true;
                else
                {
                    TenantType tenantType = new TenantTypeService().Get(barSection.TenantTypeId);
                    errorMessage = string.Format("只有加入{0}才能发帖", tenantType.Name);
                    return false;
                }
            }
        }
コード例 #4
0
ファイル: Authorizer.cs プロジェクト: hbulzy/SYS
        /// <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;
        }
コード例 #5
0
        /// <summary>
        /// 创建帖吧
        /// </summary>
        /// <param name="section">帖吧</param>
        /// <param name="userId">当前操作人</param>
        /// <param name="managerIds">管理员用户Id</param>
        /// <param name="logoFile">帖吧标识图</param>
        /// <returns>是否创建成功</returns>
        public bool Create(BarSection section, long userId, IEnumerable<long> managerIds, Stream logoFile)
        {
            EventBus<BarSection>.Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Create()));
            //设置审核状态
            auditService.ChangeAuditStatusForCreate(userId, section);

            if (!(section.SectionId > 0))
                section.SectionId = IdGenerator.Next();

            long id = 0;
            long.TryParse(barSectionRepository.Insert(section).ToString(), out id);

            if (id > 0)
            {
                if (managerIds != null && managerIds.Count() > 0)
                {
                    List<long> mangagerIds_list = managerIds.ToList();
                    mangagerIds_list.Remove(section.UserId);
                    managerIds = mangagerIds_list;
                    barSectionRepository.UpdateManagerIds(id, managerIds);
                }
                if (section.TenantTypeId == TenantTypeIds.Instance().Bar())
                {
                    //帖吧主、吧管理员自动关注本帖吧
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    int followedCount = 0;
                    bool result = subscribeService.Subscribe(section.SectionId, section.UserId);
                    if (result)
                        followedCount++;
                    if (managerIds != null && managerIds.Count() > 0)
                        foreach (var managerId in managerIds)
                        {
                            result = subscribeService.Subscribe(section.SectionId, managerId);
                            if (result)
                                followedCount++;
                        }
                    //增加帖吧的被关注数
                    CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                    countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true);
                }

                //上传Logo
                if (logoFile != null)
                {
                    LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection());
                    section.LogoImage = logoService.UploadLogo(section.SectionId, logoFile);
                    barSectionRepository.Update(section);
                }
                EventBus<BarSection>.Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Create()));
                EventBus<BarSection, AuditEventArgs>.Instance().OnAfter(section, new AuditEventArgs(section.AuditStatus, null));
            }
            return id > 0;
        }
コード例 #6
0
        /// <summary>
        /// 更新帖吧
        /// </summary>
        /// <param name="section">帖吧</param>
        /// <param name="userId">当前操作人</param>
        /// <param name="managerIds">管理员用户Id</param>
        /// <param name="sectionedFile">帖吧标识图</param>
        public void Update(BarSection section, long userId, IEnumerable<long> managerIds, Stream sectionedFile)
        {
            EventBus<BarSection>.Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Update()));

            //上传Logo
            if (sectionedFile != null)
            {
                LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection());
                section.LogoImage = logoService.UploadLogo(section.SectionId, sectionedFile);

            }

            auditService.ChangeAuditStatusForUpdate(userId, section);
            barSectionRepository.Update(section);

            if (managerIds != null && managerIds.Count() > 0)
            {
                List<long> mangagerIds_list = managerIds.ToList();
                mangagerIds_list.Remove(section.UserId);
                managerIds = mangagerIds_list;
            }
            barSectionRepository.UpdateManagerIds(section.SectionId, managerIds);

            if (section.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());

                //帖吧主、吧管理员自动关注本帖吧
                int followedCount = 0;
                bool result = subscribeService.Subscribe(section.SectionId, section.UserId);
                if (result)
                    followedCount++;
                if (managerIds != null && managerIds.Count() > 0)
                {
                    foreach (var managerId in managerIds)
                    {
                        result = subscribeService.Subscribe(section.SectionId, managerId);
                        if (result)
                            followedCount++;
                    }
                }

                //增加帖吧的被关注数
                CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true);
            }
            EventBus<BarSection>.Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Update()));
        }
コード例 #7
0
ファイル: BarSectionEventModule.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 帖吧申请处理结果通知
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        void BarSectionNoticeEventModule_After(BarSection sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {

                IUserService userService = DIContainer.Resolve<IUserService>();
                NoticeService noticeService = DIContainer.Resolve<NoticeService>();
                User toUser = userService.GetFullUser(sender.UserId);
                if (toUser == null)
                    return;
                Notice notice = Notice.New();
                notice.UserId = sender.UserId;
                notice.ApplicationId = BarConfig.Instance().ApplicationId;
                notice.TypeId = NoticeTypeIds.Instance().Reply();
                notice.LeadingActorUserId = sender.UserId;
                notice.LeadingActor = toUser.DisplayName;
                notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(toUser.UserName));
                notice.RelativeObjectId = sender.SectionId;
                notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Name, 64);
                if (eventArgs.EventOperationType == EventOperationType.Instance().Approved())
                {
                    //通知吧主,其申请的帖吧通过了审核
                    notice.TemplateName = NoticeTemplateNames.Instance().ManagerApproved();
                }
                else
                {
                    //通知吧主,其申请的帖吧未通过审核
                    notice.TemplateName = NoticeTemplateNames.Instance().ManagerDisapproved();
                }

                notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().SectionDetail(sender.SectionId));
                noticeService.Create(notice);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                IEnumerable<long> userIds = subscribeService.GetTopUserIdsOfObject(sender.SectionId, int.MaxValue);

                foreach (long userId in userIds)
                    subscribeService.CancelSubscribe(sender.SectionId, userId);
            }
        }