コード例 #1
0
        public async Task <(uint totalCount, IEnumerable <MemberSearchDetails>)> SearchMembersAsync(Guid adminUserId, string term, uint offset, uint limit, string sort, CancellationToken cancellationToken)
        {
            if (Guid.Empty == adminUserId)
            {
                throw new ArgumentOutOfRangeException(nameof(adminUserId));
            }

            if (limit is < PaginationSettings.MinLimit or > PaginationSettings.MaxLimit)
            {
                throw new ArgumentOutOfRangeException(nameof(limit));
            }

            if (term.Length is < SearchSettings.TermMinimum or > SearchSettings.TermMaximum)
            {
                throw new ArgumentOutOfRangeException(nameof(term));
            }

            var userCanPerformAction = await _permissionsService.UserCanPerformActionAsync(adminUserId, ListMembersRole, cancellationToken);

            if (!userCanPerformAction)
            {
                _logger.LogError($"Error: Search Users - User:{0} does not have access to perform admin actions", adminUserId.ToString());
                throw new SecurityException($"Error: User does not have access");
            }

            cancellationToken.ThrowIfCancellationRequested();

            return(await _userCommand.SearchUsers(term, offset, limit, sort, cancellationToken));
        }