Unverified Commit ce461112 authored by Richard Zowalla's avatar Richard Zowalla Committed by GitHub
Browse files

Add activate and deactivate methods for users (#1081)

Add /users/:id/activate
Add /users/:id/deactivate
Adds a related test.
parent 47e9e670
......@@ -1381,4 +1381,36 @@ public class UserApi extends AbstractApi {
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");
}
}
......@@ -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";
......
......@@ -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";
......@@ -130,6 +132,8 @@ public class TestUserApi extends AbstractIntegrationTest {
private static GitLabApi gitLabApi;
private static User blockUser;
private static User deactivateUser;
public TestUserApi() {
super();
}
......@@ -167,6 +171,16 @@ public class TestUserApi extends AbstractIntegrationTest {
} 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();
......@@ -237,6 +251,20 @@ public class TestUserApi extends AbstractIntegrationTest {
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 {
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment