Пример #1
0
        public async Task <ActionResponse> EditUserRights(string userId, int[] roleIds, int[] functionIds,
                                                          int[] accessedRightsIds, int[] deniedRightsIds)
        {
            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    return(new ActionResponse
                    {
                        Message = "Wrong id",
                        Status = ActionStatus.Warning
                    });
                }

                roleIds           = roleIds ?? new int[0];
                functionIds       = functionIds ?? new int[0];
                accessedRightsIds = accessedRightsIds ?? new int[0];
                deniedRightsIds   = deniedRightsIds ?? new int[0];

                if (accessedRightsIds.Intersect(deniedRightsIds).Any())
                {
                    return(new ActionResponse
                    {
                        Status = ActionStatus.Warning,
                        Message = "Accessed and denied must not have same Rights"
                    });
                }

                await _securityContext.EditUserRights(userId, roleIds,
                                                      functionIds,
                                                      accessedRightsIds,
                                                      deniedRightsIds);

                return(new ActionResponse
                {
                    Status = ActionStatus.Success
                });
            }
            catch (SecurityDbException e)
            {
                return(new ActionResponse
                {
                    Status = ActionStatus.Warning,
                    Message = PrettyExceptionHelper.GetMessage(e)
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ActionResponse
                {
                    Status = ActionStatus.Error,
                    Message = "Something went wrong!"
                });
            }
        }
Пример #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);
        }