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

Delete permanently API for apps, groups, and users #54

Merged
merged 3 commits into from
Jun 1, 2021
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
16 changes: 16 additions & 0 deletions msgraph/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@ func (c *ApplicationsClient) Delete(ctx context.Context, id string) (int, error)
return status, nil
}

// DeletePermanently removes a deleted Application permanently.
// id is the object ID of the application.
func (c *ApplicationsClient) DeletePermanently(ctx context.Context, id string) (int, error) {
_, status, _, err := c.BaseClient.Delete(ctx, DeleteHttpRequestInput{
ValidStatusCodes: []int{http.StatusNoContent},
Uri: Uri{
Entity: fmt.Sprintf("/directory/deletedItems/%s", id),
HasTenantId: true,
},
})
if err != nil {
return status, fmt.Errorf("ApplicationsClient.BaseClient.Delete(): %v", err)
}
return status, nil
}

// ListDeleted retrieves a list of recently deleted applications, optionally filtered using OData.
func (c *ApplicationsClient) ListDeleted(ctx context.Context, filter string) (*[]Application, int, error) {
params := url.Values{}
Expand Down
11 changes: 11 additions & 0 deletions msgraph/applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestApplicationsClient(t *testing.T) {
testApplicationsClient_Delete(t, c, *app.ID)
testApplicationsClient_ListDeleted(t, c, *app.ID)
testApplicationsClient_GetDeleted(t, c, *app.ID)
testApplicationsClient_DeletePermanently(t, c, *app.ID)
}

func TestApplicationsClient_groupMembershipClaims(t *testing.T) {
Expand Down Expand Up @@ -134,6 +135,16 @@ func testApplicationsClient_Delete(t *testing.T, c ApplicationsClientTest, id st
}
}

func testApplicationsClient_DeletePermanently(t *testing.T, c ApplicationsClientTest, id string) {
status, err := c.client.DeletePermanently(c.connection.Context, id)
if err != nil {
t.Fatalf("ApplicationsClient.DeletePermanently(): %v", err)
}
if status < 200 || status >= 300 {
t.Fatalf("ApplicationsClient.DeletePermanently(): invalid status: %d", status)
}
}

func testApplicationsClient_ListOwners(t *testing.T, c ApplicationsClientTest, id string) (owners *[]string) {
owners, status, err := c.client.ListOwners(c.connection.Context, id)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions msgraph/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (c *GroupsClient) Get(ctx context.Context, id string) (*Group, int, error)
}

// GetDeleted retrieves a deleted O365 Group.
// TODO: add test coverage once API supports creating O365 groups.
func (c *GroupsClient) GetDeleted(ctx context.Context, id string) (*Group, int, error) {
resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{
ValidStatusCodes: []int{http.StatusOK},
Expand Down Expand Up @@ -168,6 +169,22 @@ func (c *GroupsClient) Delete(ctx context.Context, id string) (int, error) {
return status, nil
}

// DeletePermanently removes a deleted O365 Group permanently.
// TODO: add test coverage once API supports creating O365 groups.
func (c *GroupsClient) DeletePermanently(ctx context.Context, id string) (int, error) {
_, status, _, err := c.BaseClient.Delete(ctx, DeleteHttpRequestInput{
ValidStatusCodes: []int{http.StatusNoContent},
Uri: Uri{
Entity: fmt.Sprintf("/directory/deletedItems/%s", id),
HasTenantId: true,
},
})
if err != nil {
return status, fmt.Errorf("GroupsClient.BaseClient.Delete(): %v", err)
}
return status, nil
}

// ListDeleted retrieves a list of recently deleted O365 groups, optionally filtered using OData.
// TODO: add test coverage once API supports creating O365 groups
func (c *GroupsClient) ListDeleted(ctx context.Context, filter string) (*[]Group, int, error) {
Expand Down
15 changes: 15 additions & 0 deletions msgraph/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ func (c *UsersClient) Delete(ctx context.Context, id string) (int, error) {
return status, nil
}

// DeletePermanently removes a deleted User permanently.
func (c *UsersClient) DeletePermanently(ctx context.Context, id string) (int, error) {
_, status, _, err := c.BaseClient.Delete(ctx, DeleteHttpRequestInput{
ValidStatusCodes: []int{http.StatusNoContent},
Uri: Uri{
Entity: fmt.Sprintf("/directory/deletedItems/%s", id),
HasTenantId: true,
},
})
if err != nil {
return status, fmt.Errorf("UsersClient.BaseClient.Delete(): %v", err)
}
return status, nil
}

// ListDeleted retrieves a list of recently deleted users, optionally filtered using OData.
func (c *UsersClient) ListDeleted(ctx context.Context, filter string) (*[]User, int, error) {
params := url.Values{}
Expand Down
11 changes: 11 additions & 0 deletions msgraph/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestUsersClient(t *testing.T) {
testUsersClient_Delete(t, c, *user.ID)
testUsersClient_ListDeleted(t, c, *user.ID)
testUsersClient_GetDeleted(t, c, *user.ID)
testUsersClient_DeletePermanently(t, c, *user.ID)
}

func testUsersClient_Create(t *testing.T, c UsersClientTest, u msgraph.User) (user *msgraph.User) {
Expand Down Expand Up @@ -151,6 +152,16 @@ func testUsersClient_Delete(t *testing.T, c UsersClientTest, id string) {
}
}

func testUsersClient_DeletePermanently(t *testing.T, c UsersClientTest, id string) {
status, err := c.client.DeletePermanently(c.connection.Context, id)
if err != nil {
t.Fatalf("UsersClient.DeletePermanently(): %v", err)
}
if status < 200 || status >= 300 {
t.Fatalf("UsersClient.DeletePermanently(): invalid status: %d", status)
}
}

func testUsersClient_ListGroupMemberships(t *testing.T, c UsersClientTest, id string) (groups *[]msgraph.Group) {
groups, _, err := c.client.ListGroupMemberships(c.connection.Context, id, "")
if err != nil {
Expand Down