public override async Task <GetPermissionListResultDto> GetAsync(string providerName, string providerKey)
        {
            var isHostPermission = CurrentUser.UserName == "HostUser";

            await CheckProviderPolicy(providerName);

            var result = new GetPermissionListResultDto
            {
                EntityDisplayName = providerKey,
                Groups            = new List <PermissionGroupDto>()
            };

            var multiTenancySide = CurrentTenant.GetMultiTenancySide();

            foreach (var group in PermissionDefinitionManager.GetGroups().WhereIf(!isHostPermission, x =>
                                                                                  !x.Properties.ContainsKey(AbpQa263DemoConsts.IsHostPermission) ||
                                                                                  (bool)x.Properties[AbpQa263DemoConsts.IsHostPermission] == isHostPermission))
            {
                var groupDto = new PermissionGroupDto
                {
                    Name        = group.Name,
                    DisplayName = group.DisplayName.Localize(StringLocalizerFactory),
                    Permissions = new List <PermissionGrantInfoDto>()
                };

                foreach (var permission in group.GetPermissionsWithChildren().WhereIf(!isHostPermission, x =>
                                                                                      !x.Properties.ContainsKey(AbpQa263DemoConsts.IsHostPermission) ||
                                                                                      (bool)x.Properties[AbpQa263DemoConsts.IsHostPermission] == isHostPermission))
                {
                    if (!permission.IsEnabled)
                    {
                        continue;
                    }

                    if (permission.Providers.Any() && !permission.Providers.Contains(providerName))
                    {
                        continue;
                    }

                    if (!permission.MultiTenancySide.HasFlag(multiTenancySide))
                    {
                        continue;
                    }

                    var grantInfoDto = new PermissionGrantInfoDto
                    {
                        Name             = permission.Name,
                        DisplayName      = permission.DisplayName.Localize(StringLocalizerFactory),
                        ParentName       = permission.Parent?.Name,
                        AllowedProviders = permission.Providers,
                        GrantedProviders = new List <ProviderInfoDto>()
                    };

                    var grantInfo = await PermissionManager.GetAsync(permission.Name, providerName, providerKey);

                    grantInfoDto.IsGranted = grantInfo.IsGranted;

                    foreach (var provider in grantInfo.Providers)
                    {
                        grantInfoDto.GrantedProviders.Add(new ProviderInfoDto
                        {
                            ProviderName = provider.Name,
                            ProviderKey  = provider.Key,
                        });
                    }

                    groupDto.Permissions.Add(grantInfoDto);
                }

                if (groupDto.Permissions.Any())
                {
                    result.Groups.Add(groupDto);
                }
            }

            return(result);
        }
Esempio n. 2
0
        public virtual async Task <GetPermissionListResultDto> GetAsync(string providerName, string providerKey)
        {
            await CheckProviderPolicy(providerName);

            var result = new GetPermissionListResultDto
            {
                EntityDisplayName = providerKey,
                Groups            = new List <PermissionGroupDto>()
            };

            var multiTenancySide = CurrentTenant.GetMultiTenancySide();

            foreach (var group in PermissionDefinitionManager.GetGroups())
            {
                var groupDto = new PermissionGroupDto
                {
                    Name        = group.Name,
                    DisplayName = group.DisplayName.Localize(StringLocalizerFactory),
                    Permissions = new List <PermissionGrantInfoDto>()
                };

                foreach (var permission in group.GetPermissionsWithChildren())
                {
                    if (!permission.IsEnabled)
                    {
                        continue;
                    }

                    if (!await SimpleStateCheckerManager.IsEnabledAsync(permission))
                    {
                        continue;
                    }

                    if (permission.Providers.Any() && !permission.Providers.Contains(providerName))
                    {
                        continue;
                    }

                    if (!permission.MultiTenancySide.HasFlag(multiTenancySide))
                    {
                        continue;
                    }

                    var grantInfoDto = new PermissionGrantInfoDto
                    {
                        Name             = permission.Name,
                        DisplayName      = permission.DisplayName.Localize(StringLocalizerFactory),
                        ParentName       = permission.Parent?.Name,
                        AllowedProviders = permission.Providers,
                        GrantedProviders = new List <ProviderInfoDto>()
                    };

                    var grantInfo = await PermissionManager.GetAsync(permission.Name, providerName, providerKey);

                    grantInfoDto.IsGranted = grantInfo.IsGranted;

                    foreach (var provider in grantInfo.Providers)
                    {
                        grantInfoDto.GrantedProviders.Add(new ProviderInfoDto
                        {
                            ProviderName = provider.Name,
                            ProviderKey  = provider.Key,
                        });
                    }

                    groupDto.Permissions.Add(grantInfoDto);
                }

                if (groupDto.Permissions.Any())
                {
                    result.Groups.Add(groupDto);
                }
            }

            return(result);
        }
Esempio n. 3
0
        public virtual async Task <GetPermissionListResultDto> GetAsync(string providerName, string providerKey)
        {
            await CheckProviderPolicy(providerName);

            var result = new GetPermissionListResultDto
            {
                EntityDisplayName = providerKey,
                Groups            = new List <PermissionGroupDto>()
            };

            var multiTenancySide = CurrentTenant.GetMultiTenancySide();

            foreach (var group in PermissionDefinitionManager.GetGroups())
            {
                var groupDto = new PermissionGroupDto
                {
                    Name        = group.Name,
                    DisplayName = group.DisplayName.Localize(StringLocalizerFactory),
                    Permissions = new List <PermissionGrantInfoDto>()
                };

                var neededCheckPermissions = new List <PermissionDefinition>();

                foreach (var permission in group.GetPermissionsWithChildren()
                         .Where(x => x.IsEnabled)
                         .Where(x => !x.Providers.Any() || x.Providers.Contains(providerName))
                         .Where(x => x.MultiTenancySide.HasFlag(multiTenancySide)))
                {
                    if (await SimpleStateCheckerManager.IsEnabledAsync(permission))
                    {
                        neededCheckPermissions.Add(permission);
                    }
                }

                if (!neededCheckPermissions.Any())
                {
                    return(result);
                }

                var grantInfoDtos = neededCheckPermissions.Select(x => new PermissionGrantInfoDto
                {
                    Name             = x.Name,
                    DisplayName      = x.DisplayName.Localize(StringLocalizerFactory),
                    ParentName       = x.Parent?.Name,
                    AllowedProviders = x.Providers,
                    GrantedProviders = new List <ProviderInfoDto>()
                }).ToList();

                var multipleGrantInfo = await PermissionManager.GetAsync(neededCheckPermissions.Select(x => x.Name).ToArray(), providerName, providerKey);

                foreach (var grantInfo in multipleGrantInfo.Result)
                {
                    var grantInfoDto = grantInfoDtos.First(x => x.Name == grantInfo.Name);

                    grantInfoDto.IsGranted = grantInfo.IsGranted;

                    foreach (var provider in grantInfo.Providers)
                    {
                        grantInfoDto.GrantedProviders.Add(new ProviderInfoDto
                        {
                            ProviderName = provider.Name,
                            ProviderKey  = provider.Key,
                        });
                    }

                    groupDto.Permissions.Add(grantInfoDto);
                }

                if (groupDto.Permissions.Any())
                {
                    result.Groups.Add(groupDto);
                }
            }

            return(result);
        }