feat(policy): suspend storage policies like nodes (#2961)
Mirrors the existing node active/suspended model onto storage policies. A suspended policy keeps serving existing files but rejects new uploads. - schema: StoragePolicy.status (active|suspended, default active) - group default-policy pick skips suspended policies; explicit picks for upload/import are rejected with CodePolicyNotAllowed - admin policy edit gets a status select; suspended policies show a chip on the list card - Upsert only writes status when provided, so partial payloads keep the stored value - tests: suspended group policy skipped, active returned Authored By: TDvorak <info@tdvorak.dev> Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>pull/3582/head
parent
ba9a2b3d57
commit
7a9b0a1de0
File diff suppressed because one or more lines are too long
@ -0,0 +1,42 @@
|
||||
package inventory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/enttest"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/storagepolicy"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/boolset"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetByGroupSkipsSuspended(t *testing.T) {
|
||||
client := enttest.Open(t, "sqlite3", "file:"+t.Name()+"?mode=memory&cache=shared")
|
||||
t.Cleanup(func() { require.NoError(t, client.Close()) })
|
||||
ctx := context.Background()
|
||||
|
||||
pc := NewStoragePolicyClient(client, nil)
|
||||
|
||||
t.Run("suspended group policy yields not found", func(t *testing.T) {
|
||||
p := client.StoragePolicy.Create().
|
||||
SetName("suspended").SetType("local").
|
||||
SetStatus(storagepolicy.StatusSuspended).SaveX(ctx)
|
||||
group := client.Group.Create().SetName("g1").SetPermissions(&boolset.BooleanSet{}).
|
||||
SetStoragePolicies(p).SaveX(ctx)
|
||||
|
||||
_, err := pc.GetByGroup(ctx, group)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("active group policy returned", func(t *testing.T) {
|
||||
p := client.StoragePolicy.Create().
|
||||
SetName("active").SetType("local").
|
||||
SetStatus(storagepolicy.StatusActive).SaveX(ctx)
|
||||
group := client.Group.Create().SetName("g2").SetPermissions(&boolset.BooleanSet{}).
|
||||
SetStoragePolicies(p).SaveX(ctx)
|
||||
|
||||
got, err := pc.GetByGroup(ctx, group)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "active", got.Name)
|
||||
})
|
||||
}
|
||||
Loading…
Reference in new issue