Exemple #1
0
        private UserPermissionCacheItem GetUserPermissionCacheItem(long userId)
        {
            var cacheKey = userId + "@" + (GetCurrentTenantId() ?? 0);

            return(_cacheManager.GetUserPermissionCache().Get(cacheKey, () =>
            {
                var user = AbpStore.FindById(userId);
                if (user == null)
                {
                    return null;
                }

                var newCacheItem = new UserPermissionCacheItem(userId);

                foreach (var roleName in AbpStore.GetRoles(userId))
                {
                    newCacheItem.RoleIds.Add((RoleManager.GetRoleByName(roleName)).Id);
                }

                foreach (var permissionInfo in UserPermissionStore.GetPermissions(userId))
                {
                    if (permissionInfo.IsGranted)
                    {
                        newCacheItem.GrantedPermissions.Add(permissionInfo.Name);
                    }
                    else
                    {
                        newCacheItem.ProhibitedPermissions.Add(permissionInfo.Name);
                    }
                }

                return newCacheItem;
            }));
        }
        private async Task <UserPermissionCacheItem> GetUserPermissionCacheItemAsync(long userId)
        {
            return(await _cacheManager.GetUserPermissionCache().GetAsync(userId, async() =>
            {
                var newCacheItem = new UserPermissionCacheItem(userId);

                foreach (var roleName in await GetRolesAsync(userId))
                {
                    newCacheItem.RoleIds.Add((await RoleManager.GetRoleByNameAsync(roleName)).Id);
                }

                foreach (var permissionInfo in await UserPermissionStore.GetPermissionsAsync(userId))
                {
                    if (permissionInfo.IsGranted)
                    {
                        newCacheItem.GrantedPermissions.Add(permissionInfo.Name);
                    }
                    else
                    {
                        newCacheItem.ProhibitedPermissions.Add(permissionInfo.Name);
                    }
                }

                return newCacheItem;
            }));
        }
Exemple #3
0
        private async Task <UserPermissionCacheItem> GetUserPermissionCacheItemAsync(long userId)
        {
            var cacheKey = userId + "@" + (GetCurrentTenantId() ?? 0);

            return(await _cacheManager.GetUserPermissionCache().GetAsync(cacheKey, async() =>
            {
                var user = await FindByIdAsync(userId);
                if (user == null)
                {
                    return null;
                }

                var newCacheItem = new UserPermissionCacheItem(userId);

                foreach (var roleName in await GetRolesAsync(userId))
                {
                    newCacheItem.RoleIds.Add((await RoleManager.GetRoleByNameAsync(roleName)).Id);
                }

                foreach (var permissionInfo in await UserPermissionStore.GetPermissionsAsync(userId))
                {
                    if (permissionInfo.IsGranted)
                    {
                        newCacheItem.GrantedPermissions.Add(permissionInfo.Name);
                    }
                    else
                    {
                        newCacheItem.ProhibitedPermissions.Add(permissionInfo.Name);
                    }
                }

                return newCacheItem;
            }));
        }