Esempio n. 1
0
        public async override Task <IActionResult> ListTeamsAsync([FromQuery] bool users, [FromQuery] bool teams, [FromQuery] bool policies, [FromQuery] int page, [FromQuery, Range(1, 20)] int size, [FromQuery, StringLength(255, MinimumLength = 0)] string filterDesciption, [FromQuery] List <string> orderBy)
        {
            if (ClaimsHelper.GetDataPolicies(User).Contains("a3s.viewYourTeamsOnly"))
            {
                return(Ok(await teamService.GetListAsync(ClaimsHelper.GetScalarClaimValue <Guid>(User, ClaimTypes.NameIdentifier, Guid.Empty))));
            }

            return(Ok(await teamService.GetListAsync()));
        }
Esempio n. 2
0
        public void GetDataPolicies_GivenUnfindableClaim_ReturnsEmptyList()
        {
            // Arrange

            // Act
            List <string> lookupList = ClaimsHelper.GetDataPolicies(user);

            // Assert
            Assert.True(lookupList.Count == 0, "With an unfindable claim an empty list must be returned.");
        }
Esempio n. 3
0
        public void GetDataPolicies_GivenNullClaimsPrinicple_ReturnsEmptyList()
        {
            // Arrange

            // Act
            List <string> lookupList = ClaimsHelper.GetDataPolicies(null);

            // Assert
            Assert.True(lookupList.Count == 0, "With a null Claims Principle an empty list must be returned.");
        }
Esempio n. 4
0
        public void GetDataPolicies_GivenFindableDataPolicyClaim_ReturnsEmptyList()
        {
            // Arrange
            user.AddIdentity(new ClaimsIdentity(
                                 new Claim[]
            {
                new Claim(ClaimTypes.Name, "example name"),
                new Claim(ClaimTypes.NameIdentifier, userId),
                new Claim("custom-claim", "example claim value"),
                new Claim("dataPolicy", "data policy value 1"),
                new Claim("dataPolicy", "data policy value 2")
            }));

            // Act
            List <string> lookupList = ClaimsHelper.GetDataPolicies(user);

            // Assert
            Assert.True(lookupList.Count == 2, "With findable datapolicy claim a populated list must be returned.");
            Assert.True(string.Compare(lookupList[0], "data policy value 1") == 0, $"Expected datapolicy value 'data policy value 1' not found. Found value: '{lookupList[0]}'.");
            Assert.True(string.Compare(lookupList[1], "data policy value 2") == 0, $"Expected datapolicy value 'data policy value 2' not found. Found value: '{lookupList[1]}'.");
        }
Esempio n. 5
0
        public async override Task <IActionResult> ListTeamsAsync([FromQuery] bool includeRelations, [FromQuery] int page, [FromQuery][Range(1, 20)] int size, [FromQuery][StringLength(255, MinimumLength = 0)] string filterName, [FromQuery] string orderBy)
        {
            List <KeyValuePair <string, string> > orderByKeyValueList = orderByHelper.ConvertCommaSeparateOrderByStringToKeyValuePairList(orderBy);

            // Validate only correct order by components were supplied.
            orderByHelper.ValidateOrderByListOnlyContainsCertainElements(orderByKeyValueList, new List <string> {
                "name"
            });

            PaginatedResult <TeamModel> paginatedResult = ClaimsHelper.GetDataPolicies(User).Contains("a3s.viewYourTeamsOnly")
                ? await teamService.GetPaginatedListForMemberUserAsync(ClaimsHelper.GetUserId(User), page, size, includeRelations, filterName, orderByKeyValueList)
                : await teamService.GetPaginatedListAsync(page, size, includeRelations, filterName, orderByKeyValueList);

            // Generate a K-V pair of all the current applied filters sent to the controller so that pagination header URLs can include them.
            List <KeyValuePair <string, string> > currrentFilters = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("includeRelations", includeRelations ? "true" : "false"),
                new KeyValuePair <string, string>("filterName", filterName)
            };

            paginationHelper.AddPaginationHeaderMetaDataToResponse(paginatedResult, currrentFilters, orderBy, "ListTeams", Url, Response);

            return(Ok(mapper.Map <List <Team> >(paginatedResult.Results)));
        }