Ejemplo n.º 1
0
        public async Task <ListResultDto <RoleListDto> > GetRoles(GetRolesInput input)
        {
            var isFilterPermissionGrantedByDefault = false;

            if (!input.Permission.IsNullOrWhiteSpace())
            {
                isFilterPermissionGrantedByDefault = await PermissionChecker.IsGrantedAsync(input.Permission);
            }

            var roles = await _roleManager.Roles
                        .WhereIf(!input.Permission.IsNullOrWhiteSpace(),
                                 r => r.Permissions.Any(rp => rp.Name == input.Permission && rp.IsGranted) ||
                                 (r.Permissions.All(rp => rp.Name != input.Permission) && isFilterPermissionGrantedByDefault)
                                 )
                        .ToListAsync();

            return(new ListResultDto <RoleListDto>(roles.MapTo <List <RoleListDto> >()));
        }
Ejemplo n.º 2
0
        private async Task <List <string> > GetGrantedPermissions()
        {
            var grantedPermissions = new List <string>();

            if (AbpSession.UserId.HasValue)
            {
                var allPermissionNames = PermissionManager.GetAllPermissions(false).Select(p => p.Name).ToList();

                foreach (var permissionName in allPermissionNames)
                {
                    if (await PermissionChecker.IsGrantedAsync(permissionName))
                    {
                        grantedPermissions.Add(permissionName);
                    }
                }
            }

            return(grantedPermissions);
        }
Ejemplo n.º 3
0
 public async Task <IViewComponentResult> InvokeAsync(
     string togglerCssClass,
     string textCssClass,
     string symbolCssClass,
     string symbolTextCssClas,
     bool renderOnlyIcon = false)
 {
     return(View(new UserMenuViewModel
     {
         LoginInformations = await _sessionCache.GetCurrentLoginInformationsAsync(),
         IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled,
         IsImpersonatedLogin = _abpSession.ImpersonatorUserId.HasValue,
         HasUiCustomizationPagePermission = await PermissionChecker.IsGrantedAsync(AppPermissions.Pages_Administration_UiCustomization),
         TogglerCssClass = togglerCssClass,
         TextCssClass = textCssClass,
         SymbolCssClass = symbolCssClass,
         SymbolTextCssClass = symbolTextCssClas,
         RenderOnlyIcon = renderOnlyIcon
     }));
 }
Ejemplo n.º 4
0
        public async Task <List <SupplierFruitDto> > GetAFruit(Int32 fruitId, Int32 supplierId)
        {
            if (!await PermissionChecker.IsGrantedAsync("Pages.Suppliers"))
            {
                throw new AbpAuthorizationException("You are not authorized to do this!");
            }
            fruitShopDbContext            fruitContext = (fruitShopDbContext)base.Repository.GetDbContext();
            IQueryable <SupplierFruitDto> entityQuery  =
                from SupplierFruit in fruitContext.SupplierFruits
                where supplierId == SupplierFruit.supplierId && fruitId == SupplierFruit.fruitId
                select new SupplierFruitDto
            {
                name    = SupplierFruit.fruit.name,
                colour  = SupplierFruit.fruit.colour,
                Price   = SupplierFruit.Price,
                fruitId = SupplierFruit.fruitId
            };

            return(await entityQuery.ToListAsync());
        }
Ejemplo n.º 5
0
        public async Task <bool> PaySalaried(PaySalariedInput input)
        {
            //A @【**执行顺序 * *以及 * *结果的拼装 * *】
            //B @【隐藏了领域层的复杂性及其内部实现机制】

            //1--行政财务权限【安全认证,权限校验】
            if (!await PermissionChecker.IsGrantedAsync("行政财务权限"))
            {
                return(false);
            }

            //2--转账,包含了以下逻辑,在financingServiceService中实现业务
            //(结算工时)查询财务结算薪酬
            //检查支付账号余额是否足够
            //检查目标账户账号是否合法
            var result = _financingServiceService.PayEmployeeSalaried(input);

            //3- 检查转账**任务的进度** 与异常
            await CheckErrors(result);

            //框架平台提供的配置获取
            var paySalariedSetting = SettingManager
                                     .GetSettingValueForTenant(input.EmployeeId, 021);

            //4-通知薪酬发放结果
            //【向其他系统发生基于事件的消息通知】
            //【事务控制】
            using (var unitOfWork = UnitOfWorkManager.Begin())
            {
                ///
                _sendMessageService.SendEmail(result);
                _sendMessageService.SendMessage(result);
                _sendMessageService.PushWeChat(result);
                unitOfWork.Complete();
            }

            return(true);
        }
