From 5744a84fd38007d55ec24a936cc1608a7157d334 Mon Sep 17 00:00:00 2001 From: Harsh Modi <133243723+hmodi-ns1@users.noreply.github.com> Date: Fri, 19 Jul 2024 14:57:16 -0400 Subject: [PATCH 1/2] add new monitoring permissions support --- CHANGELOG.md | 6 +++ rest/account_apikey.go | 16 ++++++ rest/account_apikey_test.go | 81 +++++++++++++++++++++++-------- rest/account_team.go | 16 ++++++ rest/account_team_test.go | 73 +++++++++++++++++++++------- rest/account_user.go | 16 ++++++ rest/account_user_test.go | 76 +++++++++++++++++++++-------- rest/client.go | 2 +- rest/model/account/permissions.go | 3 ++ rest/model/account/user_test.go | 3 ++ 10 files changed, 234 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d232a27..280bee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.12.0 (Jul 19th, 2024) + +FEATURES: + +* Adds support for new split monitoring permissions create_jobs, update_jobs and delete_jobs + ## 2.11.0 (May 23rd, 2024) FEATURES: diff --git a/rest/account_apikey.go b/rest/account_apikey.go index dbfd339..a82cc8f 100644 --- a/rest/account_apikey.go +++ b/rest/account_apikey.go @@ -66,6 +66,14 @@ 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) @@ -106,6 +114,14 @@ 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 386a3bf..779d0d1 100644 --- a/rest/account_apikey_test.go +++ b/rest/account_apikey_test.go @@ -9,35 +9,76 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gopkg.in/ns1/ns1-go.v2/rest/model/account" ) func TestCreateAPIKey(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) + 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) + 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) + _, 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) 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{}, - } + 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) - _, err := c.APIKeys.Create(k) - 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) + + _, 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{}, + } + + _, 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 1ff8dd9..0da36a3 100644 --- a/rest/account_team.go +++ b/rest/account_team.go @@ -64,6 +64,14 @@ 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) @@ -104,6 +112,14 @@ 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 306b83a..81b6c5f 100644 --- a/rest/account_team_test.go +++ b/rest/account_team_test.go @@ -9,33 +9,70 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gopkg.in/ns1/ns1-go.v2/rest/model/account" ) func TestCreateTeam(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) + 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) 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) + 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) - w.Write(b) - })) - defer ts.Close() - c := NewClient(nil, SetEndpoint(ts.URL)) + 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) - tm := &account.Team{ - ID: "id-1", - Name: "team-1", - Permissions: account.PermissionsMap{}, - } + w.Write(b) + })) + defer ts.Close() + c := NewClient(nil, SetEndpoint(ts.URL)) - _, err := c.Teams.Create(tm) - require.NoError(t, err) + tm := &account.Team{ + ID: "id-1", + Name: "team-1", + Permissions: account.PermissionsMap{}, + } + + _, 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 82bc7cf..a91fe0d 100644 --- a/rest/account_user.go +++ b/rest/account_user.go @@ -64,6 +64,14 @@ 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) @@ -104,6 +112,14 @@ 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 e6590de..7261aa5 100644 --- a/rest/account_user_test.go +++ b/rest/account_user_test.go @@ -9,34 +9,72 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gopkg.in/ns1/ns1-go.v2/rest/model/account" ) func TestCreateUser(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) + 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) 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) + 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) - w.Write(b) - })) - defer ts.Close() - c := NewClient(nil, SetEndpoint(ts.URL)) + 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) - u := &account.User{ - Name: "name-1", - Username: "user-1", - Email: "email-1", - Permissions: account.PermissionsMap{}, - } + w.Write(b) + })) + defer ts.Close() + c := NewClient(nil, SetEndpoint(ts.URL)) - _, err := c.Users.Create(u) - require.NoError(t, err) + u := &account.User{ + Name: "name-1", + Username: "user-1", + Email: "email-1", + Permissions: account.PermissionsMap{}, + } + + _, err := c.Users.Create(u) + require.NoError(t, err) + }) } func TestCreateDDIUser(t *testing.T) { diff --git a/rest/client.go b/rest/client.go index 0edf123..7757f11 100644 --- a/rest/client.go +++ b/rest/client.go @@ -13,7 +13,7 @@ import ( ) const ( - clientVersion = "2.11.0" + clientVersion = "2.12.0" defaultEndpoint = "https://api.nsone.net/v1/" defaultShouldFollowPagination = true diff --git a/rest/model/account/permissions.go b/rest/model/account/permissions.go index e43935b..55982f2 100644 --- a/rest/model/account/permissions.go +++ b/rest/model/account/permissions.go @@ -58,6 +58,9 @@ type PermissionsMonitoring struct { ManageLists bool `json:"manage_lists"` ManageJobs bool `json:"manage_jobs"` ViewJobs bool `json:"view_jobs"` + CreateJobs bool `json:"create_jobs"` + UpdateJobs bool `json:"update_jobs"` + DeleteJobs bool `json:"delete_jobs"` } // PermissionsDHCP wraps a User's "permissions.dhcp" attribute for DDI. diff --git a/rest/model/account/user_test.go b/rest/model/account/user_test.go index cfd8c0c..d64ad0b 100644 --- a/rest/model/account/user_test.go +++ b/rest/model/account/user_test.go @@ -142,6 +142,9 @@ func TestUnmarshalUsers(t *testing.T) { ManageLists: false, ManageJobs: false, ViewJobs: false, + CreateJobs: false, + UpdateJobs: false, + DeleteJobs: false, }, }, }, From e3162637c7279cbea516beedb4d9595898ae0173 Mon Sep 17 00:00:00 2001 From: Harsh Modi <133243723+hmodi-ns1@users.noreply.github.com> Date: Tue, 23 Jul 2024 14:26:48 -0400 Subject: [PATCH 2/2] update some permission default logic --- rest/account_apikey.go | 16 ------- rest/account_apikey_test.go | 84 +++++++++++-------------------------- rest/account_team.go | 16 ------- rest/account_team_test.go | 76 ++++++++++----------------------- rest/account_user.go | 16 ------- rest/account_user_test.go | 79 ++++++++++------------------------ 6 files changed, 69 insertions(+), 218 deletions(-) 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) {