/// <summary>
        /// 验证指定对象针对toUserId是否具有隐私权限
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="toUserId">被验证用户</param>
        /// <param name="specifyObjectId">指定对象Id</param>
        /// <returns>true-成功,false-失败</returns>
        bool IPrivacySpecifyObjectValidator.Validate(long userId, long toUserId, long specifyObjectId)
        {
            //done:zhengw,by mazq
            //1、所有分组Id是什么?
            //2、相互关注等特殊规则怎么制定的,编码的人遵照什么来编码
            //zhengw回复:使用FollowSpecifyGroupIds.All获取所有分组Id,具体参见:Examples\BusinessComponents\User\Follow\FollowEnum.cs中的FollowSpecifyGroupIds类

            //如果specifyObjectId为所有分组Id,则仅判断下toUserId是不是关注的人即可
            FollowService followService = new FollowService();

            if (specifyObjectId == FollowSpecifyGroupIds.All)
            {
                return(followService.IsFollowed(userId, toUserId));
            }
            else if (specifyObjectId == FollowSpecifyGroupIds.Mutual)
            {
                return(followService.IsMutualFollowed(userId, toUserId));
            }
            else
            {
                FollowEntity follow = followService.Get(userId, toUserId);
                if (follow == null)
                {
                    return(false);
                }
                IEnumerable <Category> categories = new CategoryService().GetCategoriesOfItem(follow.Id, userId, TenantTypeIds.Instance().User());
                if (categories == null)
                {
                    return(false);
                }
                return(categories.Any(n => n.CategoryId == specifyObjectId));
            }
        }
        /// <summary>
        /// 判断用户是否关注了某个用户
        /// </summary>
        /// <param name="user"><see cref="IUser"/></param>
        /// <param name="toUserId">待检测用户Id</param>
        /// <returns></returns>
        public static bool IsFollowed(this IUser user, long toUserId)
        {
            if (user == null)
            {
                return(false);
            }

            FollowService followService = new FollowService();

            return(followService.IsFollowed(user.UserId, toUserId));
        }
Exemple #3
0
        ///<overloads>隐私验证</overloads>
        /// <summary>
        /// 隐私验证
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="toUserId">被验证用户Id</param>
        /// <param name="itemKey">隐私项目Key</param>
        /// <returns>true-验证通过,false-验证失败</returns>
        public bool Validate(long userId, long toUserId, string itemKey)
        {
            if (toUserId == userId)
            {
                return(true);
            }

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

            if (toUserId > 0)
            {
                toUser = userService.GetUser(toUserId);
            }
            if (toUser != null)
            {
                if (toUser.IsSuperAdministrator())
                {
                    return(true);
                }

                //被验证用户为黑名单用户
                if (IsStopedUser(userId, toUserId))
                {
                    return(false);
                }
            }
            Dictionary <string, PrivacyStatus> userUserPrivacySettings = GetUserPrivacySettings(userId);

            if (userUserPrivacySettings.ContainsKey(itemKey))
            {
                switch (userUserPrivacySettings[itemKey])
                {
                case PrivacyStatus.Public:
                    return(true);

                case PrivacyStatus.Part:
                    return(toUser != null && ValidateUserPrivacySpecifyObject(userId, toUserId, itemKey));

                case PrivacyStatus.Private:
                    return(false);

                default:
                    return(false);
                }
            }
            var privacyItem = GetPrivacyItem(itemKey);

            if (privacyItem != null)
            {
                switch (privacyItem.PrivacyStatus)
                {
                case PrivacyStatus.Private:
                    return(false);

                case PrivacyStatus.Part:
                    FollowService followService = new FollowService();
                    return(followService.IsFollowed(userId, toUserId));

                case PrivacyStatus.Public:
                    return(true);

                default:
                    return(true);
                }
            }
            return(false);
        }