Search in sources :

Example 11 with BanOnVo

use of cz.metacentrum.perun.core.api.BanOnVo in project perun by CESNET.

the class VosManagerEntryIntegrationTest method removeBanCorrectly.

@Test
public void removeBanCorrectly() throws Exception {
    System.out.println(CLASS_NAME + "removeBanCorrectly");
    Vo createdVo = vosManagerEntry.createVo(sess, myVo);
    Member member = createMemberFromExtSource(createdVo);
    BanOnVo ban = new BanOnVo();
    ban.setMemberId(member.getId());
    vosManagerEntry.setBan(sess, ban);
    vosManagerEntry.removeBan(sess, ban.getId());
    assertThatExceptionOfType(BanNotExistsException.class).isThrownBy(() -> vosManagerEntry.getBanById(sess, ban.getId()));
}
Also used : BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) Vo(cz.metacentrum.perun.core.api.Vo) Member(cz.metacentrum.perun.core.api.Member) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 12 with BanOnVo

use of cz.metacentrum.perun.core.api.BanOnVo in project perun by CESNET.

the class VosManagerImplIntegrationTest method removeBan.

@Test
public void removeBan() throws Exception {
    System.out.println(CLASS_NAME + "removeBan");
    BanOnVo originBan = new BanOnVo(-1, member.getId(), vo.getId(), new Date(), "noob");
    vosManagerImpl.setBan(sess, originBan);
    vosManagerImpl.removeBan(sess, originBan.getId());
    assertThatExceptionOfType(BanNotExistsException.class).isThrownBy(() -> vosManagerImpl.getBanById(sess, originBan.getId()));
}
Also used : BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) Date(java.util.Date) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 13 with BanOnVo

use of cz.metacentrum.perun.core.api.BanOnVo in project perun by CESNET.

the class VosManagerBlImpl method removeBanForMember.

@Override
public void removeBanForMember(PerunSession sess, int memberId) throws BanNotExistsException {
    BanOnVo ban = vosManagerImpl.getBanForMember(sess, memberId);
    removeBan(sess, ban.getId());
}
Also used : BanOnVo(cz.metacentrum.perun.core.api.BanOnVo)

Example 14 with BanOnVo

use of cz.metacentrum.perun.core.api.BanOnVo in project perun by CESNET.

the class VosManagerBlImpl method removeBan.

@Override
public void removeBan(PerunSession sess, int banId) throws BanNotExistsException {
    BanOnVo ban = vosManagerImpl.getBanById(sess, banId);
    vosManagerImpl.removeBan(sess, banId);
    Member member;
    try {
        member = perunBl.getMembersManagerBl().getMemberById(sess, ban.getMemberId());
    } catch (MemberNotExistsException e) {
        // shouldn't happen
        log.error("Failed to find member who was just banned.", e);
        throw new ConsistencyErrorException("Failed to find member who was just banned.", e);
    }
    perunBl.getAuditer().log(sess, new MemberUnsuspended(member));
}
Also used : MemberUnsuspended(cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberUnsuspended) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) Member(cz.metacentrum.perun.core.api.Member)

Example 15 with BanOnVo

use of cz.metacentrum.perun.core.api.BanOnVo in project perun by CESNET.

the class MembersManagerEntryIntegrationTest method moveMembershipMovesBans.

@Test
public void moveMembershipMovesBans() throws Exception {
    System.out.println(CLASS_NAME + "moveMembershipMovesBans");
    User sourceUser = perun.getUsersManagerBl().getUserByMember(sess, createdMember);
    Member member = setUpMember(createdVo);
    User targetUser = perun.getUsersManagerBl().getUserByMember(sess, member);
    // delete member - member was created just to create target user
    perun.getMembersManager().deleteMember(sess, member);
    // create resource and assign it to createdGroup
    Facility facility = new Facility(0, "TESTING Facility", "TESTING Facility");
    facility = perun.getFacilitiesManagerBl().createFacility(sess, facility);
    Resource resource = new Resource(0, "TESTING Resource", "TESTING Resource", facility.getId(), createdVo.getId());
    resource = perun.getResourcesManagerBl().createResource(sess, resource, createdVo, facility);
    perun.getResourcesManagerBl().assignGroupToResource(sess, createdGroup, resource, false, false, false);
    LocalDate today = LocalDate.now();
    Date tommorow = Date.from(today.plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant());
    BanOnVo banOnVo = new BanOnVo(-1, createdMember.getId(), createdMember.getVoId(), tommorow, "ban");
    perun.getVosManagerBl().setBan(sess, banOnVo);
    BanOnResource banOnResource = new BanOnResource(-1, tommorow, "ban", createdMember.getId(), resource.getId());
    perun.getResourcesManagerBl().setBan(sess, banOnResource);
    perun.getMembersManager().moveMembership(sess, createdVo, sourceUser, targetUser);
    Member targetMember = perun.getMembersManagerBl().getMemberByUser(sess, createdVo, targetUser);
    assertTrue("Ban on VO should be moved from the source member to the target member.", perun.getVosManagerBl().getBanForMember(sess, targetMember.getId()).isPresent());
    // Ban on resource should be moved from the source member to the target member
    BanOnResource actualBanOnResource = perun.getResourcesManagerBl().getBan(sess, targetMember.getId(), resource.getId());
    banOnResource.setId(actualBanOnResource.getId());
    banOnResource.setMemberId(targetMember.getId());
    assertEquals(banOnResource, actualBanOnResource);
    assertThat(perun.getResourcesManagerBl().getBansForMember(sess, targetMember.getId())).containsExactlyInAnyOrder(banOnResource);
}
Also used : BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) User(cz.metacentrum.perun.core.api.User) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) Facility(cz.metacentrum.perun.core.api.Facility) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)22 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)13 Test (org.junit.Test)13 Member (cz.metacentrum.perun.core.api.Member)9 Vo (cz.metacentrum.perun.core.api.Vo)8 Date (java.util.Date)8 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)3 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)3 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)2 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)2 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 LocalDate (java.time.LocalDate)2 MemberUnsuspended (cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberUnsuspended)1 Attribute (cz.metacentrum.perun.core.api.Attribute)1 Facility (cz.metacentrum.perun.core.api.Facility)1 Resource (cz.metacentrum.perun.core.api.Resource)1 RichMember (cz.metacentrum.perun.core.api.RichMember)1 User (cz.metacentrum.perun.core.api.User)1 BanAlreadyExistsException (cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1