Skip to content

Commit

Permalink
Merge pull request #316 from maxixcom/features
Browse files Browse the repository at this point in the history
Help Center: Management Permission Groups / User Segments
  • Loading branch information
aheritier authored Dec 31, 2019
2 parents eafb323 + 3fa1d73 commit 6f8a723
Show file tree
Hide file tree
Showing 8 changed files with 607 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Here is the status of the various API components:
* [Help Center Articles](https://developer.zendesk.com/rest_api/docs/help_center/articles)
* [Help Center Translations](https://developer.zendesk.com/rest_api/docs/help_center/translations) - Partial (List Translations, Update Translation)
* [Help Center Subscriptions](https://developer.zendesk.com/rest_api/docs/help_center/subscriptions)
* [Help Center Management Permission Groups](https://developer.zendesk.com/rest_api/docs/help_center/permission_groups)
* [Help Center User Segments](https://developer.zendesk.com/rest_api/docs/help_center/user_segments)
* [Topic Votes](http://developer.zendesk.com/documentation/rest_api/topic_votes.html)
* [Account Settings](http://developer.zendesk.com/documentation/rest_api/account_settings.html)
* [Activity Stream](http://developer.zendesk.com/documentation/rest_api/activity_stream.html)
Expand Down
181 changes: 181 additions & 0 deletions src/main/java/org/zendesk/client/v2/Zendesk.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
import org.zendesk.client.v2.model.hc.Section;
import org.zendesk.client.v2.model.hc.Subscription;
import org.zendesk.client.v2.model.hc.Translation;
import org.zendesk.client.v2.model.hc.PermissionGroup;
import org.zendesk.client.v2.model.hc.UserSegment;
import org.zendesk.client.v2.model.schedules.Holiday;
import org.zendesk.client.v2.model.schedules.Schedule;
import org.zendesk.client.v2.model.targets.BasecampTarget;
Expand Down Expand Up @@ -1735,6 +1737,162 @@ public void deleteDynamicContentItemVariant(Long itemId, DynamicContentItemVaria
//////////////////////////////////////////////////////////////////////
// Action methods for Help Center
//////////////////////////////////////////////////////////////////////
/**
* Get all permission groups
*
* @return List of Permission Groups
*/
public Iterable<PermissionGroup> getPermissionGroups() {
return new PagedIterable<>(cnst("/guide/permission_groups.json"),
handleList(PermissionGroup.class, "permission_groups"));
}
/**
* Get permission group by id
*
* @param id
*/
public PermissionGroup getPermissionGroup(long id) {
return complete(submit(req("GET", tmpl("/guide/permission_groups/{id}.json").set("id", id)),
handle(PermissionGroup.class, "permission_group")));
}
/**
* Create permission group
*
* @param permissionGroup
*/
public PermissionGroup createPermissionGroup(PermissionGroup permissionGroup) {
return complete(submit(req("POST", tmpl("/guide/permission_groups.json"),
JSON, json(Collections.singletonMap("permission_group", permissionGroup))), handle(PermissionGroup.class, "permission_group")));
}
/**
* Update permission group
*
* @param permissionGroup
*/
public PermissionGroup updatePermissionGroup(PermissionGroup permissionGroup) {
checkHasId(permissionGroup);
return complete(submit(req("PUT", tmpl("/guide/permission_groups/{id}.json").set("id", permissionGroup.getId()),
JSON, json(Collections.singletonMap("permission_group", permissionGroup))), handle(PermissionGroup.class, "permission_group")));
}
/**
* Delete permission group
*
* @param permissionGroup
*/
public void deletePermissionGroup(PermissionGroup permissionGroup) {
checkHasId(permissionGroup);
deletePermissionGroup(permissionGroup.getId());
}
/**
* Delete permission group
*
* @param id
*/
public void deletePermissionGroup(long id) {
complete(submit(req("DELETE", tmpl("/guide/permission_groups/{id}.json").set("id", id)),
handleStatus()));
}
/**
* Get user segments
*
* @return List of User Segments
*/
public Iterable<UserSegment> getUserSegments() {
return new PagedIterable<>(cnst("/help_center/user_segments.json"),
handleList(UserSegment.class, "user_segments"));
}
/**
* Returns the list of user segments that a particular user belongs to
*
* @return List of User Segments
*/
public Iterable<UserSegment> getUserSegments(long id) {
return new PagedIterable<>(tmpl("/help_center/users/{id}/user_segments.json").set("id", id),
handleList(UserSegment.class, "user_segments"));
}
/**
* Request only user segments applicable on the account's current Guide plan
*
* @return List of User Segments
*/
public Iterable<UserSegment> getUserSegmentsApplicable() {
return new PagedIterable<>(cnst("/help_center/user_segments/applicable.json"),
handleList(UserSegment.class, "user_segments"));
}
/**
* Get user segment by id
*
* @param id
*/
public UserSegment getUserSegment(long id) {
return complete(submit(req("GET", tmpl("/help_center/user_segments/{id}.json").set("id", id)),
handle(UserSegment.class, "user_segment")));
}

/**
* List Sections using a User Segment
*
* @param userSegment
* @return List of Sections
*/
public Iterable<Section> getSections(UserSegment userSegment) {
checkHasId(userSegment);
return new PagedIterable<>(
tmpl("/help_center/user_segments/{id}/sections.json").set("id", userSegment.getId()),
handleList(Section.class, "sections"));
}

/**
* List Topics using a User Segment
*
* @param userSegment
* @return List of Topics
*/
public Iterable<Topic> getTopics(UserSegment userSegment) {
checkHasId(userSegment);
return new PagedIterable<>(
tmpl("/help_center/user_segments/{id}/topics.json").set("id", userSegment.getId()),
handleList(Topic.class, "topics"));
}

/**
* Create User Segment
*
* @param userSegment
*/
public UserSegment createUserSegment(UserSegment userSegment) {
return complete(submit(req("POST", tmpl("/help_center/user_segments.json"),
JSON, json(Collections.singletonMap("user_segment", userSegment))), handle(UserSegment.class, "user_segment")));
}
/**
* Update User Segment
*
* @param userSegment
*/
public UserSegment updateUserSegment(UserSegment userSegment) {
checkHasId(userSegment);
return complete(submit(req("PUT", tmpl("/help_center/user_segments/{id}.json").set("id", userSegment.getId()),
JSON, json(Collections.singletonMap("user_segment", userSegment))), handle(UserSegment.class, "user_segment")));
}
/**
* Delete User Segment
*
* @param userSegment
*/
public void deleteUserSegment(UserSegment userSegment) {
checkHasId(userSegment);
deleteUserSegment(userSegment.getId());
}

/**
* Delete User Segment
*
* @param id
*/
public void deleteUserSegment(long id) {
complete(submit(req("DELETE", tmpl("/help_center/user_segments/{id}.json").set("id", id)),
handleStatus()));
}

public List<String> getHelpCenterLocales() {
return complete(submit(
Expand Down Expand Up @@ -1787,6 +1945,17 @@ public Article createArticle(Article article) {
JSON, json(Collections.singletonMap("article", article))), handle(Article.class, "article")));
}

public Article createArticle(Article article, boolean notifySubscribers) {
checkHasSectionId(article);

Map map = new HashMap<String, Object>();
map.put("article", article);
map.put("notify_subscribers", notifySubscribers ? String.valueOf("true") : String.valueOf("false"));

return complete(submit(req("POST", tmpl("/help_center/sections/{id}/articles.json").set("id", article.getSectionId()),
JSON, json(Collections.unmodifiableMap(map))), handle(Article.class, "article")));
}

public Article updateArticle(Article article) {
checkHasId(article);
return complete(submit(req("PUT", tmpl("/help_center/articles/{id}.json").set("id", article.getId()),
Expand Down Expand Up @@ -2555,6 +2724,18 @@ private static void checkHasId(Holiday holiday) {
}
}

private static void checkHasId(PermissionGroup permissionGroup) {
if (permissionGroup.getId() == null) {
throw new IllegalArgumentException("PermissionGroup requires id");
}
}

private static void checkHasId(UserSegment userSegment) {
if (userSegment.getId() == null) {
throw new IllegalArgumentException("UserSegment requires id");
}
}

private static void checkHasToken(Attachment.Upload upload) {
if (upload.getToken() == null) {
throw new IllegalArgumentException("Upload requires token");
Expand Down
105 changes: 105 additions & 0 deletions src/main/java/org/zendesk/client/v2/model/hc/PermissionGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package org.zendesk.client.v2.model.hc;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.zendesk.client.v2.model.SearchResultEntity;

import java.util.Date;
import java.util.List;

/**
* Management Permission Group
* A management permission group defines which agents can create, update, archive, and publish articles.
* https://developer.zendesk.com/rest_api/docs/help_center/permission_groups
* @author Maxim Savenko ([email protected])
*/
public class PermissionGroup implements SearchResultEntity {
/** Automatically assigned when the permission group is created */
private Long id;
/** Permission group name */
private String name;
/** The ids of user segments that have edit privileges */
private List<Long> edit;
/** The ids of user segments that have publish privileges */
private List<Long> publish;
/** When the permission group was created */
@JsonProperty("created_at")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd hh:mm:ss Z")
private Date createdAt;
/** When the permission group was last updated */
@JsonProperty("updated_at")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd hh:mm:ss Z")
private Date updatedAt;
/** Whether the permission group is built-in. Built-in permission groups cannot be modified */
@JsonProperty("built_in")
private Boolean builtIn;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<Long> getEdit() {
return edit;
}

public void setEdit(List<Long> edit) {
this.edit = edit;
}

public List<Long> getPublish() {
return publish;
}

public void setPublish(List<Long> publish) {
this.publish = publish;
}

public Date getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}

public Date getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}

public Boolean getBuiltIn() {
return builtIn;
}

public void setBuiltIn(Boolean builtIn) {
this.builtIn = builtIn;
}

@Override
public String toString() {
return "PermissionGroup{" +
"id=" + id +
", name='" + name + '\'' +
", edit=" + edit +
", publish=" + publish +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", builtIn=" + builtIn +
'}';
}
}
Loading

0 comments on commit 6f8a723

Please sign in to comment.