From e4e1f9afc738f3d56973dd6f0afb6cd0da12820b Mon Sep 17 00:00:00 2001 From: Tyler Fong Date: Thu, 8 Feb 2024 21:58:14 +0000 Subject: [PATCH] fixed comments for shared workspace --- pkg/cmd/ls/ls.go | 2 +- pkg/entity/entity.go | 10 ++++++++++ pkg/errors/errors.go | 12 ------------ pkg/store/workspace.go | 18 ++---------------- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/pkg/cmd/ls/ls.go b/pkg/cmd/ls/ls.go index 0335126d..cb273c37 100644 --- a/pkg/cmd/ls/ls.go +++ b/pkg/cmd/ls/ls.go @@ -448,7 +448,7 @@ func displayWorkspacesTable(t *terminal.Terminal, workspaces []entity.Workspace, ta.AppendHeader(header) for _, w := range workspaces { isShared := "" - if w.CreatedByUserID != userID { + if w.IsShared(userID) { isShared = "(shared)" } status := getWorkspaceDisplayStatus(w) diff --git a/pkg/entity/entity.go b/pkg/entity/entity.go index 2c5ef846..54133848 100644 --- a/pkg/entity/entity.go +++ b/pkg/entity/entity.go @@ -7,6 +7,8 @@ import ( "regexp" "strings" "time" + + "github.com/brevdev/brev-cli/pkg/collections" ) const WorkspaceGroupDevPlane = "devplane-brev-1" @@ -328,6 +330,14 @@ func (w Workspace) GetIsStoppable() bool { return w.IsStoppable } +func (w Workspace) CanShow(userID string) bool { + return w.CreatedByUserID == userID || (w.AdditionalUsers != nil && collections.ListContains(w.AdditionalUsers, userID)) +} + +func (w Workspace) IsShared(userID string) bool { + return w.CreatedByUserID != userID && (w.AdditionalUsers != nil && collections.ListContains(w.AdditionalUsers, userID)) +} + func (w Workspace) GetHostname() string { hostname := w.DNS if hostname == "" { diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go index 7d030208..9586c1ba 100644 --- a/pkg/errors/errors.go +++ b/pkg/errors/errors.go @@ -5,9 +5,6 @@ import ( "runtime" "time" - "github.com/brevdev/brev-cli/pkg/cmd/version" - "github.com/brevdev/brev-cli/pkg/config" - "github.com/brevdev/brev-cli/pkg/featureflag" "github.com/getsentry/sentry-go" "github.com/pkg/errors" ) @@ -45,15 +42,6 @@ type SentryErrorReporter struct{} var _ ErrorReporter = SentryErrorReporter{} func (s SentryErrorReporter) Setup() func() { - if !featureflag.IsDev() { - err := sentry.Init(sentry.ClientOptions{ - Dsn: config.GlobalConfig.GetSentryURL(), - Release: version.Version, - }) - if err != nil { - fmt.Println(err) - } - } return func() { err := recover() if err != nil { diff --git a/pkg/store/workspace.go b/pkg/store/workspace.go index d96a6343..31e64041 100644 --- a/pkg/store/workspace.go +++ b/pkg/store/workspace.go @@ -5,7 +5,6 @@ import ( "fmt" "io/ioutil" - "github.com/brevdev/brev-cli/pkg/collections" "github.com/brevdev/brev-cli/pkg/config" "github.com/brevdev/brev-cli/pkg/entity" breverrors "github.com/brevdev/brev-cli/pkg/errors" @@ -168,14 +167,8 @@ func (s AuthHTTPStore) GetWorkspaces(organizationID string, options *GetWorkspac if options.UserID != "" { userWorkspaces := []entity.Workspace{} for _, w := range workspaces { - if w.CreatedByUserID == options.UserID { + if w.CanShow(options.UserID) { userWorkspaces = append(userWorkspaces, w) - } else { - if w.AdditionalUsers != nil { - if collections.ListContains(w.AdditionalUsers, options.UserID) { - userWorkspaces = append(userWorkspaces, w) - } - } } } workspaces = userWorkspaces @@ -197,16 +190,9 @@ func (s AuthHTTPStore) GetWorkspaces(organizationID string, options *GetWorkspac func FilterForUserWorkspaces(workspaces []entity.Workspace, userID string) []entity.Workspace { filteredWorkspaces := []entity.Workspace{} for _, w := range workspaces { - if w.CreatedByUserID == userID { + if w.CanShow(userID) { filteredWorkspaces = append(filteredWorkspaces, w) - } else { - if w.AdditionalUsers != nil { - if collections.ListContains(w.AdditionalUsers, userID) { - filteredWorkspaces = append(filteredWorkspaces, w) - } - } } - } return filteredWorkspaces }