From 4562042b8d86668d8211967ee642361b58c20bee Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Thu, 26 Jun 2025 18:48:07 +0800 Subject: [PATCH] fix(dashboard): cannot save settings for anonymous group --- inventory/group.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/inventory/group.go b/inventory/group.go index c40b6e8..3ecd697 100644 --- a/inventory/group.go +++ b/inventory/group.go @@ -77,27 +77,34 @@ func (c *groupClient) ListAll(ctx context.Context) ([]*ent.Group, error) { } func (c *groupClient) Upsert(ctx context.Context, group *ent.Group) (*ent.Group, error) { - if group.ID == 0 { - return c.client.Group.Create(). + stm := c.client.Group.Create(). SetName(group.Name). SetMaxStorage(group.MaxStorage). SetSpeedLimit(group.SpeedLimit). SetPermissions(group.Permissions). - SetSettings(group.Settings). - SetStoragePoliciesID(group.Edges.StoragePolicies.ID). - Save(ctx) + SetSettings(group.Settings) + + if group.StoragePolicyID > 0 { + stm.SetStoragePolicyID(group.StoragePolicyID) + } + + return stm.Save(ctx) } - res, err := c.client.Group.UpdateOne(group). + stm := c.client.Group.UpdateOne(group). SetName(group.Name). SetMaxStorage(group.MaxStorage). SetSpeedLimit(group.SpeedLimit). SetPermissions(group.Permissions). SetSettings(group.Settings). - ClearStoragePolicies(). - SetStoragePoliciesID(group.Edges.StoragePolicies.ID). - Save(ctx) + ClearStoragePolicies() + + if group.StoragePolicyID > 0 { + stm.SetStoragePolicyID(group.StoragePolicyID) + } + + res, err := stm.Save(ctx) if err != nil { return nil, err }