8000 Fix for Setting a new Group's Visibility by djayard · Pull Request #232 · timols/java-gitlab-api · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
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
26 changes: 8 additions & 18 deletions src/main/java/org/gitlab/api/GitlabAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.gitlab.api.http.GitlabHTTPRequestor;
import org.gitlab.api.http.Query;
import org.gitlab.api.models.*;
Expand Down Expand Up @@ -364,7 +365,7 @@ public GitlabGroup getGroup(Integer groupId) throws IOException {
* @throws IOException
*/
public GitlabGroup getGroup(String path) throws IOException {
String tailUrl = GitlabGroup.URL + "/" + path;
String tailUrl = GitlabGroup.URL + "/" + URLEncoder.encode(path, "UTF-8");
return retrieve().to(tailUrl, GitlabGroup.class);
}

Expand Down Expand Up @@ -488,27 +489,16 @@ public GitlabGroup createGroup(String name, String path, String ldapCn, GitlabAc
/**
* Creates a Group
*
* @param request The project-creation request
* @param sudoUser The user to create the group on behalf of
* @param request An object that represents the parameters for the request.
* @param sudoUser The user for whom we're creating the group
*
* @return The GitLab Group
* @throws IOException on gitlab api call error
*/
public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) throws IOException {

Query query = new Query()
.append("name", request.getName())
.append("path", request.getPath())
.appendIf("ldap_cn", request.getLdapCn())
.appendIf("description", request.getDescription())
.appendIf("membershipLock", request.getMembershipLock())
.appendIf("share_with_group_lock", request.getShareWithGroupLock())
.appendIf("visibility", request.getVisibility())
.appendIf("lfs_enabled", request.getLfsEnabled())
.appendIf("request_access_enabled", request.getRequestAccessEnabled())
.appendIf("parent_id", request.getParentId())
.appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null);

public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) throws IOException {
Query query = request.toQuery();
query.appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null);

String tailUrl = GitlabGroup.URL + query.toString();

return dispatch().to(tailUrl, GitlabGroup.class);
Expand Down
37 changes: 31 additions & 6 deletions src/main/java/org/gitlab/api/models/CreateGroupRequest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package org.gitlab.api.models;

import java.io.UnsupportedEncodingException;
import org.gitlab.api.http.Query;

/**
* The model for custom group-creation requests.
*
*/
public class CreateGroupRequest {

public CreateGroupRequest(String name) {
this(name, name);
this(name, name);
}

public CreateGroupRequest(String name, String path) {
this.name = name;
this.path = path;
this.name = name;
this.path = path;
}

private String name;
Expand All @@ -18,10 +24,29 @@ public CreateGroupRequest(String name, String path) {
private String description;
private Boolean membershipLock;
private Boolean shareWithGroupLock;
private Boolean visibility;
private GitlabVisibility visibility;
private Boolean lfsEnabled;
private Boolean requestAccessEnabled;
private Integer parentId;

/**
* Generates query representing this request's properties.
* @return {@link Query}
* @throws UnsupportedEncodingException
*/
public Query toQuery() throws UnsupportedEncodingException{
return new Query()
.append("name", name)
.append("path", path)
.appendIf("ldap_cn", ldapCn)
.appendIf("description", description)
.appendIf("membershipLock", membershipLock)
.appendIf("share_with_group_lock", shareWithGroupLock)
.appendIf("visibility", visibility != null ? visibility.toString() : null)
.appendIf("lfs_enabled", lfsEnabled)
.appendIf("request_access_enabled", requestAccessEnabled)
.appendIf("parent_id", parentId);
}

public String getName() {
return name;
Expand Down Expand Up @@ -76,11 +101,11 @@ public CreateGroupRequest setShareWithGroupLock(Boolean shareWithGroupLock) {
return this;
}

public Boolean getVisibility() {
public GitlabVisibility getVisibility() {
return visibility;
}

public CreateGroupRequest setVisibility(Boolean visibility) {
public CreateGroupRequest setVisibility(GitlabVisibility visibility) {
this.visibility = visibility;
return this;
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/gitlab/api/models/GitlabVisibility.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.gitlab.api.models;

import com.fasterxml.jackson.annotation.JsonValue;

/**
* Enum for the privacy settings supported by GitLab API v4.
*/
public enum GitlabVisibility {
PRIVATE, INTERNAL, PUBLIC;

/**
* Returns lower-case of {@link #name()}. Lower-case is required for requests
* that accept a visiblity parameter.
*/
@Override
@JsonValue
public String toString() {
return name().toLowerCase();
}
}
0