Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this adds the remove user call from the accounts api, and a wrapper o… #65

Merged
merged 2 commits into from
Feb 26, 2024
Merged
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/edu/ksu/canvas/impl/AccountImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,4 +101,15 @@ public Boolean deleteAccount(String parentAccountId, String accountId) throws IO
Optional<Delete> responseParsed = responseParser.parseToObject(Delete.class, response);
return responseParsed.map(r -> r.getDelete()).orElse(false);
}

public User deleteUser(String userId, String accountId) throws IOException {
Map<String, List<String>> 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<DeletedUserResponse> responseParsed = responseParser.parseToObject(DeletedUserResponse.class, response);
return responseParsed.map(DeletedUserResponse::getUser).orElse(null);
}
}
9 changes: 9 additions & 0 deletions src/main/java/edu/ksu/canvas/interfaces/AccountWriter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,4 +31,12 @@ public interface AccountWriter extends CanvasWriter<Account, AccountWriter> {
* @throws IOException When there is an error communicating with Canvas
*/
Boolean deleteAccount(String parentAccountId, String accountId) throws IOException;

buckett marked this conversation as resolved.
Show resolved Hide resolved
/**
* @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;
}
14 changes: 14 additions & 0 deletions src/main/java/edu/ksu/canvas/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading