Ejemplo n.º 1
0
        public async Task <AccessRightResponse> GetRights(int itemsPerPage, int pageNumber, string mask = null)
        {
            try
            {
                if (itemsPerPage < 1 || pageNumber < 1 || int.MaxValue / itemsPerPage < pageNumber || mask?.Trim().Length > 100)
                {
                    return(new AccessRightResponse
                    {
                        Status = ActionStatus.Warning,
                        Message = "BadRequest"
                    });
                }

                var rights = await
                             _securityContext.GetRights(itemsPerPage, pageNumber, mask?.Trim() ?? "");

                return(new AccessRightResponse
                {
                    AccessRights = _mapper.Map <AccessRight[]>(rights.Rights),
                    TotalCount = rights.TotalCount,
                    Status = ActionStatus.Success
                });
            }
            catch (SecurityDbException e)
            {
                return(new AccessRightResponse
                {
                    Status = ActionStatus.Warning,
                    Message = PrettyExceptionHelper.GetMessage(e)
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new AccessRightResponse
                {
                    Status = ActionStatus.Error,
                    Message = "Something went wrong!"
                });
            }
        }
Ejemplo n.º 2
0
        public async Task Test1()
        {
            var right = await _data.GetRights(10, 1, "");

            Assert.IsTrue(right.TotalCount == 3);

            var features = await _data.GetFeatures(10, 1, "");

            Assert.IsTrue(features.TotalCount == 3);
            Assert.IsTrue(features.Features.SelectMany(l => l.AvailableAccessRights).Count() == 5);

            var functions = await _data.GetFunctions(10, 1, "");

            Assert.IsTrue(functions.TotalCount == 3);
            Assert.IsTrue(functions.Functions.SelectMany(l => l.AccessRights).Count() == 5);

            var roles = await _data.GetRoles(10, 1, "");

            Assert.IsTrue(roles.TotalCount == 3);
            Assert.IsTrue(roles.Roles.SelectMany(l => l.AccessRights).Count() == 3);
            Assert.IsTrue(roles.Roles.SelectMany(l => l.DeniedRights).Count() == 2);
            Assert.IsTrue(roles.Roles.SelectMany(l => l.AccessFunctions).Count() == 2);

            var userRights = await _data.GetUserRights("1");

            Assert.IsTrue(userRights.AccessRights.Count() == 1);
            Assert.IsTrue(userRights.DeniedRights.Count() == 1);
            Assert.IsTrue(userRights.AccessFunctions.Count() == 2);
            Assert.IsTrue(userRights.Roles.Count() == 1);

            Assert.IsTrue(await _data.EditUserRights("1", new[] { 2, 3 }, new[] { 2 }, new[] { 2 }, new int[0]));

            var userRights2 = await _data.GetUserRights("1");

            Assert.IsTrue(userRights2.AccessRights.Count() == 1);
            Assert.IsTrue(!userRights2.DeniedRights.Any());
            Assert.IsTrue(userRights2.AccessFunctions.Count() == 1);
            Assert.IsTrue(userRights2.Roles.Count() == 2);
        }