Ejemplo n.º 6
0
        public async Task <bool> ResetPassword(ResetPasswordDto input)
        {
            if (_abpSession.UserId == null)
            {
                throw new UserFriendlyException("Please log in before attemping to reset password.");
            }
            long currentUserId = _abpSession.UserId.Value;
            var  currentUser   = await _userManager.GetUserByIdAsync(currentUserId);

            var loginAsync = await _logInManager.LoginAsync(currentUser.UserName, input.AdminPassword, shouldLockout : false);

            if (loginAsync.Result != ShaLoginResultType.Success)
            {
                throw new UserFriendlyException("Your 'Admin Password' did not match the one on record.  Please try again.");
            }
            if (currentUser.IsDeleted || !currentUser.IsActive)
            {
                return(false);
            }

            if (!await PermissionChecker.IsGrantedAsync(ShaPermissionNames.Users_ResetPassword))
            {
                throw new UserFriendlyException("You are not authorized to reset passwords.");
            }

            var user = await _userManager.GetUserByIdAsync(input.UserId);

            if (user != null)
            {
                user.AddHistoryEvent("Password reset", "Password reset");
                _personRepository.GetAll().FirstOrDefault(x => x.User == user)?.AddHistoryEvent("Password reset", "Password reset");

                user.Password = _passwordHasher.HashPassword(user, input.NewPassword);
                CurrentUnitOfWork.SaveChanges();
            }

            return(true);
        }
Ejemplo n.º 7
0
        protected virtual async Task <AbpUserAuthConfigDto> GetUserAuthConfig()
        {
            var config = new AbpUserAuthConfigDto();

            var allPermissionNames     = PermissionManager.GetAllPermissions(false).Select(p => p.Name).ToList();
            var grantedPermissionNames = new List <string>();

            if (AbpSession.UserId.HasValue)
            {
                foreach (var permissionName in allPermissionNames)
                {
                    if (await PermissionChecker.IsGrantedAsync(permissionName))
                    {
                        grantedPermissionNames.Add(permissionName);
                    }
                }
            }

            config.AllPermissions     = allPermissionNames.ToDictionary(permissionName => permissionName, permissionName => "true");
            config.GrantedPermissions = grantedPermissionNames.ToDictionary(permissionName => permissionName, permissionName => "true");

            return(config);
        }
