Skip to content

Commit

Permalink
Ignore delete permission error for manually deleted jobs (issue #2217)
Browse files Browse the repository at this point in the history
this fixes #2217
  • Loading branch information
alexott committed Apr 18, 2023
1 parent c282084 commit 305e9e8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions permissions/resource_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ func (a PermissionsAPI) Delete(objectID string) error {
}
job, err := w.Jobs.GetByJobId(a.context, jobId)
if err != nil {
if strings.HasSuffix(err.Error(), " does not exist.") {
return nil
}
return err
}
accl.AccessControlList = append(accl.AccessControlList, AccessControlChange{
Expand Down
42 changes: 42 additions & 0 deletions permissions/resource_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,48 @@ func TestShouldKeepAdminsOnAnythingExceptPasswordsAndAssignsOwnerForJob(t *testi
})
}

func TestShouldDeleteNonExistentJob(t *testing.T) {
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/permissions/jobs/123",
Response: ObjectACL{
ObjectID: "/jobs/123",
ObjectType: "job",
AccessControlList: []AccessControl{
{
GroupName: "admins",
AllPermissions: []Permission{
{
PermissionLevel: "CAN_DO_EVERYTHING",
Inherited: true,
},
{
PermissionLevel: "CAN_MANAGE",
Inherited: false,
},
},
},
},
},
},
{
Method: "GET",
Resource: "/api/2.1/jobs/get?job_id=123",
Status: 400,
Response: apierr.APIError{
StatusCode: 400,
Message: "Job 123 does not exist.",
ErrorCode: "INVALID_PARAMETER_VALUE",
},
},
}, func(ctx context.Context, client *common.DatabricksClient) {
p := NewPermissionsAPI(ctx, client)
err := p.Delete("/jobs/123")
assert.NoError(t, err)
})
}

func TestShouldKeepAdminsOnAnythingExceptPasswordsAndAssignsOwnerForPipeline(t *testing.T) {
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
{
Expand Down

0 comments on commit 305e9e8

Please sign in to comment.