diff --git a/rest/account_apikey.go b/rest/account_apikey.go index a82cc8f..dbfd339 100644 --- a/rest/account_apikey.go +++ b/rest/account_apikey.go @@ -66,14 +66,6 @@ func (s *APIKeysService) Create(a *account.APIKey) (*http.Response, error) { err error ) - // Replace `manage_jobs` with the new split permissions - if a != nil && a.Permissions.Monitoring.ManageJobs { - a.Permissions.Monitoring.ManageJobs = false - a.Permissions.Monitoring.CreateJobs = true - a.Permissions.Monitoring.UpdateJobs = true - a.Permissions.Monitoring.DeleteJobs = true - } - // If this is DDI then the permissions need to be transformed to DDI-compatible permissions. if s.client.DDI && a != nil { ddiAPIKey := apiKeyToDDIAPIKey(a) @@ -114,14 +106,6 @@ func (s *APIKeysService) Update(a *account.APIKey) (*http.Response, error) { err error ) - // Replace `manage_jobs` with the new split permissions - if a != nil && a.Permissions.Monitoring.ManageJobs { - a.Permissions.Monitoring.ManageJobs = false - a.Permissions.Monitoring.CreateJobs = true - a.Permissions.Monitoring.UpdateJobs = true - a.Permissions.Monitoring.DeleteJobs = true - } - // If this is DDI then the permissions need to be transformed to DDI-compatible permissions. if s.client.DDI && a != nil { ddiAPIKey := apiKeyToDDIAPIKey(a) diff --git a/rest/account_apikey_test.go b/rest/account_apikey_test.go index 779d0d1..a636f8e 100644 --- a/rest/account_apikey_test.go +++ b/rest/account_apikey_test.go @@ -14,71 +14,35 @@ import ( ) func TestCreateAPIKey(t *testing.T) { - t.Run("with manage_jobs set to true", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) - require.NoError(t, err) - - var k account.APIKey - require.NoError(t, json.Unmarshal(b, &k)) - assert.Nil(t, k.Permissions.Security) - assert.Nil(t, k.Permissions.DHCP) - assert.Nil(t, k.Permissions.IPAM) - assert.False(t, k.Permissions.Monitoring.ManageJobs) - assert.True(t, k.Permissions.Monitoring.CreateJobs) - assert.True(t, k.Permissions.Monitoring.UpdateJobs) - assert.True(t, k.Permissions.Monitoring.DeleteJobs) - - _, err = w.Write(b) - require.NoError(t, err) - })) - defer ts.Close() - c := NewClient(nil, SetEndpoint(ts.URL)) - - k := &account.APIKey{ - ID: "id-1", - Key: "key-1", - Name: "name-1", - Permissions: account.PermissionsMap{ - Monitoring: account.PermissionsMonitoring{ManageJobs: true}, - }, - } - - _, err := c.APIKeys.Create(k) + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + b, err := ioutil.ReadAll(r.Body) require.NoError(t, err) - }) - - t.Run("with manage_jobs not set", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) - require.NoError(t, err) - var k account.APIKey - require.NoError(t, json.Unmarshal(b, &k)) - assert.Nil(t, k.Permissions.Security) - assert.Nil(t, k.Permissions.DHCP) - assert.Nil(t, k.Permissions.IPAM) - assert.False(t, k.Permissions.Monitoring.ManageJobs) - assert.False(t, k.Permissions.Monitoring.CreateJobs) - assert.False(t, k.Permissions.Monitoring.UpdateJobs) - assert.False(t, k.Permissions.Monitoring.DeleteJobs) + var k account.APIKey + require.NoError(t, json.Unmarshal(b, &k)) + assert.Nil(t, k.Permissions.Security) + assert.Nil(t, k.Permissions.DHCP) + assert.Nil(t, k.Permissions.IPAM) + assert.False(t, k.Permissions.Monitoring.ManageJobs) + assert.False(t, k.Permissions.Monitoring.CreateJobs) + assert.False(t, k.Permissions.Monitoring.UpdateJobs) + assert.False(t, k.Permissions.Monitoring.DeleteJobs) - _, err = w.Write(b) - require.NoError(t, err) - })) - defer ts.Close() - c := NewClient(nil, SetEndpoint(ts.URL)) + _, err = w.Write(b) + require.NoError(t, err) + })) + defer ts.Close() + c := NewClient(nil, SetEndpoint(ts.URL)) - k := &account.APIKey{ - ID: "id-1", - Key: "key-1", - Name: "name-1", - Permissions: account.PermissionsMap{}, - } + k := &account.APIKey{ + ID: "id-1", + Key: "key-1", + Name: "name-1", + Permissions: account.PermissionsMap{}, + } - _, err := c.APIKeys.Create(k) - require.NoError(t, err) - }) + _, err := c.APIKeys.Create(k) + require.NoError(t, err) } func TestCreateDDIAPIKey(t *testing.T) { diff --git a/rest/account_team.go b/rest/account_team.go index 0da36a3..1ff8dd9 100644 --- a/rest/account_team.go +++ b/rest/account_team.go @@ -64,14 +64,6 @@ func (s *TeamsService) Create(t *account.Team) (*http.Response, error) { err error ) - // Replace `manage_jobs` with the new split permissions - if t != nil && t.Permissions.Monitoring.ManageJobs { - t.Permissions.Monitoring.ManageJobs = false - t.Permissions.Monitoring.CreateJobs = true - t.Permissions.Monitoring.UpdateJobs = true - t.Permissions.Monitoring.DeleteJobs = true - } - // If this is DDI then the permissions need to be transformed to DDI-compatible permissions. if s.client.DDI && t != nil { ddiTeam := teamToDDITeam(t) @@ -112,14 +104,6 @@ func (s *TeamsService) Update(t *account.Team) (*http.Response, error) { err error ) - // Replace `manage_jobs` with the new split permissions - if t != nil && t.Permissions.Monitoring.ManageJobs { - t.Permissions.Monitoring.ManageJobs = false - t.Permissions.Monitoring.CreateJobs = true - t.Permissions.Monitoring.UpdateJobs = true - t.Permissions.Monitoring.DeleteJobs = true - } - // If this is DDI then the permissions need to be transformed to DDI-compatible permissions. if s.client.DDI && t != nil { ddiTeam := teamToDDITeam(t) diff --git a/rest/account_team_test.go b/rest/account_team_test.go index 81b6c5f..1dfad94 100644 --- a/rest/account_team_test.go +++ b/rest/account_team_test.go @@ -14,65 +14,33 @@ import ( ) func TestCreateTeam(t *testing.T) { - t.Run("with manage_jobs set to true", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) - require.NoError(t, err) - - var tm account.Team - require.NoError(t, json.Unmarshal(b, &tm)) - assert.Nil(t, tm.Permissions.Security) - assert.Nil(t, tm.Permissions.DHCP) - assert.Nil(t, tm.Permissions.IPAM) - assert.False(t, tm.Permissions.Monitoring.ManageJobs) - assert.True(t, tm.Permissions.Monitoring.CreateJobs) - assert.True(t, tm.Permissions.Monitoring.UpdateJobs) - assert.True(t, tm.Permissions.Monitoring.DeleteJobs) - - w.Write(b) - })) - defer ts.Close() - c := NewClient(nil, SetEndpoint(ts.URL)) - - tm := &account.Team{ - ID: "id-1", - Name: "team-1", - Permissions: account.PermissionsMap{Monitoring: account.PermissionsMonitoring{ManageJobs: true}}, - } - - _, err := c.Teams.Create(tm) + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + b, err := ioutil.ReadAll(r.Body) require.NoError(t, err) - }) - - t.Run("with manage_jobs not set", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) - require.NoError(t, err) - var tm account.Team - require.NoError(t, json.Unmarshal(b, &tm)) - assert.Nil(t, tm.Permissions.Security) - assert.Nil(t, tm.Permissions.DHCP) - assert.Nil(t, tm.Permissions.IPAM) - assert.False(t, tm.Permissions.Monitoring.ManageJobs) - assert.False(t, tm.Permissions.Monitoring.CreateJobs) - assert.False(t, tm.Permissions.Monitoring.UpdateJobs) - assert.False(t, tm.Permissions.Monitoring.DeleteJobs) + var tm account.Team + require.NoError(t, json.Unmarshal(b, &tm)) + assert.Nil(t, tm.Permissions.Security) + assert.Nil(t, tm.Permissions.DHCP) + assert.Nil(t, tm.Permissions.IPAM) + assert.False(t, tm.Permissions.Monitoring.ManageJobs) + assert.False(t, tm.Permissions.Monitoring.CreateJobs) + assert.False(t, tm.Permissions.Monitoring.UpdateJobs) + assert.False(t, tm.Permissions.Monitoring.DeleteJobs) - w.Write(b) - })) - defer ts.Close() - c := NewClient(nil, SetEndpoint(ts.URL)) + w.Write(b) + })) + defer ts.Close() + c := NewClient(nil, SetEndpoint(ts.URL)) - tm := &account.Team{ - ID: "id-1", - Name: "team-1", - Permissions: account.PermissionsMap{}, - } + tm := &account.Team{ + ID: "id-1", + Name: "team-1", + Permissions: account.PermissionsMap{}, + } - _, err := c.Teams.Create(tm) - require.NoError(t, err) - }) + _, err := c.Teams.Create(tm) + require.NoError(t, err) } func TestCreateDDITeam(t *testing.T) { diff --git a/rest/account_user.go b/rest/account_user.go index a91fe0d..82bc7cf 100644 --- a/rest/account_user.go +++ b/rest/account_user.go @@ -64,14 +64,6 @@ func (s *UsersService) Create(u *account.User) (*http.Response, error) { err error ) - // Replace `manage_jobs` with the new split permissions - if u != nil && u.Permissions.Monitoring.ManageJobs { - u.Permissions.Monitoring.ManageJobs = false - u.Permissions.Monitoring.CreateJobs = true - u.Permissions.Monitoring.UpdateJobs = true - u.Permissions.Monitoring.DeleteJobs = true - } - // If this is DDI then the permissions need to be transformed to DDI-compatible permissions. if s.client.DDI && u != nil { ddiUser := userToDDIUser(u) @@ -112,14 +104,6 @@ func (s *UsersService) Update(u *account.User) (*http.Response, error) { err error ) - // Replace `manage_jobs` with the new split permissions - if u != nil && u.Permissions.Monitoring.ManageJobs { - u.Permissions.Monitoring.ManageJobs = false - u.Permissions.Monitoring.CreateJobs = true - u.Permissions.Monitoring.UpdateJobs = true - u.Permissions.Monitoring.DeleteJobs = true - } - // If this is DDI then the permissions need to be transformed to DDI-compatible permissions. if s.client.DDI && u != nil { ddiUser := userToDDIUser(u) diff --git a/rest/account_user_test.go b/rest/account_user_test.go index 7261aa5..7299122 100644 --- a/rest/account_user_test.go +++ b/rest/account_user_test.go @@ -14,67 +14,34 @@ import ( ) func TestCreateUser(t *testing.T) { - t.Run("with manage_jobs set to true", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) - require.NoError(t, err) - - var u account.User - require.NoError(t, json.Unmarshal(b, &u)) - assert.Nil(t, u.Permissions.Security) - assert.Nil(t, u.Permissions.DHCP) - assert.Nil(t, u.Permissions.IPAM) - assert.False(t, u.Permissions.Monitoring.ManageJobs) - assert.True(t, u.Permissions.Monitoring.CreateJobs) - assert.True(t, u.Permissions.Monitoring.UpdateJobs) - assert.True(t, u.Permissions.Monitoring.DeleteJobs) - - w.Write(b) - })) - defer ts.Close() - c := NewClient(nil, SetEndpoint(ts.URL)) - - u := &account.User{ - Name: "name-1", - Username: "user-1", - Email: "email-1", - Permissions: account.PermissionsMap{Monitoring: account.PermissionsMonitoring{ManageJobs: true}}, - } - - _, err := c.Users.Create(u) + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + b, err := ioutil.ReadAll(r.Body) require.NoError(t, err) - }) - - t.Run("with manage_jobs not set", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) - require.NoError(t, err) - var u account.User - require.NoError(t, json.Unmarshal(b, &u)) - assert.Nil(t, u.Permissions.Security) - assert.Nil(t, u.Permissions.DHCP) - assert.Nil(t, u.Permissions.IPAM) - assert.False(t, u.Permissions.Monitoring.ManageJobs) - assert.False(t, u.Permissions.Monitoring.CreateJobs) - assert.False(t, u.Permissions.Monitoring.UpdateJobs) - assert.False(t, u.Permissions.Monitoring.DeleteJobs) + var u account.User + require.NoError(t, json.Unmarshal(b, &u)) + assert.Nil(t, u.Permissions.Security) + assert.Nil(t, u.Permissions.DHCP) + assert.Nil(t, u.Permissions.IPAM) + assert.False(t, u.Permissions.Monitoring.ManageJobs) + assert.False(t, u.Permissions.Monitoring.CreateJobs) + assert.False(t, u.Permissions.Monitoring.UpdateJobs) + assert.False(t, u.Permissions.Monitoring.DeleteJobs) - w.Write(b) - })) - defer ts.Close() - c := NewClient(nil, SetEndpoint(ts.URL)) + w.Write(b) + })) + defer ts.Close() + c := NewClient(nil, SetEndpoint(ts.URL)) - u := &account.User{ - Name: "name-1", - Username: "user-1", - Email: "email-1", - Permissions: account.PermissionsMap{}, - } + u := &account.User{ + Name: "name-1", + Username: "user-1", + Email: "email-1", + Permissions: account.PermissionsMap{}, + } - _, err := c.Users.Create(u) - require.NoError(t, err) - }) + _, err := c.Users.Create(u) + require.NoError(t, err) } func TestCreateDDIUser(t *testing.T) {