Ejemplo n.º 8
0
        public async Task AuthorizeAsync(IEnumerable <IBaseAuthorizeAttribute> authorizeAttributes)
        {
            //2.检查session 是否有用户登陆记录,如果用户未登陆,那么直接异常
            if (!Session.UserId.HasValue)
            {
                throw new Exception($"UserId={Session.UserId}:未授权");
            }

            bool isGrant = false;;

            //检查特性是否有授权
            foreach (var authorizeAttribute in authorizeAttributes)
            {
                if (authorizeAttribute.Permissions.IsNullOrEmpty())
                {
                    continue;
                }
                foreach (var pName in authorizeAttribute.Permissions)
                {
                    if (await PermissionChecker.IsGrantedAsync(pName))
                    {
                        isGrant = true;
                        break;
                    }
                }
            }

            if (isGrant)
            {
                return;
            }
            else
            {
                throw new Exception($"UserId={Session.UserId}:未授权");
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Checks if current user is granted for a permission.
 /// </summary>
 /// <param name="permissionName">Name of the permission</param>
 protected Task <bool> IsGrantedAsync(string permissionName)
 {
     return(PermissionChecker.IsGrantedAsync(permissionName));
 }
        private async Task <int> FillUserMenuItems(UserIdentifier user, IList <MenuItemDefinition> menuItemDefinitions, IList <UserMenuItem> userMenuItems)
        {
            //TODO: Can be optimized by re-using FeatureDependencyContext.

            var addedMenuItemCount = 0;

            using (var featureDependencyContext = _iocResolver.ResolveAsDisposable <FeatureDependencyContext>())
            {
                featureDependencyContext.Object.TenantId = user == null ? null : user.TenantId;

                foreach (var menuItemDefinition in menuItemDefinitions)
                {
                    if (menuItemDefinition.RequiresAuthentication && user == null)
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(menuItemDefinition.RequiredPermissionName) && (user == null || !(await PermissionChecker.IsGrantedAsync(user, menuItemDefinition.RequiredPermissionName))))
                    {
                        continue;
                    }

                    if (menuItemDefinition.FeatureDependency != null &&
                        (AbpSession.MultiTenancySide == MultiTenancySides.Tenant || (user != null && user.TenantId != null)) &&
                        !(await menuItemDefinition.FeatureDependency.IsSatisfiedAsync(featureDependencyContext.Object)))
                    {
                        continue;
                    }

                    var userMenuItem = new UserMenuItem(menuItemDefinition, _localizationContext);
                    if (menuItemDefinition.IsLeaf || (await FillUserMenuItems(user, menuItemDefinition.Items, userMenuItem.Items)) > 0)
                    {
                        userMenuItems.Add(userMenuItem);
                        ++addedMenuItemCount;
                    }
                }
            }

            return(addedMenuItemCount);
        }
Ejemplo n.º 11
0
 private async Task <bool> IsGrantedAsync(string permissionName)
 {
     return(await PermissionChecker.IsGrantedAsync(testUser.ToUserIdentifier(), permissionName));
 }
 private async Task <bool> IsGrantedAsync(string permissionName)
 {
     return(await PermissionChecker.IsGrantedAsync(_testUser.Id, permissionName));
 }
Ejemplo n.º 13
0
        private async Task <int> FillUserMenuItems(int?tenantId, long?userId, IList <MenuItemDefinition> menuItemDefinitions, IList <UserMenuItem> userMenuItems)
        {
            var addedMenuItemCount = 0;

            using (var featureDependencyContext = _iocResolver.ResolveAsDisposable <FeatureDependencyContext>())
            {
                featureDependencyContext.Object.TenantId = tenantId;

                foreach (var menuItemDefinition in menuItemDefinitions)
                {
                    if (menuItemDefinition.RequiresAuthentication && !userId.HasValue)
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(menuItemDefinition.RequiredPermissionName) && (!userId.HasValue || !(await PermissionChecker.IsGrantedAsync(userId.Value, menuItemDefinition.RequiredPermissionName))))
                    {
                        continue;
                    }

                    if (menuItemDefinition.FeatureDependency != null &&
                        (AbpSession.MultiTenancySide == MultiTenancySides.Tenant || tenantId.HasValue) &&
                        !(await menuItemDefinition.FeatureDependency.IsSatisfiedAsync(featureDependencyContext.Object)))
                    {
                        continue;
                    }

                    var userMenuItem = new UserMenuItem(menuItemDefinition, _localizationContext);
                    if (menuItemDefinition.IsLeaf || (await FillUserMenuItems(tenantId, userId, menuItemDefinition.Items, userMenuItem.Items)) > 0)
                    {
                        userMenuItems.Add(userMenuItem);
                        ++addedMenuItemCount;
                    }
                }
            }

            return(addedMenuItemCount);
        }
        protected virtual async Task <ListResultDto <SettingGroupDto> > GetAllForProviderAsync(string providerName, string providerKey)
        {
            var settingGroups = new List <SettingGroupDto>();

            // 无权限返回空结果,直接报错的话,网关聚合会抛出异常
            if (await PermissionChecker.IsGrantedAsync(AliyunSettingPermissionNames.Settings))
            {
                var aliyunSettingGroup = new SettingGroupDto(L["DisplayName:Aliyun"], L["Description:Aliyun"]);
                #region 访问控制

                var ramSetting = aliyunSettingGroup.AddSetting(L["DisplayName:Aliyun.RAM"], L["Description:Aliyun.RAM"]);

                ramSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSettingNames.Authorization.RegionId),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSettingNames.Authorization.RegionId, providerName, providerKey),
                    ValueType.String);
                ramSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSettingNames.Authorization.AccessKeyId),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSettingNames.Authorization.AccessKeyId, providerName, providerKey),
                    ValueType.String);
                ramSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSettingNames.Authorization.AccessKeySecret),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSettingNames.Authorization.AccessKeySecret, providerName, providerKey),
                    ValueType.String);
                ramSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSettingNames.Authorization.RamRoleArn),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSettingNames.Authorization.RamRoleArn, providerName, providerKey),
                    ValueType.String);
                ramSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSettingNames.Authorization.RoleSessionName),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSettingNames.Authorization.RoleSessionName, providerName, providerKey),
                    ValueType.String);
                ramSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSettingNames.Authorization.Policy),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSettingNames.Authorization.Policy, providerName, providerKey),
                    ValueType.String);
                ramSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSettingNames.Authorization.UseSecurityTokenService),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSettingNames.Authorization.UseSecurityTokenService, providerName, providerKey),
                    ValueType.Boolean);
                ramSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSettingNames.Authorization.DurationSeconds),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSettingNames.Authorization.DurationSeconds, providerName, providerKey),
                    ValueType.Number);

                #endregion

                #region 短信

                var smsSetting = aliyunSettingGroup.AddSetting(L["DisplayName:Aliyun.Sms"], L["Description:Aliyun.Sms"]);
                smsSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSmsSettingNames.Sms.Domain),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSmsSettingNames.Sms.Domain, providerName, providerKey),
                    ValueType.String);
                smsSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSmsSettingNames.Sms.Version),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSmsSettingNames.Sms.Version, providerName, providerKey),
                    ValueType.String);
                smsSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSmsSettingNames.Sms.ActionName),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSmsSettingNames.Sms.ActionName, providerName, providerKey),
                    ValueType.String);
                smsSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSmsSettingNames.Sms.DefaultPhoneNumber),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSmsSettingNames.Sms.DefaultPhoneNumber, providerName, providerKey),
                    ValueType.String);
                smsSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSmsSettingNames.Sms.DefaultSignName),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSmsSettingNames.Sms.DefaultSignName, providerName, providerKey),
                    ValueType.String);
                smsSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSmsSettingNames.Sms.DefaultTemplateCode),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSmsSettingNames.Sms.DefaultTemplateCode, providerName, providerKey),
                    ValueType.String);
                smsSetting.AddDetail(
                    SettingDefinitionManager.Get(AliyunSmsSettingNames.Sms.VisableErrorToClient),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(AliyunSmsSettingNames.Sms.VisableErrorToClient, providerName, providerKey),
                    ValueType.Boolean);

                #endregion

                settingGroups.Add(aliyunSettingGroup);
            }

            return(new ListResultDto <SettingGroupDto>(settingGroups));
        }
