use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.
the class UserApi method modifyUser.
/**
* Modifies an existing user. Only administrators can change attributes of a user.
* <p>
* PUT /users/:id
* <p>
* email (required) - Email
* password (required) - Password
* username (required) - Username
* name (required) - Name
* skype (optional) - Skype ID
* linkedin (optional) - Linkedin
* twitter (optional) - Twitter account
* website_url (optional) - Website url
* projects_limit (optional) - Number of projects user can create
* extern_uid (optional) - External UID
* provider (optional) - External provider name
* bio (optional) - User's bio
* admin (optional) - User is admin - true or false (default)
* can_create_group (optional) - User can create groups - true or false
*
* @param user the User instance with the user info to modify
* @param password the new password for the user
* @param projectsLimit the maximum number of project
* @return the modified User instance
* @throws GitLabApiException if any exception occurs
*/
public User modifyUser(User user, String password, Integer projectsLimit) throws GitLabApiException {
Form form = userToForm(user, projectsLimit, password, false);
Response response = put(Response.Status.OK, form.asMap(), "users", user.getId());
return (response.readEntity(User.class));
}
use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.
the class GitLabApi method sudo.
/**
* Sets up all future calls to the GitLab API to be done as another user specified by sudoAsUsername.
* To revert back to normal non-sudo operation you must call unsudo(), or pass null as the username.
*
* @param sudoAsUsername the username to sudo as, null will turn off sudo
* @throws GitLabApiException if any exception occurs
*/
public void sudo(String sudoAsUsername) throws GitLabApiException {
if (sudoAsUsername == null || sudoAsUsername.trim().length() == 0) {
apiClient.setSudoAsId(null);
return;
}
// Get the User specified by username, if you are not an admin or the username is not found, this will fail
User user = getUserApi().getUser(sudoAsUsername);
if (user == null || user.getId() == null) {
throw new GitLabApiException("the specified username was not found");
}
Integer sudoAsId = user.getId();
apiClient.setSudoAsId(sudoAsId);
}
use of org.gitlab4j.api.models.User in project catma by forTEXT.
the class CustomUserApiTest method createImpersonationTokenWithExpiryAndScopes.
@Test
public void createImpersonationTokenWithExpiryAndScopes() throws Exception {
// create a user
User user = new User();
user.setEmail("testuser@catma.de");
user.setUsername("testuser");
user.setName("Test User");
user = this.gitLabApi.getUserApi().createUser(user, "password", null);
this.usersToDeleteOnTearDown.add(user.getId());
// create an impersonation token for the user, with expiresAt and scopes
GregorianCalendar cal = new GregorianCalendar();
cal.add(Calendar.DATE, 1);
Date expiryDate = cal.getTime();
PersonalAccessToken impersonationToken = this.customUserApi.createImpersonationToken(user.getId(), "test-token", expiryDate, new String[] { "api", "read_user" });
assertNotNull(impersonationToken);
assert impersonationToken.id > 0;
assertFalse(impersonationToken.revoked);
assertArrayEquals(new String[] { "api", "read_user" }, impersonationToken.scopes);
assert impersonationToken.token.length() > 0;
assert impersonationToken.active;
assert impersonationToken.impersonation;
assertEquals("test-token", impersonationToken.name);
assert impersonationToken.createdAt.length() > 0;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String expectedIsoFormattedExpiryDate = df.format(expiryDate);
assertEquals(expectedIsoFormattedExpiryDate, impersonationToken.expiresAt);
List<PersonalAccessToken> impersonationTokens = this.customUserApi.getImpersonationTokens(user.getId(), null);
assertEquals(1, impersonationTokens.size());
assertEquals(impersonationToken.id, impersonationTokens.get(0).id);
}
use of org.gitlab4j.api.models.User in project catma by forTEXT.
the class JsonLdWebAnnotationTest method tearDown.
@After
public void tearDown() throws Exception {
if (this.projectsToDeleteOnTearDown.size() > 0) {
GitProjectManager gitProjectHandler = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
for (String projectId : this.projectsToDeleteOnTearDown) {
gitProjectHandler.delete(projectId);
}
this.projectsToDeleteOnTearDown.clear();
}
if (this.directoriesToDeleteOnTearDown.size() > 0) {
for (File dir : this.directoriesToDeleteOnTearDown) {
FileUtils.deleteDirectory(dir);
}
this.directoriesToDeleteOnTearDown.clear();
}
// delete the GitLab user that the GitLabServerManager constructor in setUp would have
// created - see GitLabServerManagerTest tearDown() for more info
User user = this.gitLabServerManager.getGitLabUser();
this.gitLabServerManager.getAdminGitLabApi().getUserApi().deleteUser(user.getId());
GitLabServerManagerTest.awaitUserDeleted(this.gitLabServerManager.getAdminGitLabApi().getUserApi(), user.getId());
}
use of org.gitlab4j.api.models.User in project catma by forTEXT.
the class GitLabServerManagerTest method createAdminUser.
@Test
public void createAdminUser() throws Exception {
Integer createdUserId = this.serverManager.createUser("testadminuser@catma.de", "testadminuser", null, "Test AdminUser", true);
this.usersToDeleteOnTearDown.add(createdUserId);
assertNotNull(createdUserId);
assert createdUserId > 0;
User user = this.serverManager.getAdminGitLabApi().getUserApi().getUser(createdUserId);
assertNotNull(user);
assertEquals("testadminuser@catma.de", user.getEmail());
assertEquals("testadminuser", user.getUsername());
assertEquals("Test AdminUser", user.getName());
// assert user.getIsAdmin(); // seems to always return null
assert user.getCanCreateGroup();
assert user.getCanCreateProject();
assertEquals("active", user.getState());
}
Aggregations