mirror of
https://github.com/coder/coder.git
synced 2026-10-16 14:48:56 +08:00
feat: default the CLI workspace search to the user filter (#29753)
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/coder/serpent"
|
||||
)
|
||||
|
||||
var defaultQuery = "owner:me"
|
||||
var defaultQuery = "user:me"
|
||||
|
||||
// WorkspaceFilter wraps codersdk.WorkspaceFilter
|
||||
// and allows easy integration to a CLI command.
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ func (r *RootCmd) list() *serpent.Command {
|
||||
workspaceFilter.SharedWithUser = user.ID.String()
|
||||
|
||||
// Unset the default query that conflicts with the --shared-with-me flag
|
||||
if workspaceFilter.FilterQuery == "owner:me" {
|
||||
if workspaceFilter.FilterQuery == "user:me" {
|
||||
workspaceFilter.FilterQuery = ""
|
||||
}
|
||||
}
|
||||
|
||||
+20
-3
@@ -127,24 +127,41 @@ func TestList(t *testing.T) {
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
|
||||
client.UpdateWorkspaceACL(ctx, sharedWorkspace.ID, codersdk.UpdateWorkspaceACL{
|
||||
// Share orgOwner's workspace with member
|
||||
err := client.UpdateWorkspaceACL(ctx, sharedWorkspace.ID, codersdk.UpdateWorkspaceACL{
|
||||
UserRoles: map[string]codersdk.WorkspaceRole{
|
||||
member.ID.String(): codersdk.WorkspaceRoleUse,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
inv, root := clitest.New(t, "list", "--shared-with-me", "--output=json")
|
||||
// member should see the workspace with the default filter
|
||||
inv, root := clitest.New(t, "list", "--output=json")
|
||||
clitest.SetupConfig(t, memberClient, root)
|
||||
|
||||
stdout := new(bytes.Buffer)
|
||||
inv.Stdout = stdout
|
||||
err := inv.WithContext(ctx).Run()
|
||||
err = inv.WithContext(ctx).Run()
|
||||
require.NoError(t, err)
|
||||
|
||||
var workspaces []codersdk.Workspace
|
||||
require.NoError(t, json.Unmarshal(stdout.Bytes(), &workspaces))
|
||||
require.Len(t, workspaces, 1)
|
||||
require.Equal(t, sharedWorkspace.ID, workspaces[0].ID)
|
||||
|
||||
// member should see the workspace when passing `--shared-with-me`
|
||||
inv, root = clitest.New(t, "list", "--shared-with-me", "--output=json")
|
||||
clitest.SetupConfig(t, memberClient, root)
|
||||
|
||||
stdout = new(bytes.Buffer)
|
||||
inv.Stdout = stdout
|
||||
err = inv.WithContext(ctx).Run()
|
||||
require.NoError(t, err)
|
||||
|
||||
workspaces = nil
|
||||
require.NoError(t, json.Unmarshal(stdout.Bytes(), &workspaces))
|
||||
require.Len(t, workspaces, 1)
|
||||
require.Equal(t, sharedWorkspace.ID, workspaces[0].ID)
|
||||
})
|
||||
|
||||
t.Run("HTMLResponse", func(t *testing.T) {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ OPTIONS:
|
||||
-o, --output table|json (default: table)
|
||||
Output format.
|
||||
|
||||
--search string (default: owner:me)
|
||||
--search string (default: user:me)
|
||||
Search for a workspace with a query.
|
||||
|
||||
———
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ OPTIONS:
|
||||
-o, --output table|json (default: table)
|
||||
Output format.
|
||||
|
||||
--search string (default: owner:me)
|
||||
--search string (default: user:me)
|
||||
Search for a workspace with a query.
|
||||
|
||||
———
|
||||
|
||||
+4
-4
@@ -30,10 +30,10 @@ Specifies whether all workspaces will be listed or not.
|
||||
|
||||
### --search
|
||||
|
||||
| | |
|
||||
|---------|-----------------------|
|
||||
| Type | <code>string</code> |
|
||||
| Default | <code>owner:me</code> |
|
||||
| | |
|
||||
|---------|----------------------|
|
||||
| Type | <code>string</code> |
|
||||
| Default | <code>user:me</code> |
|
||||
|
||||
Search for a workspace with a query.
|
||||
|
||||
|
||||
Generated
+4
-4
@@ -30,10 +30,10 @@ Specifies whether all workspaces will be listed or not.
|
||||
|
||||
### --search
|
||||
|
||||
| | |
|
||||
|---------|-----------------------|
|
||||
| Type | <code>string</code> |
|
||||
| Default | <code>owner:me</code> |
|
||||
| | |
|
||||
|---------|----------------------|
|
||||
| Type | <code>string</code> |
|
||||
| Default | <code>user:me</code> |
|
||||
|
||||
Search for a workspace with a query.
|
||||
|
||||
|
||||
Generated
+4
-4
@@ -37,10 +37,10 @@ Specifies whether all workspaces will be listed or not.
|
||||
|
||||
### --search
|
||||
|
||||
| | |
|
||||
|---------|-----------------------|
|
||||
| Type | <code>string</code> |
|
||||
| Default | <code>owner:me</code> |
|
||||
| | |
|
||||
|---------|----------------------|
|
||||
| Type | <code>string</code> |
|
||||
| Default | <code>user:me</code> |
|
||||
|
||||
Search for a workspace with a query.
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ OPTIONS:
|
||||
-o, --output table|json (default: table)
|
||||
Output format.
|
||||
|
||||
--search string (default: owner:me)
|
||||
--search string (default: user:me)
|
||||
Search for a workspace with a query.
|
||||
|
||||
———
|
||||
|
||||
Reference in New Issue
Block a user