Search in sources :

Example 26 with User

use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.

the class UserApi method getActiveUsers.

/**
 * Get a list of active users. Only returns the first page
 * <p>
 * GET /users?active=true
 *
 * @return a list of active Users, this list will only contain the first 100 users in the system.
 * @throws GitLabApiException if any exception occurs
 */
public List<User> getActiveUsers() throws GitLabApiException {
    GitLabApiForm formData = new GitLabApiForm().withParam("active", true).withParam(PER_PAGE_PARAM, getDefaultPerPage());
    Response response = get(Response.Status.OK, formData.asMap(), "users");
    return (response.readEntity(new GenericType<List<User>>() {
    }));
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) User(org.gitlab4j.api.models.User)

Example 27 with User

use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.

the class UserApi method findUsers.

/**
 * Search users by Email or username in the specified page range.
 * <p>
 * GET /users?search=:email_or_username
 *
 * @param emailOrUsername the email or username to search for
 * @param page            the page to get
 * @param perPage         the number of users per page
 * @return the User List with the email or username like emailOrUsername in the specified page range
 * @throws GitLabApiException if any exception occurs
 */
public List<User> findUsers(String emailOrUsername, int page, int perPage) throws GitLabApiException {
    GitLabApiForm formData = new GitLabApiForm().withParam("search", emailOrUsername, true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
    Response response = get(Response.Status.OK, formData.asMap(), "users");
    return (response.readEntity(new GenericType<List<User>>() {
    }));
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) User(org.gitlab4j.api.models.User)

Example 28 with User

use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.

the class UserApi method getBlockedUsers.

/**
 * Get a list of blocked users. Only returns the first page
 * <p>
 * GET /users?blocked=true
 *
 * @return a list of blocked Users, this list will only contain the first 100 users in the system.
 * @throws GitLabApiException if any exception occurs
 */
public List<User> getBlockedUsers() throws GitLabApiException {
    GitLabApiForm formData = new GitLabApiForm().withParam("blocked", true).withParam(PER_PAGE_PARAM, getDefaultPerPage());
    Response response = get(Response.Status.OK, formData.asMap(), "users");
    return (response.readEntity(new GenericType<List<User>>() {
    }));
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) User(org.gitlab4j.api.models.User)

Example 29 with User

use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.

the class GitLabApi method setSudoAsId.

/**
 * Sets up all future calls to the GitLab API to be done as another user specified by provided user ID.
 * To revert back to normal non-sudo operation you must call unsudo(), or pass null as the sudoAsId.
 *
 * @param sudoAsId the ID of the user to sudo as, null will turn off sudo
 * @throws GitLabApiException if any exception occurs
 */
public void setSudoAsId(Integer sudoAsId) throws GitLabApiException {
    if (sudoAsId == null) {
        apiClient.setSudoAsId(null);
        return;
    }
    // Get the User specified by the sudoAsId, if you are not an admin or the username is not found, this will fail
    User user = getUserApi().getUser(sudoAsId);
    if (user == null || !user.getId().equals(sudoAsId)) {
        throw new GitLabApiException("the specified user ID was not found");
    }
    apiClient.setSudoAsId(sudoAsId);
}
Also used : User(org.gitlab4j.api.models.User)

Aggregations

User (org.gitlab4j.api.models.User)29 Response (javax.ws.rs.core.Response)9 GitLabApiException (org.gitlab4j.api.GitLabApiException)8 GenericType (javax.ws.rs.core.GenericType)6 UserApi (org.gitlab4j.api.UserApi)6 Test (org.junit.Test)6 GitUser (de.catma.repository.git.GitUser)5 File (java.io.File)5 Project (org.gitlab4j.api.models.Project)4 IOException (java.io.IOException)3 CustomAttribute (org.gitlab4j.api.models.CustomAttribute)3 PersonalAccessToken (org.gitlab4j.api.models.PersonalAccessToken)3 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)2 IRemoteGitServerManager (de.catma.repository.git.interfaces.IRemoteGitServerManager)2 GitLabServerManagerTest (de.catma.repository.git.managers.GitLabServerManagerTest)2 PersonalAccessToken (de.catma.repository.git.managers.gitlab4j_api_custom.models.PersonalAccessToken)2 Pair (de.catma.util.Pair)2 SecureRandom (java.security.SecureRandom)2 List (java.util.List)2 Form (javax.ws.rs.core.Form)2