Ejemplo n.º 15
0
        private async Task <int> FillUserMenuItems(long?userId, IList <MenuItemDefinition> menuItemDefinitions, IList <UserMenuItem> userMenuItems)
        {
            var addedMenuItemCount = 0;

            foreach (var menuItemDefinition in menuItemDefinitions)
            {
                if (menuItemDefinition.RequiresAuthentication && !userId.HasValue)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(menuItemDefinition.RequiredPermissionName) && (!userId.HasValue || !(await PermissionChecker.IsGrantedAsync(userId.Value, menuItemDefinition.RequiredPermissionName))))
                {
                    continue;
                }

                if (menuItemDefinition.FeatureDependency != null &&
                    AbpSession.MultiTenancySide == MultiTenancySides.Tenant &&
                    !(await menuItemDefinition.FeatureDependency.IsSatisfiedAsync(_featureDependencyContext)))
                {
                    continue;
                }

                var userMenuItem = new UserMenuItem(menuItemDefinition);
                if (menuItemDefinition.IsLeaf || (await FillUserMenuItems(userId, menuItemDefinition.Items, userMenuItem.Items)) > 0)
                {
                    userMenuItems.Add(userMenuItem);
                    ++addedMenuItemCount;
                }
            }

            return(addedMenuItemCount);
        }
Ejemplo n.º 16
0
        public virtual Task <bool> GetGrantedPermissionsAsync(string permissionName)
        {
            //return PermissionChecker.IsGranted(UserIdentifier.Parse(AbpClaimTypes.UserId), permissionName);

            return(PermissionChecker.IsGrantedAsync(permissionName));
        }
