/// <summary>
        /// 检查用户是否接收动态
        /// </summary>
        /// <param name="userId">UserId</param>
        /// <param name="activityItemKey">动态项目标识</param>
        /// <param name="fromOwnerId">动态拥有者</param>
        /// <returns>接收动态返回true,否则返回false</returns>
        private bool IsReceiveActivity(ActivityService activityService, long userId, Activity activity)
        {
            //首先检查是否屏蔽用户
            UserBlockService userBlockService = new UserBlockService();

            if (userBlockService.IsBlockedUser(userId, activity.OwnerId))
            {
                return(false);
            }

            //被验证用户为黑名单用户
            PrivacyService privacyService = new PrivacyService();

            if (privacyService.IsStopedUser(activity.OwnerId, userId))
            {
                return(false);
            }

            //判断指定对象可见
            Dictionary <int, IEnumerable <ContentPrivacySpecifyObject> > dictionary = new ContentPrivacyService().GetPrivacySpecifyObjects(activity.TenantTypeId, activity.SourceId);

            if (dictionary != null && dictionary.Count() > 0)
            {
                foreach (var pair in dictionary)
                {
                    IPrivacySpecifyObjectValidator privacySpecifyUserGetter = DIContainer.ResolveNamed <IPrivacySpecifyObjectValidator>(pair.Key.ToString());
                    foreach (var specifyObject in pair.Value)
                    {
                        if (privacySpecifyUserGetter.Validate(activity.OwnerId, userId, specifyObject.SpecifyObjectId))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }

            //检查用户是否接收该动态项目
            Dictionary <string, bool> userSettings = activityService.GetActivityItemUserSettings(userId);

            if (userSettings.ContainsKey(activity.ActivityItemKey))
            {
                return(userSettings[activity.ActivityItemKey]);
            }
            else
            {
                //如果用户没有设置从默认设置获取
                ActivityItem activityItem = activityService.GetActivityItem(activity.ActivityItemKey);
                if (activityItem != null)
                {
                    return(activityItem.IsUserReceived);
                }
                else
                {
                    return(true);
                }
            }
        }
        /// <summary>
        /// 检查用户是否接收动态
        /// </summary>
        /// <param name="userId">UserId</param>
        /// <param name="activityItemKey">动态项目标识</param>
        /// <param name="fromOwnerId">动态拥有者</param>
        /// <returns>接收动态返回true,否则返回false</returns>
        private bool IsReceiveActivity(ActivityService activityService, long userId, Activity activity)
        {
            //首先检查是否屏蔽用户
            UserBlockService userBlockService = new UserBlockService();
            if (userBlockService.IsBlockedUser(userId, activity.OwnerId))
                return false;

            //被验证用户为黑名单用户
            PrivacyService privacyService = new PrivacyService();
            if (privacyService.IsStopedUser(activity.OwnerId, userId))
                return false;

            //判断指定对象可见
            Dictionary<int, IEnumerable<ContentPrivacySpecifyObject>> dictionary = new ContentPrivacyService().GetPrivacySpecifyObjects(activity.TenantTypeId, activity.SourceId);
            if (dictionary != null && dictionary.Count() > 0)
            {
                foreach (var pair in dictionary)
                {
                    IPrivacySpecifyObjectValidator privacySpecifyUserGetter = DIContainer.ResolveNamed<IPrivacySpecifyObjectValidator>(pair.Key.ToString());
                    foreach (var specifyObject in pair.Value)
                    {
                        if (privacySpecifyUserGetter.Validate(activity.OwnerId, userId, specifyObject.SpecifyObjectId))
                            return true;
                    }
                }
                return false;
            }

            //检查用户是否接收该动态项目
            Dictionary<string, bool> userSettings = activityService.GetActivityItemUserSettings(userId);
            if (userSettings.ContainsKey(activity.ActivityItemKey))
                return userSettings[activity.ActivityItemKey];
            else
            {
                //如果用户没有设置从默认设置获取
                ActivityItem activityItem = activityService.GetActivityItem(activity.ActivityItemKey);
                if (activityItem != null)
                    return activityItem.IsUserReceived;
                else
                    return true;
            }
        }
Example #3
0
        /// <summary>
        /// 查看文章
        /// 仅自己可见的只能是文章作者或管理员可以查看
        /// 部分可见的只能是文章作者、指定可见的用户或管理员可以查看
        /// </summary>
        public static bool BlogThread_View(this Authorizer authorizer, BlogThread blogThread)
        {
            if (blogThread.PrivacyStatus == PrivacyStatus.Public)
            {
                return true;
            }

            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
            {
                return false;
            }

            if (blogThread.UserId == currentUser.UserId || authorizer.IsAdministrator(BlogConfig.Instance().ApplicationId))
            {
                return true;
            }

            if (blogThread.PrivacyStatus == PrivacyStatus.Private)
            {
                return false;
            }

            ContentPrivacyService contentPrivacyService = new ContentPrivacyService();
            if (contentPrivacyService.Validate(blogThread, currentUser.UserId))
            {
                return true;
            }

            return false;
        }