Skip to content

Commit

Permalink
fixed comments for shared workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerfong committed Feb 8, 2024
1 parent b7a8971 commit e4e1f9a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/ls/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions pkg/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"regexp"
"strings"
"time"

"github.com/brevdev/brev-cli/pkg/collections"

Check failure on line 11 in pkg/entity/entity.go

View workflow job for this annotation

GitHub Actions / ci (ubuntu-20.04)

could not import github.com/brevdev/brev-cli/pkg/collections (-: build constraints exclude all Go files in pkg/collections) (typecheck)

Check failure on line 11 in pkg/entity/entity.go

View workflow job for this annotation

GitHub Actions / ci (ubuntu-20.04)

could not import github.com/brevdev/brev-cli/pkg/collections (-: build constraints exclude all Go files in pkg/collections) (typecheck)

Check failure on line 11 in pkg/entity/entity.go

View workflow job for this annotation

GitHub Actions / goreleaser

could not import github.com/brevdev/brev-cli/pkg/collections (-: build constraints exclude all Go files in pkg/collections) (typecheck)
)

const WorkspaceGroupDevPlane = "devplane-brev-1"
Expand Down Expand Up @@ -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 == "" {
Expand Down
12 changes: 0 additions & 12 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 2 additions & 16 deletions pkg/store/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit e4e1f9a

Please sign in to comment.