Exemplo n.º 1
0
        /// <summary>
        /// 是否具有编辑BarPost的权限
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public static bool BarPost_Edit(this Authorizer authorizer, BarPost post)
        {
            if (authorizer.IsAdministrator(BarConfig.Instance().ApplicationId))
            {
                return(true);
            }

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

            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }
            if (post.UserId == currentUser.UserId)
            {
                return(true);
            }
            BarSectionService barSectionService = new BarSectionService();

            if (authorizer.BarSection_Manage(barSectionService.Get(post.SectionId)))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 贴吧显示
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="barSection"></param>
        /// <returns></returns>
        public static bool BarSection_View(this Authorizer authorizer, BarSection barSection)
        {
            if (barSection == null)
            {
                return(false);
            }

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

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

            return(false);
        }
Exemplo n.º 5
0
        /// <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())
            {
                //检查是否需要是关注用户才能发帖
                IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
                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);
            }

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

            if (siteSettings.EnableAnonymousPosting)
            {
                return(true);
            }

            if (currentUser == null)
            {
                errorMessage = "您必须先登录,才能回帖";
                return(false);
            }
            return(true);
        }
Exemplo n.º 6
0
        /// <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())
            {
                IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
                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);
                }
            }
        }