Ejemplo n.º 17
0
        public async Task<JsonResult> Authenticate([FromBody] AuthenticateModel model)
        { 
            //AuthenticateResultModel 返回的字典类型
            SortedDictionary<string, object> DgDict = new SortedDictionary<string, object>();
            //返回登录结果
            var loginResult = await GetLoginResultAsync(
                model.UserNameOrEmailAddress,
                model.Password,
                GetTenancyNameOrNull()
            );
            AbpClaimTypes.UserId = loginResult.User.Id.ToString();
            #region 角色列表版本  暂时没用
            DgDict.Add("permissionsToRolesVersion", 1001);
            #endregion
           
            #region 获取所有权限列表
            var Permissions = PermissionManager.GetAllPermissions();
            Treelist = new List<TreeClass>();
            TreeClass treeClass1 = new TreeClass();
            treeClass1.id = 1;
            treeClass1.parentId = 0;
            treeClass1.label = Mapper.Map<PermissionDto>(Permissions.Where(x => x.Name == PermissionNames.Pages_Staff).FirstOrDefault()).DisplayName;
            treeClass1.Permission = Mapper.Map<PermissionDto>(Permissions.Where(x => x.Name == PermissionNames.Pages_Staff).FirstOrDefault());           
            Treelist = Recursion(Permissions.Where(x => x.Name == PermissionNames.Pages_Staff).FirstOrDefault(), 1);
            Treelist.Add(treeClass1);
            DgDict.Add("allPermissions", new ListResultDto<PermissionDto>(
                ObjectMapper.Map<List<PermissionDto>>(Permissions)
            ));
            try
            { 
                DgDict.Add("allPermissionsForTree", Treelist);
            }
            catch (Exception ex)
            {

            }
            num = 1;
            //权限列表
            List<Permission> allPermissions = new List<Permission>();
            foreach (var item in Permissions)
            {
                allPermissions.Add(item);
            }
            #endregion
           
            #region 角色列表
            //var allRoles = await _roleRepository.GetAllListAsync();
            var allRoleIReadOnlyList = await _roleRepository.GetAllListAsync();
            List<Role> allRoles = new List<Role>();
            foreach (var item in allRoleIReadOnlyList.Where(x=>x.IsDeleted==false).ToList())
            {
                allRoles.Add(item);
            }
            DgDict.Add("allRoles", Mapper.Map<List<RoleListDto>>(allRoles));
            //DgDict.Add("allRoles", new ListResultDto<RoleListDto>(ObjectMapper.Map<List<RoleListDto>>(allRoles)));

            //new ListResultDto<RoleListDto>(ObjectMapper.Map<List<RoleListDto>>(allRoles));

            #endregion
            //获取登录用户的所拥有的所有权限
            var grantedPermissionNames = new List<string>();
            if (loginResult.User.Id>0)
            {
                foreach (var permissionName in allPermissions)
                {
                   Abp.UserIdentifier Identifier=UserIdentifier.Parse(loginResult.User.Id.ToString());
                    if (await PermissionChecker.IsGrantedAsync(Identifier, permissionName.Name))
                    {
                        grantedPermissionNames.Add(permissionName.Name);  // 获取当前用户的权限
                    }
                }
            }
          
            #region  是否有审核权 canAssignInspectionToOther
            bool canAssignInspectionToOther = await PermissionChecker.IsGrantedAsync(UserIdentifier.Parse(loginResult.User.Id.ToString()), PermissionNames.Pages_Inspection);
            if (!canAssignInspectionToOther)
            {
                DgDict.Add("canAssignInspectionToOther", "没有Pages_Inspection");
                DgDict.Add("canAssignInspectionToOtherValue", false);
            }
            else
            {
                DgDict.Add("canAssignInspectionToOther", "拥有Pages_Inspection");
                DgDict.Add("canAssignInspectionToOtherValue", true);
            }
            #endregion

            bool canAssignRolesFromAdmin = await PermissionChecker.IsGrantedAsync(UserIdentifier.Parse(loginResult.User.Id.ToString()), PermissionNames.Pages_Tenants);
            bool canAssignRolesFromRQAdmin = await PermissionChecker.IsGrantedAsync(UserIdentifier.Parse(loginResult.User.Id.ToString()), PermissionNames.Pages_Admin);
            bool canAssignRolesFromRQAssitant = await PermissionChecker.IsGrantedAsync(UserIdentifier.Parse(loginResult.User.Id.ToString()), PermissionNames.Pages_RQAssitant);
 
            #region 可分配角色列表--针对员工管理

            List<Role> RolescanAssigned = allRoles;
            List<string> RolescanAssignedString = new List<string>();//角色名数组初始化
            foreach (var item in allRoleIReadOnlyList.Where(x => x.IsDeleted == false).ToList())
            {
                RolescanAssignedString.Add(item.Name);
            }
            //如果任务已经分配且未分配给自己,且不具有分配任务权限,则抛出异常
            if (canAssignRolesFromAdmin) 
            {
                List<Role> allmyRoles = new List<Role>();//当前用户可分配的角色 初始化
                string[] outAdmin = { "Admin"};
                foreach (var item in outAdmin)
                {
                    if (RolescanAssignedString.Contains(item))
                    {
                        RolescanAssignedString.Remove(item);
                    }  //item.SetNormalizedName in
                }
                foreach (var itemStr in RolescanAssignedString)
                {
                    foreach (var item in allRoles)
                    {
                        if (item.Name == itemStr)
                        {
                            allmyRoles.Add(item);
                        }
                    }
                }
                DgDict.Add("RolescanAssigned", Mapper.Map<List<RoleDto>>(allmyRoles));
            }
            else if (canAssignRolesFromRQAdmin)
            {
                List<Role> allmyRoles = new List<Role>();//当前用户可分配的角色 初始化
                string[] outAdmin = { "Admin","RQAdmin","RQAdminPermissions"};
                foreach (var item in outAdmin)
                {
                    if (RolescanAssignedString.Contains(item))
                    {
                        RolescanAssignedString.Remove(item);
                    }  //item.SetNormalizedName in
                }
                foreach (var itemStr in RolescanAssignedString)
                {
                    foreach (var item in allRoles)
                    {
                        if (item.Name == itemStr)
                        {
                            allmyRoles.Add(item);
                        }
                    }
                }
                DgDict.Add("RolescanAssigned", Mapper.Map<List<RoleDto>>(allmyRoles));

            }
            else if (canAssignRolesFromRQAssitant)
            {
                string[] outAdmin = { "Admin", "RQAssitantPermissions",
                    "RQAdmin" , "RQAssitant" ,"RQAdminPermissions"};
                List<Role> allmyRoles = new List<Role>();//当前用户可分配的角色 初始化
                foreach (var item in outAdmin)
                {
                    if (RolescanAssignedString.Contains(item))
                    {
                        RolescanAssignedString.Remove(item);
                    }  //item.SetNormalizedName in
                }
                foreach (var itemStr in RolescanAssignedString)
                {
                    foreach (var item in allRoles)
                    {
                        if (item.Name == itemStr)
                        {
                            allmyRoles.Add(item);
                        }
                    }
                }
                DgDict.Add("RolescanAssigned", Mapper.Map<List<RoleDto>>(allmyRoles));

            }
            else
            { 
                DgDict.Add("RolescanAssigned", null);
            }
            #endregion
            
            #region 可分配权限列表【角色管理-分配权限】
            var PermissionscanAssigned = allPermissions;
            List<string> PermissionscanAssignedString = new List<string>();
            foreach (var item in PermissionscanAssigned)
            {
                PermissionscanAssignedString.Add(item.Name);
            }

            if (canAssignRolesFromAdmin) 
            {
                DgDict.Add("PermissionscanAssigned", Mapper.Map<List<PermissionDto>>(PermissionscanAssigned));
            }
            else if (canAssignRolesFromRQAdmin)
            {
                List<Permission> allMyPermission = new List<Permission>();//当前用户可分配的权限 初始化
                string[] outAdmin = {"Pages","Pages.Tenants",
                    "Pages.Users", "Pages.Roles", "Pages.Admin",
                    "Pages.Admin.Users","Pages.Admin.Roles"
                };
                foreach (var item in outAdmin)
                {
                    if (PermissionscanAssignedString.Contains(item))
                    {
                        PermissionscanAssignedString.Remove(item);
                    }  
                }
                foreach (var itemStr in PermissionscanAssignedString)
                {
                    foreach (var item in PermissionscanAssigned)
                    {
                        if (item.Name == itemStr)
                        {
                            allMyPermission.Add(item);
                        }
                    }
                }
                DgDict.Add("PermissionscanAssigned", Mapper.Map<List<PermissionDto>>(allMyPermission));

            }
            else if (canAssignRolesFromRQAssitant)
            {
                List<Permission> allMyPermission = new List<Permission>();//当前用户可分配的权限 初始化
                string[] outAdmin = {"Pages","Pages.Tenants",
                    "Pages.Users", "Pages.Roles", "Pages.Admin",
                    "Pages.Admin.Users","Pages.Admin.Roles",
                    "Pages.RQAssitant.Roles", "Pages.RQAssitant.Users",
                    "Pages.RQAssitant"
                };
                foreach (var item in outAdmin)
                {
                    if (PermissionscanAssignedString.Contains(item))
                    {
                        PermissionscanAssignedString.Remove(item);
                    }
                }
                foreach (var itemStr in PermissionscanAssignedString)
                {
                    foreach (var item in PermissionscanAssigned)
                    {
                        if (item.Name == itemStr)
                        {
                            allMyPermission.Add(item);
                        }
                    }
                }
                DgDict.Add("PermissionscanAssigned", Mapper.Map<List<PermissionDto>>(allMyPermission));

            }
            else
            {
                DgDict.Add("PermissionscanAssigned", null);
            }

            #endregion
            
            #region 登录返回UserId-accessToken--EncryptedAccessToken-ExpireInSeconds
            var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity));
            DgDict.Add("AuthenticateResultModel",
                   new AuthenticateResultModel
                   {
                       AccessToken = accessToken,
                       EncryptedAccessToken = GetEncrpyedAccessToken(accessToken),
                       ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds,
                       UserId = loginResult.User.Id
                   }
                );
            #endregion

            return Json(DgDict);
        }
