Skip to content

Add "approve" and "reject" user methods #1007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/main/java/org/gitlab4j/api/UserApi.java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a similar "reject user" endpoint https://docs.gitlab.com/ee/api/users.html#reject-user

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added that method as well

Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,36 @@ public Stream<User> getActiveUsersStream() throws GitLabApiException {
return (getActiveUsers(getDefaultPerPage()).stream());
}

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

/**
* Rejects specified user that is pending approval. Available only for administrators.
*
* <pre><code>GitLab Endpoint: POST /users/:id/reject</code></pre>
*
* @param userId the ID of the user to reject
* @throws GitLabApiException if any exception occurs
*/
public void rejectUser(Long userId) throws GitLabApiException {
if (userId == null) {
throw new RuntimeException("userId cannot be null");
}
post(Response.Status.OK, (Form) null, "users", userId, "reject");
}

/**
* Blocks the specified user. Available only for admin.
*
Expand Down