diff --git a/pom.xml b/pom.xml
index c297f383..f99e55e9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -335,7 +335,7 @@
org.apache.commons
commons-lang3
- 3.4
+ 3.12.0
com.google.guava
diff --git a/src/main/java/edu/ksu/canvas/impl/AccountImpl.java b/src/main/java/edu/ksu/canvas/impl/AccountImpl.java
index 8d9e346d..15a4f773 100644
--- a/src/main/java/edu/ksu/canvas/impl/AccountImpl.java
+++ b/src/main/java/edu/ksu/canvas/impl/AccountImpl.java
@@ -5,7 +5,9 @@
import edu.ksu.canvas.interfaces.AccountReader;
import edu.ksu.canvas.interfaces.AccountWriter;
import edu.ksu.canvas.model.Account;
+import edu.ksu.canvas.model.User;
import edu.ksu.canvas.model.status.Delete;
+import edu.ksu.canvas.model.wrapper.DeletedUserResponse;
import edu.ksu.canvas.net.Response;
import edu.ksu.canvas.net.RestClient;
import edu.ksu.canvas.oauth.OauthToken;
@@ -99,4 +101,15 @@ public Boolean deleteAccount(String parentAccountId, String accountId) throws IO
Optional responseParsed = responseParser.parseToObject(Delete.class, response);
return responseParsed.map(r -> r.getDelete()).orElse(false);
}
+
+ public User deleteUser(String userId, String accountId) throws IOException {
+ Map> postParams = new HashMap<>();
+ String deleteUrl = buildCanvasUrl("accounts/" + accountId + "/users/" + userId, Collections.emptyMap());
+ Response response = canvasMessenger.deleteFromCanvas(oauthToken, deleteUrl, postParams);
+ if (response.getErrorHappened() || ( response.getResponseCode() != 200)) {
+ LOG.debug("Failed to delete user, error message: " + response);
+ }
+ Optional responseParsed = responseParser.parseToObject(DeletedUserResponse.class, response);
+ return responseParsed.map(DeletedUserResponse::getUser).orElse(null);
+ }
}
diff --git a/src/main/java/edu/ksu/canvas/interfaces/AccountWriter.java b/src/main/java/edu/ksu/canvas/interfaces/AccountWriter.java
index 1ff53ea4..6c9f3cb1 100644
--- a/src/main/java/edu/ksu/canvas/interfaces/AccountWriter.java
+++ b/src/main/java/edu/ksu/canvas/interfaces/AccountWriter.java
@@ -1,6 +1,7 @@
package edu.ksu.canvas.interfaces;
import edu.ksu.canvas.model.Account;
+import edu.ksu.canvas.model.User;
import java.io.IOException;
import java.util.Optional;
@@ -30,4 +31,12 @@ public interface AccountWriter extends CanvasWriter {
* @throws IOException When there is an error communicating with Canvas
*/
Boolean deleteAccount(String parentAccountId, String accountId) throws IOException;
+
+ /**
+ * @param userId The ID of the user to delete.
+ * @param accountId The ID of the account to delete the user from
+ * @return the user who was deleted
+ * @throws IOException When there is an error communicating with Canvas
+ */
+ User deleteUser(String userId, String accountId) throws IOException;
}
diff --git a/src/main/java/edu/ksu/canvas/model/User.java b/src/main/java/edu/ksu/canvas/model/User.java
index 807a4cf2..4c3ec312 100644
--- a/src/main/java/edu/ksu/canvas/model/User.java
+++ b/src/main/java/edu/ksu/canvas/model/User.java
@@ -19,6 +19,8 @@ public class User extends BaseCanvasModel implements Serializable {
private long id;
private String name;
+ private String firstName;
+ private String lastName;
private String sortableName;
private String shortName;
private String sisUserId;
@@ -62,6 +64,8 @@ public User(User other) {
this.bio = other.bio;
this.createdAt = other.createdAt;
this.confirmationUrl = other.confirmationUrl;
+ this.firstName = other.firstName;
+ this.lastName = other.lastName;
}
public long getId() {
@@ -81,6 +85,16 @@ public void setName(String name) {
this.name = name;
}
+ @CanvasField(postKey = "first_name")
+ public String getFirstName() {
+ return firstName;
+ }
+
+ @CanvasField(postKey = "last_name")
+ public String getLastName() {
+ return lastName;
+ }
+
@CanvasField(postKey = "sortable_name")
public String getSortableName() {
return sortableName;
diff --git a/src/main/java/edu/ksu/canvas/model/wrapper/DeletedUserResponse.java b/src/main/java/edu/ksu/canvas/model/wrapper/DeletedUserResponse.java
new file mode 100644
index 00000000..44756f27
--- /dev/null
+++ b/src/main/java/edu/ksu/canvas/model/wrapper/DeletedUserResponse.java
@@ -0,0 +1,14 @@
+package edu.ksu.canvas.model.wrapper;
+
+import edu.ksu.canvas.model.User;
+
+import java.io.Serializable;
+
+public class DeletedUserResponse implements Serializable {
+ public static final long serialVersionUID = 1L;
+ private User user;
+
+ public User getUser() {
+ return user;
+ }
+}