Search in sources :

Example 1 with Permission

use of uk.gov.pay.adminusers.model.Permission in project pay-adminusers by alphagov.

the class ServiceDaoIT method setupUsersForServiceAndRole.

private void setupUsersForServiceAndRole(String externalId, int roleId, int noOfUsers) {
    Permission perm1 = aPermission();
    Permission perm2 = aPermission();
    databaseHelper.add(perm1).add(perm2);
    Role role = role(roleId, "role-" + roleId, "role-desc-" + roleId);
    role.setPermissions(Set.of(perm1, perm2));
    databaseHelper.add(role);
    String gatewayAccountId1 = randomInt().toString();
    Service service1 = Service.from(randomInt(), externalId, new ServiceName(Service.DEFAULT_NAME_VALUE));
    databaseHelper.addService(service1, gatewayAccountId1);
    range(0, noOfUsers - 1).forEach(i -> {
        String username = randomUuid();
        String email = username + "@example.com";
        UserDbFixture.userDbFixture(databaseHelper).withServiceRole(service1, roleId).withUsername(username).withEmail(email).insertUser();
    });
    // unmatching service
    String gatewayAccountId2 = randomInt().toString();
    Integer serviceId2 = randomInt();
    String externalId2 = randomUuid();
    Service service2 = Service.from(serviceId2, externalId2, new ServiceName(Service.DEFAULT_NAME_VALUE));
    databaseHelper.addService(service2, gatewayAccountId2);
    // same user 2 diff services - should count only once
    String username3 = randomUuid();
    String email3 = username3 + "@example.com";
    User user3 = UserDbFixture.userDbFixture(databaseHelper).withServiceRole(service1, roleId).withUsername(username3).withEmail(email3).insertUser();
    databaseHelper.addUserServiceRole(user3.getId(), serviceId2, role.getId());
}
Also used : Role(uk.gov.pay.adminusers.model.Role) User(uk.gov.pay.adminusers.model.User) ServiceName(uk.gov.pay.adminusers.model.ServiceName) Permission(uk.gov.pay.adminusers.model.Permission) Service(uk.gov.pay.adminusers.model.Service)

Example 2 with Permission

use of uk.gov.pay.adminusers.model.Permission in project pay-adminusers by alphagov.

the class RoleDbFixture method insert.

public Role insert(Role role, Permission... permissions) {
    for (Permission permission : permissions) {
        databaseHelper.add(permission);
    }
    role.setPermissions(Set.of(permissions));
    databaseHelper.add(role);
    return role;
}
Also used : Permission(uk.gov.pay.adminusers.model.Permission)

Aggregations

Permission (uk.gov.pay.adminusers.model.Permission)2 Role (uk.gov.pay.adminusers.model.Role)1 Service (uk.gov.pay.adminusers.model.Service)1 ServiceName (uk.gov.pay.adminusers.model.ServiceName)1 User (uk.gov.pay.adminusers.model.User)1