diff --git a/management/cmd/management.go b/management/cmd/management.go index 014610f609d..3eb52eb9012 100644 --- a/management/cmd/management.go +++ b/management/cmd/management.go @@ -276,10 +276,10 @@ var ( userManager := users.NewManager(store) settingsManager := settings.NewManager(store) permissionsManager := permissions.NewManager(userManager, settingsManager) - networksManager := networks.NewManager(store, permissionsManager) - groupsManager := groups.NewManager(store, permissionsManager) resourcesManager := resources.NewManager(store, permissionsManager, accountManager) routersManager := routers.NewManager(store, permissionsManager, accountManager) + networksManager := networks.NewManager(store, permissionsManager, resourcesManager) + groupsManager := groups.NewManager(store, permissionsManager) httpAPIHandler, err := httpapi.APIHandler(ctx, accountManager, networksManager, resourcesManager, routersManager, groupsManager, geo, *jwtValidator, appMetrics, httpAPIAuthCfg, integratedPeerValidator) if err != nil { diff --git a/management/server/networks/manager.go b/management/server/networks/manager.go index db1b9d5d6d6..d5291d9dafb 100644 --- a/management/server/networks/manager.go +++ b/management/server/networks/manager.go @@ -6,6 +6,7 @@ import ( "github.com/rs/xid" + "github.com/netbirdio/netbird/management/server/networks/resources" "github.com/netbirdio/netbird/management/server/networks/types" "github.com/netbirdio/netbird/management/server/permissions" "github.com/netbirdio/netbird/management/server/status" @@ -23,12 +24,14 @@ type Manager interface { type managerImpl struct { store store.Store permissionsManager permissions.Manager + resourcesManager resources.Manager } -func NewManager(store store.Store, permissionsManager permissions.Manager) Manager { +func NewManager(store store.Store, permissionsManager permissions.Manager, manager resources.Manager) Manager { return &managerImpl{ store: store, permissionsManager: permissionsManager, + resourcesManager: manager, } } diff --git a/management/server/networks/manager_test.go b/management/server/networks/manager_test.go index 5fa2b17f188..af1ce1caeea 100644 --- a/management/server/networks/manager_test.go +++ b/management/server/networks/manager_test.go @@ -6,6 +6,8 @@ import ( "github.com/stretchr/testify/require" + "github.com/netbirdio/netbird/management/server/mock_server" + "github.com/netbirdio/netbird/management/server/networks/resources" "github.com/netbirdio/netbird/management/server/networks/types" "github.com/netbirdio/netbird/management/server/permissions" "github.com/netbirdio/netbird/management/server/store" @@ -21,8 +23,10 @@ func Test_GetAllNetworksReturnsNetworks(t *testing.T) { t.Fatal(err) } t.Cleanup(cleanUp) + am := mock_server.MockAccountManager{} permissionsManager := permissions.NewManagerMock() - manager := NewManager(s, permissionsManager) + resourcesManager := resources.NewManager(s, permissionsManager, &am) + manager := NewManager(s, permissionsManager, resourcesManager) networks, err := manager.GetAllNetworks(ctx, accountID, userID) require.NoError(t, err) @@ -40,8 +44,10 @@ func Test_GetAllNetworksReturnsPermissionDenied(t *testing.T) { t.Fatal(err) } t.Cleanup(cleanUp) + am := mock_server.MockAccountManager{} permissionsManager := permissions.NewManagerMock() - manager := NewManager(s, permissionsManager) + resourcesManager := resources.NewManager(s, permissionsManager, &am) + manager := NewManager(s, permissionsManager, resourcesManager) networks, err := manager.GetAllNetworks(ctx, accountID, userID) require.Error(t, err) @@ -59,8 +65,10 @@ func Test_GetNetworkReturnsNetwork(t *testing.T) { t.Fatal(err) } t.Cleanup(cleanUp) + am := mock_server.MockAccountManager{} permissionsManager := permissions.NewManagerMock() - manager := NewManager(s, permissionsManager) + resourcesManager := resources.NewManager(s, permissionsManager, &am) + manager := NewManager(s, permissionsManager, resourcesManager) networks, err := manager.GetNetwork(ctx, accountID, userID, networkID) require.NoError(t, err) @@ -78,8 +86,10 @@ func Test_GetNetworkReturnsPermissionDenied(t *testing.T) { t.Fatal(err) } t.Cleanup(cleanUp) + am := mock_server.MockAccountManager{} permissionsManager := permissions.NewManagerMock() - manager := NewManager(s, permissionsManager) + resourcesManager := resources.NewManager(s, permissionsManager, &am) + manager := NewManager(s, permissionsManager, resourcesManager) network, err := manager.GetNetwork(ctx, accountID, userID, networkID) require.Error(t, err) @@ -99,8 +109,10 @@ func Test_CreateNetworkSuccessfully(t *testing.T) { t.Fatal(err) } t.Cleanup(cleanUp) + am := mock_server.MockAccountManager{} permissionsManager := permissions.NewManagerMock() - manager := NewManager(s, permissionsManager) + resourcesManager := resources.NewManager(s, permissionsManager, &am) + manager := NewManager(s, permissionsManager, resourcesManager) createdNetwork, err := manager.CreateNetwork(ctx, userID, network) require.NoError(t, err) @@ -120,8 +132,10 @@ func Test_CreateNetworkFailsWithPermissionDenied(t *testing.T) { t.Fatal(err) } t.Cleanup(cleanUp) + am := mock_server.MockAccountManager{} permissionsManager := permissions.NewManagerMock() - manager := NewManager(s, permissionsManager) + resourcesManager := resources.NewManager(s, permissionsManager, &am) + manager := NewManager(s, permissionsManager, resourcesManager) createdNetwork, err := manager.CreateNetwork(ctx, userID, network) require.Error(t, err) @@ -139,8 +153,10 @@ func Test_DeleteNetworkSuccessfully(t *testing.T) { t.Fatal(err) } t.Cleanup(cleanUp) + am := mock_server.MockAccountManager{} permissionsManager := permissions.NewManagerMock() - manager := NewManager(s, permissionsManager) + resourcesManager := resources.NewManager(s, permissionsManager, &am) + manager := NewManager(s, permissionsManager, resourcesManager) err = manager.DeleteNetwork(ctx, accountID, userID, networkID) require.NoError(t, err) @@ -157,8 +173,10 @@ func Test_DeleteNetworkFailsWithPermissionDenied(t *testing.T) { t.Fatal(err) } t.Cleanup(cleanUp) + am := mock_server.MockAccountManager{} permissionsManager := permissions.NewManagerMock() - manager := NewManager(s, permissionsManager) + resourcesManager := resources.NewManager(s, permissionsManager, &am) + manager := NewManager(s, permissionsManager, resourcesManager) err = manager.DeleteNetwork(ctx, accountID, userID, networkID) require.Error(t, err) @@ -178,8 +196,10 @@ func Test_UpdateNetworkSuccessfully(t *testing.T) { t.Fatal(err) } t.Cleanup(cleanUp) + am := mock_server.MockAccountManager{} permissionsManager := permissions.NewManagerMock() - manager := NewManager(s, permissionsManager) + resourcesManager := resources.NewManager(s, permissionsManager, &am) + manager := NewManager(s, permissionsManager, resourcesManager) updatedNetwork, err := manager.UpdateNetwork(ctx, userID, network) require.NoError(t, err) @@ -200,8 +220,11 @@ func Test_UpdateNetworkFailsWithPermissionDenied(t *testing.T) { t.Fatal(err) } t.Cleanup(cleanUp) + + am := mock_server.MockAccountManager{} permissionsManager := permissions.NewManagerMock() - manager := NewManager(s, permissionsManager) + resourcesManager := resources.NewManager(s, permissionsManager, &am) + manager := NewManager(s, permissionsManager, resourcesManager) updatedNetwork, err := manager.UpdateNetwork(ctx, userID, network) require.Error(t, err)