/// <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="privacyable">可隐私接口</param>
        /// <param name="toUserId">被验证用户Id</param>
        /// <returns>true-验证通过,false-验证失败</returns>
        public bool Validate(IPrivacyable privacyable, long toUserId)
        {
            if (privacyable.PrivacyStatus == PrivacyStatus.Public)
            {
                return(true);
            }
            if (privacyable.PrivacyStatus == PrivacyStatus.Private)
            {
                return(false);
            }

            if (toUserId == privacyable.UserId)
            {
                return(true);
            }

            //被验证用户为超级管理员
            IUserService userService = DIContainer.Resolve <IUserService>();
            IUser        toUser      = userService.GetUser(toUserId);

            if (toUser.IsInRoles(RoleNames.Instance().SuperAdministrator()))
            {
                return(true);
            }

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

            if (privacyService.IsStopedUser(privacyable.UserId, toUserId))
            {
                return(false);
            }

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

            if (dictionary == null || dictionary.Count() == 0)
            {
                return(false);
            }
            foreach (var pair in dictionary)
            {
                IPrivacySpecifyObjectValidator privacySpecifyUserGetter = DIContainer.ResolveNamed <IPrivacySpecifyObjectValidator>(pair.Key.ToString());
                foreach (var specifyObject in pair.Value)
                {
                    if (privacySpecifyUserGetter.Validate(privacyable.UserId, toUserId, specifyObject.SpecifyObjectId))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// 用户隐私验证指定对象
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="toUserId">被验证用户Id</param>
        /// <param name="itemKey">隐私项目Key</param>
        /// <returns>true-验证通过,false-验证失败</returns>
        private bool ValidateUserPrivacySpecifyObject(long userId, long toUserId, string itemKey)
        {
            Dictionary <int, IEnumerable <UserPrivacySpecifyObject> > dictionary = GetUserPrivacySpecifyObjects(userId, itemKey);

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