Esempio n. 1
0
        public IAsyncEnumerable <UserRoleMappingIdentityViewModel> AsyncEnumerateRoleMappingIdentities(
            ulong userId,
            Optional <bool> isDeleted = default)
        {
            UsersLogMessages.UserRoleMappingIdentitiesEnumerating(_logger, userId, isDeleted);

            var query = _context.Set <UserRoleMappingEntity>()
                        .AsQueryable()
                        .Where(x => x.UserId == userId);

            RepositoryLogMessages.QueryInitializing(_logger, query);

            if (isDeleted.IsSpecified)
            {
                RepositoryLogMessages.QueryAddingWhereClause(_logger, nameof(isDeleted));
                query = isDeleted.Value
                    ? query.Where(x => x.DeletionId != null)
                    : query.Where(x => x.DeletionId == null);
            }

            RepositoryLogMessages.QueryTerminating(_logger);
            var result = query
                         .Select(UserRoleMappingIdentityViewModel.FromEntityProjection)
                         .AsAsyncEnumerable();

            RepositoryLogMessages.QueryBuilt(_logger);
            return(result);
        }
Esempio n. 2
0
        public IAsyncEnumerable <ulong> AsyncEnumerateIds(
            Optional <long> roleId = default)
        {
            UsersLogMessages.UserIdsEnumerating(_logger, roleId);

            var query = _context.Set <UserEntity>()
                        .AsQueryable();

            RepositoryLogMessages.QueryInitializing(_logger, query);

            if (roleId.IsSpecified)
            {
                RepositoryLogMessages.QueryAddingWhereClause(_logger, nameof(roleId));
                query = query.Where(u => u.RoleMappings.Any(urm =>
                                                            (urm.DeletionId == null) &&
                                                            (urm.RoleId == roleId.Value)));
            }

            RepositoryLogMessages.QueryTerminating(_logger);
            var result = query
                         .Select(u => u.Id)
                         .AsAsyncEnumerable();

            RepositoryLogMessages.QueryBuilt(_logger);
            return(result);
        }
Esempio n. 3
0
        public IAsyncEnumerable <PermissionIdentityViewModel> AsyncEnumerateGrantedPermissionIdentities(
            ulong userId)
        {
            UsersLogMessages.GrantedPermissionIdentitiesEnumerating(_logger, userId);

            var result = _context.Set <PermissionEntity>()
                         .AsQueryable()
                         .Where(p => _context.Set <UserPermissionMappingEntity>()
                                .AsQueryable()
                                .Where(upm => upm.UserId == userId)
                                .Where(upm => !upm.IsDenied)
                                .Where(upm => upm.DeletionId == null)
                                .Any(upm => upm.PermissionId == p.PermissionId) ||
                                _context.Set <RolePermissionMappingEntity>()
                                .AsQueryable()
                                .Where(rpm => _context.Set <UserRoleMappingEntity>()
                                       .AsQueryable()
                                       .Where(urm => urm.DeletionId == null)
                                       .Where(urm => urm.UserId == userId)
                                       .Any(urm => urm.RoleId == rpm.RoleId))
                                .Where(x => x.DeletionId == null)
                                .Any(rpm => rpm.PermissionId == p.PermissionId))
                         .Where(p => !_context.Set <UserPermissionMappingEntity>()
                                .AsQueryable()
                                .Where(upm => upm.UserId == userId)
                                .Where(upm => upm.IsDenied)
                                .Where(upm => upm.DeletionId == null)
                                .Any(upm => upm.PermissionId == p.PermissionId))
                         .Select(PermissionIdentityViewModel.FromEntityProjection)
                         .AsAsyncEnumerable();

            RepositoryLogMessages.QueryBuilt(_logger);
            return(result);
        }
Esempio n. 4
0
        public IAsyncEnumerable <UserOverviewViewModel> AsyncEnumerateOverviews()
        {
            UsersLogMessages.UserOverviewsEnumerating(_logger);

            var result = _context.Set <UserEntity>()
                         .Select(UserOverviewViewModel.FromEntityProjection)
                         .AsAsyncEnumerable();

            RepositoryLogMessages.QueryBuilt(_logger);
            return(result);
        }
Esempio n. 5
0
        public async Task <IReadOnlyList <long> > CreatePermissionMappingsAsync(
            ulong userId,
            IEnumerable <int> permissionIds,
            PermissionMappingType type,
            long actionId,
            CancellationToken cancellationToken)
        {
            UsersLogMessages.UserPermissionMappingsCreating(_logger, userId, permissionIds, type, actionId);

            var entities = permissionIds
                           .Do(permissionId => UsersLogMessages.UserPermissionMappingCreating(_logger, userId, permissionId, type, actionId))
                           .Select(permissionId => new UserPermissionMappingEntity(
                                       id:             default,
Esempio n. 6
0
        public IAsyncEnumerable <long> AsyncEnumerateDefaultRoleIds()
        {
            UsersLogMessages.DefaultRoleIdsEnumerating(_logger);

            var result = _context.Set <DefaultRoleMappingEntity>()
                         .AsQueryable()
                         .Where(x => x.DeletionId == null)
                         .Select(x => x.RoleId)
                         .AsAsyncEnumerable();

            RepositoryLogMessages.QueryBuilt(_logger);
            return(result);
        }
Esempio n. 7
0
        public Task <bool> AnyAsync(
            Optional <ulong> userId             = default,
            CancellationToken cancellationToken = default)
        {
            UsersLogMessages.UsersEnumeratingAny(_logger, userId);

            var query = _context.Set <UserEntity>()
                        .AsQueryable();

            RepositoryLogMessages.QueryInitializing(_logger, query);

            if (userId.IsSpecified)
            {
                RepositoryLogMessages.QueryAddingWhereClause(_logger, nameof(userId));
                query = query.Where(x => x.Id == userId.Value);
            }

            RepositoryLogMessages.QueryTerminating(_logger);
            var result = query.AnyAsync(cancellationToken);

            RepositoryLogMessages.QueryExecuting(_logger);
            return(result);
        }