mirror of
https://github.com/netbirdio/netbird.git
synced 2025-05-29 14:22:41 +02:00
[management] fix groups delete and resource create and update error response (#3189)
This commit is contained in:
parent
992a6c79b4
commit
c6f7a299a9
@ -463,7 +463,7 @@ func validateDeleteGroup(ctx context.Context, transaction store.Store, group *ty
|
|||||||
if group.Issued == types.GroupIssuedIntegration {
|
if group.Issued == types.GroupIssuedIntegration {
|
||||||
executingUser, err := transaction.GetUserByUserID(ctx, store.LockingStrengthShare, userID)
|
executingUser, err := transaction.GetUserByUserID(ctx, store.LockingStrengthShare, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return status.Errorf(status.Internal, "failed to get user")
|
||||||
}
|
}
|
||||||
if executingUser.Role != types.UserRoleAdmin || !executingUser.IsServiceUser {
|
if executingUser.Role != types.UserRoleAdmin || !executingUser.IsServiceUser {
|
||||||
return status.Errorf(status.PermissionDenied, "only service users with admin power can delete integration group")
|
return status.Errorf(status.PermissionDenied, "only service users with admin power can delete integration group")
|
||||||
@ -505,7 +505,7 @@ func validateDeleteGroup(ctx context.Context, transaction store.Store, group *ty
|
|||||||
func checkGroupLinkedToSettings(ctx context.Context, transaction store.Store, group *types.Group) error {
|
func checkGroupLinkedToSettings(ctx context.Context, transaction store.Store, group *types.Group) error {
|
||||||
dnsSettings, err := transaction.GetAccountDNSSettings(ctx, store.LockingStrengthShare, group.AccountID)
|
dnsSettings, err := transaction.GetAccountDNSSettings(ctx, store.LockingStrengthShare, group.AccountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return status.Errorf(status.Internal, "failed to get DNS settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(dnsSettings.DisabledManagementGroups, group.ID) {
|
if slices.Contains(dnsSettings.DisabledManagementGroups, group.ID) {
|
||||||
@ -514,7 +514,7 @@ func checkGroupLinkedToSettings(ctx context.Context, transaction store.Store, gr
|
|||||||
|
|
||||||
settings, err := transaction.GetAccountSettings(ctx, store.LockingStrengthShare, group.AccountID)
|
settings, err := transaction.GetAccountSettings(ctx, store.LockingStrengthShare, group.AccountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return status.Errorf(status.Internal, "failed to get account settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
if settings.Extra != nil && slices.Contains(settings.Extra.IntegratedValidatorGroups, group.ID) {
|
if settings.Extra != nil && slices.Contains(settings.Extra.IntegratedValidatorGroups, group.ID) {
|
||||||
|
@ -239,8 +239,9 @@ func (h *handler) deleteGroup(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
err = h.accountManager.DeleteGroup(r.Context(), accountID, userID, groupID)
|
err = h.accountManager.DeleteGroup(r.Context(), accountID, userID, groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, ok := err.(*server.GroupLinkError)
|
wrappedErr, ok := err.(interface{ Unwrap() []error })
|
||||||
if ok {
|
if ok && len(wrappedErr.Unwrap()) > 0 {
|
||||||
|
err = wrappedErr.Unwrap()[0]
|
||||||
util.WriteErrorResponse(err.Error(), http.StatusBadRequest, w)
|
util.WriteErrorResponse(err.Error(), http.StatusBadRequest, w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@ -73,10 +74,12 @@ func initGroupTestData(initGroups ...*types.Group) *handler {
|
|||||||
},
|
},
|
||||||
DeleteGroupFunc: func(_ context.Context, accountID, userId, groupID string) error {
|
DeleteGroupFunc: func(_ context.Context, accountID, userId, groupID string) error {
|
||||||
if groupID == "linked-grp" {
|
if groupID == "linked-grp" {
|
||||||
return &server.GroupLinkError{
|
err := &server.GroupLinkError{
|
||||||
Resource: "something",
|
Resource: "something",
|
||||||
Name: "linked-grp",
|
Name: "linked-grp",
|
||||||
}
|
}
|
||||||
|
var allErrors error
|
||||||
|
return errors.Join(allErrors, err)
|
||||||
}
|
}
|
||||||
if groupID == "invalid-grp" {
|
if groupID == "invalid-grp" {
|
||||||
return fmt.Errorf("internal error")
|
return fmt.Errorf("internal error")
|
||||||
|
@ -113,7 +113,7 @@ func (m *managerImpl) CreateResource(ctx context.Context, userID string, resourc
|
|||||||
err = m.store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
|
err = m.store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
|
||||||
_, err = transaction.GetNetworkResourceByName(ctx, store.LockingStrengthShare, resource.AccountID, resource.Name)
|
_, err = transaction.GetNetworkResourceByName(ctx, store.LockingStrengthShare, resource.AccountID, resource.Name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return errors.New("resource already exists")
|
return status.Errorf(status.InvalidArgument, "resource with name %s already exists", resource.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
network, err := transaction.GetNetworkByID(ctx, store.LockingStrengthUpdate, resource.AccountID, resource.NetworkID)
|
network, err := transaction.GetNetworkByID(ctx, store.LockingStrengthUpdate, resource.AccountID, resource.NetworkID)
|
||||||
@ -223,7 +223,7 @@ func (m *managerImpl) UpdateResource(ctx context.Context, userID string, resourc
|
|||||||
|
|
||||||
oldResource, err := transaction.GetNetworkResourceByName(ctx, store.LockingStrengthShare, resource.AccountID, resource.Name)
|
oldResource, err := transaction.GetNetworkResourceByName(ctx, store.LockingStrengthShare, resource.AccountID, resource.Name)
|
||||||
if err == nil && oldResource.ID != resource.ID {
|
if err == nil && oldResource.ID != resource.ID {
|
||||||
return errors.New("new resource name already exists")
|
return status.Errorf(status.InvalidArgument, "new resource name already exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
oldResource, err = transaction.GetNetworkResourceByID(ctx, store.LockingStrengthShare, resource.AccountID, resource.ID)
|
oldResource, err = transaction.GetNetworkResourceByID(ctx, store.LockingStrengthShare, resource.AccountID, resource.ID)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user