@Test
public void remove_component_user_permission() throws Exception {
MockUserSession.set().setLogin("admin").addProjectPermissions(UserRole.ADMIN, project.key());
UserDto user1 = new UserDto().setLogin("user1").setName("User1");
db.userDao().insert(session, user1);
UserDto user2 = new UserDto().setLogin("user2").setName("User2");
db.userDao().insert(session, user2);
session.commit();
service.addPermission(params(user1.getLogin(), null, project.key(), UserRole.USER));
service.addPermission(params(user2.getLogin(), null, project.key(), UserRole.USER));
service.removePermission(params(user1.getLogin(), null, project.key(), UserRole.USER));
session.commit();
// Check in db
assertThat(tester.get(RoleDao.class).selectUserPermissions(session, user1.getLogin(), project.getId())).isEmpty();
assertThat(tester.get(RoleDao.class).selectUserPermissions(session, user2.getLogin(), project.getId())).hasSize(1);
// Check in index
IssueAuthorizationDoc issueAuthorizationDoc = index.getNullableByKey(project.uuid());
assertThat(issueAuthorizationDoc).isNotNull();
assertThat(issueAuthorizationDoc.project()).isEqualTo(project.uuid());
assertThat(issueAuthorizationDoc.users()).containsExactly(user2.getLogin());
assertThat(issueAuthorizationDoc.groups()).isEmpty();
}