Commit 3fb72c8f authored by Denny Ayard's avatar Denny Ayard Committed by Tim Olshansky

Fix for Setting a new Group's Visibility (#234)

* Updated getGroup to better support path arguments

* Fix for setting new-group visiblity
parent 0de85809
...@@ -2,6 +2,7 @@ package org.gitlab.api; ...@@ -2,6 +2,7 @@ package org.gitlab.api;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.gitlab.api.http.GitlabHTTPRequestor; import org.gitlab.api.http.GitlabHTTPRequestor;
import org.gitlab.api.http.Query; import org.gitlab.api.http.Query;
import org.gitlab.api.models.*; import org.gitlab.api.models.*;
...@@ -375,7 +376,7 @@ public class GitlabAPI { ...@@ -375,7 +376,7 @@ public class GitlabAPI {
* @throws IOException * @throws IOException
*/ */
public GitlabGroup getGroup(String path) 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); return retrieve().to(tailUrl, GitlabGroup.class);
} }
...@@ -499,26 +500,15 @@ public class GitlabAPI { ...@@ -499,26 +500,15 @@ public class GitlabAPI {
/** /**
* Creates a Group * Creates a Group
* *
* @param request The project-creation request * @param request An object that represents the parameters for the request.
* @param sudoUser The user to create the group on behalf of * @param sudoUser The user for whom we're creating the group
* *
* @return The GitLab Group * @return The GitLab Group
* @throws IOException on gitlab api call error * @throws IOException on gitlab api call error
*/ */
public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) throws IOException { public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) throws IOException {
Query query = request.toQuery();
Query query = new Query() query.appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null);
.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);
String tailUrl = GitlabGroup.URL + query.toString(); String tailUrl = GitlabGroup.URL + query.toString();
......
package org.gitlab.api.models; 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 class CreateGroupRequest {
public CreateGroupRequest(String name) { public CreateGroupRequest(String name) {
...@@ -18,11 +24,30 @@ public class CreateGroupRequest { ...@@ -18,11 +24,30 @@ public class CreateGroupRequest {
private String description; private String description;
private Boolean membershipLock; private Boolean membershipLock;
private Boolean shareWithGroupLock; private Boolean shareWithGroupLock;
private Boolean visibility; private GitlabVisibility visibility;
private Boolean lfsEnabled; private Boolean lfsEnabled;
private Boolean requestAccessEnabled; private Boolean requestAccessEnabled;
private Integer parentId; 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() { public String getName() {
return name; return name;
} }
...@@ -76,11 +101,11 @@ public class CreateGroupRequest { ...@@ -76,11 +101,11 @@ public class CreateGroupRequest {
return this; return this;
} }
public Boolean getVisibility() { public GitlabVisibility getVisibility() {
return visibility; return visibility;
} }
public CreateGroupRequest setVisibility(Boolean visibility) { public CreateGroupRequest setVisibility(GitlabVisibility visibility) {
this.visibility = visibility; this.visibility = visibility;
return this; return this;
} }
......
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();
}
}
\ No newline at end of file
Markdown is supported
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