mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
SMQ-3224 - Add consistent error for assigning channel and client with parent group to parent group (#3225)
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
This commit is contained in:
+7
-1
@@ -26,6 +26,7 @@ var (
|
||||
errAddConnectionsClients = errors.New("failed to add connections in clients service")
|
||||
errRemoveConnectionsClients = errors.New("failed to remove connections from clients service")
|
||||
errSetParentGroup = errors.New("channel already have parent")
|
||||
errSetSameParentGroup = errors.New("channel already assigned to the parent group")
|
||||
)
|
||||
|
||||
type service struct {
|
||||
@@ -421,7 +422,12 @@ func (svc service) SetParentGroup(ctx context.Context, session authn.Session, pa
|
||||
}
|
||||
|
||||
var pols []policies.Policy
|
||||
if ch.ParentGroup != "" {
|
||||
switch ch.ParentGroup {
|
||||
case parentGroupID:
|
||||
return errors.Wrap(svcerr.ErrConflict, errSetSameParentGroup)
|
||||
case "":
|
||||
// No action needed, proceed to next code after switch
|
||||
default:
|
||||
return errors.Wrap(svcerr.ErrConflict, errSetParentGroup)
|
||||
}
|
||||
pols = append(pols, policies.Policy{
|
||||
|
||||
+4
-3
@@ -20,8 +20,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
errRollbackRepo = errors.New("failed to rollback repo")
|
||||
errSetParentGroup = errors.New("client already have parent")
|
||||
errRollbackRepo = errors.New("failed to rollback repo")
|
||||
errSetParentGroup = errors.New("client already have parent")
|
||||
errSetSameParentGroup = errors.New("client already assigned to the parent group")
|
||||
)
|
||||
var _ Service = (*service)(nil)
|
||||
|
||||
@@ -247,7 +248,7 @@ func (svc service) SetParentGroup(ctx context.Context, session authn.Session, pa
|
||||
}
|
||||
switch cli.ParentGroup {
|
||||
case parentGroupID:
|
||||
return nil
|
||||
return errors.Wrap(svcerr.ErrConflict, errSetSameParentGroup)
|
||||
case "":
|
||||
// No action needed, proceed to next code after switch
|
||||
default:
|
||||
|
||||
@@ -1029,7 +1029,7 @@ func TestSetParentGroup(t *testing.T) {
|
||||
parentGroupID: validID,
|
||||
session: smqauthn.Session{UserID: validID, DomainID: validID, DomainUserID: validID + "_" + validID},
|
||||
retrieveByIDResp: parentedClient,
|
||||
err: nil,
|
||||
err: svcerr.ErrConflict,
|
||||
},
|
||||
{
|
||||
desc: "set parent group of client with existing parent group",
|
||||
|
||||
Reference in New Issue
Block a user