Search in sources :

Example 1 with UFGroupMember

use of bio.terra.cli.serialization.userfacing.UFGroupMember in project terra-cli by DataBiosphere.

the class Group method listUsersReflectsAddRemove.

@Test
@DisplayName("list-users reflects adding and removing a user")
void listUsersReflectsAddRemove() throws IOException {
    TestUser groupCreator = TestUser.chooseTestUser();
    groupCreator.login();
    // `terra group create --name=$name`
    String name = SamGroups.randomGroupName();
    TestCommand.runCommandExpectSuccess("group", "create", "--name=" + name);
    // track the group so we can clean it up in case this test method fails
    trackedGroups.trackGroup(name, groupCreator);
    // `terra group add-user --name=$name --email=$email --policy=MEMBER`
    TestUser groupMember = TestUser.chooseTestUserWhoIsNot(groupCreator);
    TestCommand.runCommandExpectSuccess("group", "add-user", "--name=" + name, "--email=" + groupMember.email, "--policy=MEMBER");
    // check that group member is included in the list-users output with one policy
    expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.MEMBER);
    // `terra group add-user --name=$name --email=$email --policy=ADMIN`
    TestCommand.runCommandExpectSuccess("group", "add-user", "--name=" + name, "--email=" + groupMember.email, "--policy=ADMIN");
    // check that group member is included in the list-users output with two policies
    expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.MEMBER, GroupPolicy.ADMIN);
    // `terra group describe --name=$name`
    UFGroup groupDescribed = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + name);
    assertEquals(2, groupDescribed.numMembers, "group describe shows two members");
    // `terra group remove-user --name=$name --email=$email --policy=MEMBER`
    TestCommand.runCommandExpectSuccess("group", "remove-user", "--name=" + name, "--email=" + groupMember.email, "--policy=MEMBER");
    // check that group member is included in the list-users output with one policy
    expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.ADMIN);
    // `terra group remove-user --name=$name --email=$email --policy=ADMIN`
    TestCommand.runCommandExpectSuccess("group", "remove-user", "--name=" + name, "--email=" + groupMember.email, "--policy=ADMIN");
    // check that group member is no longer included in the list-users output
    Optional<UFGroupMember> listedGroupMember = listMembersWithEmail(name, groupMember.email);
    assertTrue(listedGroupMember.isEmpty(), "test user is no longer included in members list");
    // check that the group creator is included in the list-users output
    expectListedMemberWithPolicies(name, groupCreator.email, GroupPolicy.ADMIN);
    // `terra group delete --name=$name`
    TestCommand.runCommandExpectSuccess("group", "delete", "--name=" + name, "--quiet");
}
Also used : UFGroupMember(bio.terra.cli.serialization.userfacing.UFGroupMember) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with UFGroupMember

use of bio.terra.cli.serialization.userfacing.UFGroupMember in project terra-cli by DataBiosphere.

the class AddUser method execute.

/**
 * Add a user to a Terra group.
 */
@Override
protected void execute() {
    Group.Member groupMember = Group.get(groupMemberOption.groupNameOption.name).addPolicyToMember(groupMemberOption.email, groupMemberOption.policy);
    formatOption.printReturnValue(new UFGroupMember(groupMember), AddUser::printText);
}
Also used : Group(bio.terra.cli.businessobject.Group) UFGroupMember(bio.terra.cli.serialization.userfacing.UFGroupMember)

Aggregations

UFGroupMember (bio.terra.cli.serialization.userfacing.UFGroupMember)2 Group (bio.terra.cli.businessobject.Group)1 UFGroup (bio.terra.cli.serialization.userfacing.UFGroup)1 TestUser (harness.TestUser)1 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1