Exemplo n.º 1
0
        /// <summary>
        /// 获取用户项目来源权限(仅用于权限分配)
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List <RightItem> GetUserProjectSourceRights(int userId)
        {
            //权限判断
            loginService.HaveAdminRightForUserGrant(userId);

            return(DARightsHelper.GetUserProjectSourceRights(userId));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 设置用户的权限
        /// </summary>
        /// <param name="user"></param>
        /// <param name="sysId"></param>
        private void SetUserRights(UserContext user, int sysId)
        {
            UserTypeOptions userType     = user.LoginUser.AccountType;
            bool            isSuperAdmin = userType == UserTypeOptions.SuperAdmin;
            bool            isWhiteUser  = user.LoginUser.IsWhiteUser;

            if (user.AvailableRights == null)
            {
                List <Right> availableRights = DABasicInfoHelper.GetRights(sysId, -1, CacheTimeOption.Short);
                List <int>   rights          = DARightsHelper.GetUserRights(sysId, user.LoginUser.ID, user.LoginUser.AccountType).Select(a => a.RightID).ToList();
                user.AvailableRights = availableRights.Where(a => (isSuperAdmin || internalRequest || !a.OnlyInternal || isWhiteUser) && rights.Contains(a.ID)).ToList();
            }
            //只有report才有这些权限
            if (sysId == DACommonHelper.REPORT_SYS_ID)
            {
                if (user.AvailableSofts == null)
                {
                    //从Report平台获得的产品权限
                    List <Soft> availableSofts = GetAvailableSofts();
                    List <int>  rights         = DARightsHelper.GetUserSoftRights(user.LoginUser.ID).Select(a => a.RightID).ToList();
                    user.AvailableSofts = availableSofts.Where(a => a.Status == StatusOptions.Valid && (isSuperAdmin || internalRequest || !a.OnlyInternal || isWhiteUser) && rights.Contains(a.ID)).ToList();
                }
                if (user.AvailableProjectSources == null)
                {
                    List <ProjectSource> availableProjectSources = GetAvailableProjectSources();
                    List <int>           rights = DARightsHelper.GetUserProjectSourceRights(user.LoginUser.ID).Select(a => a.RightID).ToList();
                    user.AvailableProjectSources = availableProjectSources.Where(a => (isSuperAdmin || internalRequest || !a.OnlyInternal || isWhiteUser) && rights.Contains(a.ProjectSourceID)).ToList();
                }
                if (internalRequest && user.AvailableResIds == null)
                {
                    user.AvailableResIds = DARightsHelper.GetUserResRights(user.LoginUser.ID).Select(a => a.RightID).ToList();
                }
            }
            else
            {
                if (user.AvailableSofts == null)
                {
                    user.AvailableSofts = new List <Soft>();
                }
                if (user.AvailableProjectSources == null)
                {
                    user.AvailableProjectSources = new List <ProjectSource>();
                }
                if (internalRequest && user.AvailableResIds == null)
                {
                    user.AvailableResIds = new List <int>();
                }
            }
            if (user.AdminSystems == null)
            {
                List <SystemInfo> systems = DABasicInfoHelper.GetSystems(CacheTimeOption.Short);
                List <int>        sysIds  = DARightsHelper.GetAdminSystemIds(user.LoginUser.ID);
                user.AdminSystems = systems.Where(a => sysIds.Contains(a.ID)).ToList();
            }
        }
        /// <summary>
        /// 获取项目来源信息列表
        /// </summary>
        /// <param name="mustAdmin"></param>
        /// <returns></returns>
        public List <ProjectSource> GetProjectSources(bool mustAdmin = true)
        {
            if (mustAdmin)
            {
                //权限判断
                loginService.HaveAdminRight(DACommonHelper.REPORT_SYS_ID);

                List <ProjectSource> projectSources = DABasicInfoHelper.GetProjectSources();
                if (loginService.LoginUser.AccountType == UserTypeOptions.ProductAdmin)
                {
                    List <RightItem> rangeRights = DARightsHelper.GetUserProjectSourceRights(loginService.LoginUser.ID);
                    var availableRights          = from r in projectSources
                                                   join rr in rangeRights
                                                   on r.ProjectSourceID equals rr.RightID
                                                   select r;
                    return(availableRights.ToList());
                }
                return(projectSources);
            }
            return(DABasicInfoHelper.GetProjectSources());
        }