From 4d1dcb56a37a2bedac0ab161f8261d0915d8d56a Mon Sep 17 00:00:00 2001
From: "a.petraki" <a.petraki@perx.ru>
Date: Wed, 8 May 2024 12:13:18 +0300
Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?=
 =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0,=20?=
 =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D0=BE=D0=B9?=
 =?UTF-8?q?=20=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=20=D0=BD=D0=B0=20=D1=87?=
 =?UTF-8?q?=D1=82=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=20=D0=BF=D1=80=D0=BE?=
 =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D0=BD=D1=81=D1=82=D0=B2=D1=83=20=D0=B2?=
 =?UTF-8?q?=20=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F=D0=BD=D0=B8=D0=B8=20'St?=
 =?UTF-8?q?ateMigrationScheduled'=20=D0=B1=D1=8B=D0=BB=20=D0=BE=D0=B3?=
 =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B8=D1=87=D0=B5=D0=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pkg/spaces/service.go |  7 ++++---
 pkg/spaces/space.go   | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/pkg/spaces/service.go b/pkg/spaces/service.go
index e8baf185..24922169 100644
--- a/pkg/spaces/service.go
+++ b/pkg/spaces/service.go
@@ -2,6 +2,7 @@ package spaces
 
 import (
 	"context"
+	"slices"
 	"time"
 
 	"git.perx.ru/perxis/perxis-go/pkg/errors"
@@ -71,10 +72,10 @@ func IsSpaceAvailable(ctx context.Context, svc Spaces, spaceID string) error {
 	if err != nil {
 		return errors.Wrap(err, "fail to get space")
 	}
-	if sp.StateInfo == nil || sp.StateInfo != nil && (sp.StateInfo.State == StateNew || sp.StateInfo.State == StateReady) {
+	if sp.StateInfo == nil || slices.Contains(WriteAllowedStates, sp.StateInfo.State) {
 		return nil
 	}
-	return ErrSpaceNotAvailable
+	return errors.WithContext(ErrSpaceNotAvailable, "state", sp.StateInfo.State)
 }
 
 func IsSpaceReadable(ctx context.Context, svc Spaces, spaceID string) error {
@@ -82,7 +83,7 @@ func IsSpaceReadable(ctx context.Context, svc Spaces, spaceID string) error {
 	if err != nil {
 		return errors.Wrap(err, "fail to get space")
 	}
-	if sp.StateInfo == nil || sp.StateInfo != nil && sp.StateInfo.State == StateNew || sp.StateInfo.State == StateReady || sp.StateInfo.State == StateMigration {
+	if sp.StateInfo == nil || slices.Contains(ReadAllowedStates, sp.StateInfo.State) {
 		return nil
 	}
 	return errors.WithContext(ErrSpaceNotAvailable, "state", sp.StateInfo.State)
diff --git a/pkg/spaces/space.go b/pkg/spaces/space.go
index 985cd6c5..baa44124 100644
--- a/pkg/spaces/space.go
+++ b/pkg/spaces/space.go
@@ -46,6 +46,20 @@ func (s State) String() string {
 	}
 }
 
+var (
+	ReadAllowedStates = []State{
+		StateNew,
+		StateReady,
+		StateMigrationScheduled,
+		StateMigration,
+	}
+
+	WriteAllowedStates = []State{
+		StateNew,
+		StateReady,
+	}
+)
+
 type Config struct {
 	Features []string // Deprecated Возможности используемые пространством
 }
-- 
GitLab