Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini committed Feb 4, 2024
2 parents 8d3cdac + ce46111 commit da358ec
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/org/gitlab4j/api/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -1381,4 +1381,36 @@ public Pager<Membership> getMemberships(Long userId, int itemsPerPage) throws Gi
GitLabApiForm formData = new GitLabApiForm();
return (new Pager<>(this, Membership.class, itemsPerPage, formData.asMap(), "users", userId, "memberships"));
}

/**
* Activates the given user (admin only)
*
* <pre><code>GitLab Endpoint: POST /users/:id/activate</code></pre>
*
* @param userId the ID of the user to activate
* @throws GitLabApiException if any exception occurs.
* @since GitLab 12.4
*/
public void activateUser(Long userId) throws GitLabApiException {
if (userId == null) {
throw new RuntimeException("userId cannot be null");
}
post(Response.Status.CREATED, (Form) null, "users", userId, "activate");
}

/**
* Deactivates the given user (admin only)
*
* <pre><code>GitLab Endpoint: POST /users/:id/deactivate</code></pre>
*
* @param userId the ID of the user to deactivate
* @throws GitLabApiException if any exception occurs.
* @since GitLab 12.4
*/
public void deactivateUser(Long userId) throws GitLabApiException {
if (userId == null) {
throw new RuntimeException("userId cannot be null");
}
post(Response.Status.CREATED, (Form) null, "users", userId, "deactivate");
}
}
1 change: 1 addition & 0 deletions src/test/java/org/gitlab4j/api/PropertyConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface PropertyConstants {
String ADMIN_USERNAME_KEY = "TEST_ADMIN_USERNAME";
String ACCESS_TOKEN_KEY = "TEST_ACCESS_TOKEN";
String BLOCK_USERNAME_KEY = "TEST_BLOCK_USERNAME";
String DEACTIVATE_USERNAME_KEY = "TEST_DEACTIVATE_USERNAME";
String GROUP_KEY = "TEST_GROUP";
String GROUP_MEMBER_USERNAME_KEY = "TEST_GROUP_MEMBER_USERNAME";
String GROUP_PROJECT_KEY = "TEST_GROUP_PROJECT";
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/gitlab4j/api/TestUserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class TestUserApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_USERNAME = HelperUtils.getProperty(USERNAME_KEY);
private static final String TEST_BLOCK_USERNAME = HelperUtils.getProperty(BLOCK_USERNAME_KEY);

private static final String TEST_DEACTIVATE_USERNAME = HelperUtils.getProperty(DEACTIVATE_USERNAME_KEY);
private static final String TEST_SUDO_AS_USERNAME = HelperUtils.getProperty(SUDO_AS_USERNAME_KEY);

private static final String TEST_IMPERSONATION_TOKEN_NAME = "ipt_1";
Expand Down Expand Up @@ -130,6 +132,8 @@ public class TestUserApi extends AbstractIntegrationTest {
private static GitLabApi gitLabApi;
private static User blockUser;

private static User deactivateUser;

public TestUserApi() {
super();
}
Expand Down Expand Up @@ -167,6 +171,16 @@ public static void setup() {
} catch (Exception ignore) {}
}

if (TEST_DEACTIVATE_USERNAME != null) {
try {
deactivateUser = gitLabApi.getUserApi().getUser(TEST_DEACTIVATE_USERNAME);
if (deactivateUser != null) {
gitLabApi.getUserApi().unblockUser(deactivateUser.getId());
}
} catch (Exception ignore) {}
}


if (TEST_SSH_KEY != null) {
try {
List<SshKey> sshKeys = gitLabApi.getUserApi().getSshKeys();
Expand Down Expand Up @@ -237,6 +251,20 @@ public void testBlockUnblockUser() throws GitLabApiException {
assertNotEquals("blocked", user.getState());
}

@Test
public void testActivateDeactivateUser() throws GitLabApiException {
assumeTrue(deactivateUser != null);

assertNotEquals("deactivated", deactivateUser.getState());
gitLabApi.getUserApi().deactivateUser(deactivateUser.getId());
User user = gitLabApi.getUserApi().getUser(deactivateUser.getId());
assertEquals("deactivated", user.getState());

gitLabApi.getUserApi().activateUser(deactivateUser.getId());
user = gitLabApi.getUserApi().getUser(deactivateUser.getId());
assertNotEquals("deactivated", user.getState());
}

@Test
public void testGetOptionalUser() throws GitLabApiException {

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/test-gitlab4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TEST_USERNAME=gitlab4j
# it will be created during integration testing
TEST_SUDO_AS_USERNAME=user1
TEST_BLOCK_USERNAME=user1
TEST_DEACTIVATE_USERNAME=user1
TEST_XFER_NAMESPACE=user1
TEST_REQUEST_ACCESS_USERNAME=user1

Expand Down

0 comments on commit da358ec

Please sign in to comment.