Ejemplo n.º 18
0
        protected virtual async Task <ListResultDto <SettingGroupDto> > GetAllForProviderAsync(string providerName, string providerKey)
        {
            var settingGroups      = new List <SettingGroupDto>();
            var wechatSettingGroup = new SettingGroupDto(L["DisplayName:WeChat"], L["Description:WeChat"]);

            // 无权限返回空结果,直接报错的话,网关聚合会抛出异常
            if (await PermissionChecker.IsGrantedAsync(WeChatSettingPermissionNames.Official))
            {
                #region 公众号

                var officialSetting = wechatSettingGroup.AddSetting(L["DisplayName:WeChat.Official"], L["Description:WeChat.Official"]);
                officialSetting.AddDetail(
                    SettingDefinitionManager.Get(WeChatOfficialSettingNames.AppId),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(WeChatOfficialSettingNames.AppId, providerName, providerKey),
                    ValueType.String);
                officialSetting.AddDetail(
                    SettingDefinitionManager.Get(WeChatOfficialSettingNames.AppSecret),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(WeChatOfficialSettingNames.AppSecret, providerName, providerKey),
                    ValueType.String);
                officialSetting.AddDetail(
                    SettingDefinitionManager.Get(WeChatOfficialSettingNames.Url),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(WeChatOfficialSettingNames.Url, providerName, providerKey),
                    ValueType.String);
                officialSetting.AddDetail(
                    SettingDefinitionManager.Get(WeChatOfficialSettingNames.Token),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(WeChatOfficialSettingNames.Token, providerName, providerKey),
                    ValueType.String);
                officialSetting.AddDetail(
                    SettingDefinitionManager.Get(WeChatOfficialSettingNames.EncodingAESKey),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(WeChatOfficialSettingNames.EncodingAESKey, providerName, providerKey),
                    ValueType.String);

                #endregion
            }

            if (await PermissionChecker.IsGrantedAsync(WeChatSettingPermissionNames.MiniProgram))
            {
                #region 小程序

                var miniProgramSetting = wechatSettingGroup.AddSetting(L["DisplayName:WeChat.MiniProgram"], L["Description:WeChat.MiniProgram"]);
                miniProgramSetting.AddDetail(
                    SettingDefinitionManager.Get(WeChatMiniProgramSettingNames.AppId),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(WeChatMiniProgramSettingNames.AppId, providerName, providerKey),
                    ValueType.String);
                miniProgramSetting.AddDetail(
                    SettingDefinitionManager.Get(WeChatMiniProgramSettingNames.AppSecret),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(WeChatMiniProgramSettingNames.AppSecret, providerName, providerKey),
                    ValueType.String);
                miniProgramSetting.AddDetail(
                    SettingDefinitionManager.Get(WeChatMiniProgramSettingNames.Token),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(WeChatMiniProgramSettingNames.Token, providerName, providerKey),
                    ValueType.String);
                miniProgramSetting.AddDetail(
                    SettingDefinitionManager.Get(WeChatMiniProgramSettingNames.EncodingAESKey),
                    StringLocalizerFactory,
                    await SettingManager.GetOrNullAsync(WeChatMiniProgramSettingNames.EncodingAESKey, providerName, providerKey),
                    ValueType.String);

                #endregion
            }

            settingGroups.Add(wechatSettingGroup);
            return(new ListResultDto <SettingGroupDto>(settingGroups));
        }