public async void AddUserButtonClick()
        {
            if (ActiveUser.IsActive == true)
            {
                AddUserBoardPermisionDTO dto = new AddUserBoardPermisionDTO()
                {
                    BoardId  = parentBoardId,
                    Username = NewUsername
                };

                ReadUserDTO user = await PermissionService.CreatePermission(ActiveUser.Instance.LoggedUser.Token, dto);

                if (user != null)
                {
                    ShowMessageBox(null, "Dodat user");
                    Users.Add(new ReadUser(user));
                }
                else
                {
                    ShowMessageBox(null, "Error adding user.");
                }
            }
            else
            {
                ShowMessageBox(null, "Error getting user.");
            }
        }
예제 #2
0
        public void Permission_DeletePermission_Pass()
        {
            //Arrange
            var aString           = "Rate Show";
            var permission        = new Permission(aString);
            var context           = new BroadwayBuilderContext();
            var permissionService = new PermissionService(context);

            var expected = true;
            var actual   = false;

            //Act
            permissionService.CreatePermission(permission);
            context.SaveChanges();
            permissionService.DeletePermission(permission);
            var save = context.SaveChanges();

            if (save > 0)
            {
                actual = true;
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #3
0
        public Response CreatePermission([FromBody] PermissionModel permissionModel)
        {
            Response reqResponse = new Response();

            if (permissionModel.username != "root")
            {
                reqResponse.SetResponse(401, "Not Authorized", "You are not authorized to create a permission!", null);
                goto Finish;
            }

            int userId = _userService.GetUser(permissionModel.username, permissionModel.password);

            if (userId == -1)
            {
                reqResponse.SetResponse(401, "Not Authorized", "Invalid credentials inserted!", null);
                goto Finish;
            }

            if (_permissionService.ExistsPermission(permissionModel.permissionName))
            {
                reqResponse.SetResponse(500, "Already Existing", "Permission '" + permissionModel.permissionName + "' already exists in the system.", null);
                goto Finish;
            }

            _permissionService.CreatePermission(permissionModel.permissionName, permissionModel.rights);
            reqResponse = new Response();

Finish:
            return(reqResponse);
        }
        public void SetPermission(int id, FormCollection formInfo)
        {
            //ToTest
            //int modifyUserId = Convert.ToInt32(Session["UserId"]);
            int modifyUserId = 1;
            PermissionService permissionService = new PermissionService();

            permissionService.ClearPermission(id);
            permissionService.CreatePermission(id, formInfo.AllKeys, modifyUserId);
        }
예제 #5
0
        public void AuthorizationService_UserHasPermission_Pass()
        {
            // Arrange
            BroadwayBuilderContext broadwayBuilderContext = new BroadwayBuilderContext();

            var username      = "******";
            var firstName     = "Abi";
            var lastName      = "Castro";
            int age           = 24;
            var dob           = new DateTime(1994, 1, 7);
            var city          = "San Diego";
            var stateProvince = "California";
            var country       = "United States";
            var enable        = true;

            var user       = new User(username, firstName, lastName, age, dob, city, stateProvince, country, enable);
            var permission = new Permission("RateShow", true);
            var theater    = new Theater("someTheater", "Regal", "theater st", "LA", "CA", "US", "323323");


            var expected = true;
            var actual   = false;


            var service           = new AuthorizationService(broadwayBuilderContext);
            var userService       = new UserService(broadwayBuilderContext);
            var theaterService    = new TheaterService(broadwayBuilderContext);
            var permissionService = new PermissionService(broadwayBuilderContext);

            //Adding data into tables
            permissionService.CreatePermission(permission);
            broadwayBuilderContext.SaveChanges();
            userService.CreateUser(user);
            broadwayBuilderContext.SaveChanges();
            theaterService.CreateTheater(theater);
            broadwayBuilderContext.SaveChanges();
            userService.AddUserPermission(user, permission, theater);
            broadwayBuilderContext.SaveChanges();


            // Act
            actual = service.HasPermission(user, permission, theater);

            UserPermission userPermission = userService.GetUserPermission(user, permission, theater);

            userService.DeleteUserPermission(userPermission);
            broadwayBuilderContext.SaveChanges();
            userService.DeleteUser(user);
            permissionService.DeletePermission(permission);
            theaterService.DeleteTheater(theater);
            broadwayBuilderContext.SaveChanges();

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void TestCreatePermission()
        {
            //Arrange
            Guid       id       = Guid.NewGuid();
            Permission ToCreate = new Permission()
            {
                PermissionId = id, PermissionName = "Suspend Client", Roles = CreateRoles()
            };

            //Act
            permissionService.CreatePermission(ToCreate);
            //Assert
            //Verifies the Permission has been inserted
            Assert.AreEqual(id, permissionService.GetById(id).PermissionId);
            Assert.IsTrue(permissionService.GetPermissions().Count() == 3);
        }
예제 #7
0
        public void PermissionService_GetPermission_Pass()

        {
            //Arrange

            var aString = "RateShow";

            var permission = new Permission(aString, true);

            var context = new BroadwayBuilderContext();

            var permissionService = new PermissionService(context);



            var expected = true;

            var actual = false;


            //Act

            permissionService.CreatePermission(permission);

            context.SaveChanges();



            Permission getPermission = permissionService.GetPermission(permission.PermissionID);

            if (getPermission != null)
            {
                actual = true;
            }


            permissionService.DeletePermission(permission);

            context.SaveChanges();


            //Assert

            Assert.AreEqual(expected, actual);
        }
 public void SetPermission(int id, FormCollection formInfo)
 {
     //ToTest
     //int modifyUserId = Convert.ToInt32(Session["UserId"]);
     int modifyUserId = 1;
     PermissionService permissionService = new PermissionService();
     permissionService.ClearPermission(id);
     permissionService.CreatePermission(id, formInfo.AllKeys, modifyUserId);
 }