Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add shared_with_group: and shared_with_user: filters to /workspaces endpoint#19875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
brettkolodny merged 6 commits intomainfrombrett/i1004
Sep 19, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletionscoderd/database/modelqueries.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -276,6 +276,8 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
arg.HasAITask,
arg.HasExternalAgent,
arg.Shared,
arg.SharedWithUserID,
arg.SharedWithGroupID,
arg.RequesterID,
arg.Offset,
arg.Limit,
Expand Down
27 changes: 21 additions & 6 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

13 changes: 12 additions & 1 deletioncoderd/database/queries/workspaces.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,7 +384,18 @@ WHERE
(workspaces.user_acl!='{}'::jsonbORworkspaces.group_acl!='{}'::jsonb)=sqlc.narg('shared') ::boolean
ELSE true
END

-- Filter by shared_with_user_id
AND CASE
WHEN @shared_with_user_id :: uuid!='00000000-0000-0000-0000-000000000000'::uuid THEN
workspaces.user_acl ? (@shared_with_user_id :: uuid) ::text
ELSE true
END
-- Filter by shared_with_group_id
AND CASE
WHEN @shared_with_group_id :: uuid!='00000000-0000-0000-0000-000000000000'::uuid THEN
workspaces.group_acl ? (@shared_with_group_id :: uuid) ::text
ELSE true
END
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
-- @authorize_filter
), filtered_workspaces_orderAS (
Expand Down
81 changes: 81 additions & 0 deletionscoderd/searchquery/search.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -226,6 +226,8 @@ func Workspaces(ctx context.Context, db database.Store, query string, page coder
filter.HasExternalAgent = parser.NullableBoolean(values, sql.NullBool{}, "has_external_agent")
filter.OrganizationID = parseOrganization(ctx, db, parser, values, "organization")
filter.Shared = parser.NullableBoolean(values, sql.NullBool{}, "shared")
filter.SharedWithUserID = parseUser(ctx, db, parser, values, "shared_with_user")
filter.SharedWithGroupID = parseGroup(ctx, db, parser, values, "shared_with_group")

type paramMatch struct {
name string
Expand DownExpand Up@@ -363,6 +365,85 @@ func parseOrganization(ctx context.Context, db database.Store, parser *httpapi.Q
})
}

func parseUser(ctx context.Context, db database.Store, parser *httpapi.QueryParamParser, vals url.Values, queryParam string) uuid.UUID {
return httpapi.ParseCustom(parser, vals, uuid.Nil, queryParam, func(v string) (uuid.UUID, error) {
if v == "" {
return uuid.Nil, nil
}
userID, err := uuid.Parse(v)
if err == nil {
return userID, nil
}
user, err := db.GetUserByEmailOrUsername(ctx, database.GetUserByEmailOrUsernameParams{
Username: v,
})
if err != nil {
return uuid.Nil, xerrors.Errorf("user %q either does not exist, or you are unauthorized to view them", v)
}
return user.ID, nil
})
}

// Parse a group filter value into a group UUID.
// Supported formats:
// - <group-uuid>
// - <organization-name>/<group-name>
// - <group-name> (resolved in the default organization)
func parseGroup(ctx context.Context, db database.Store, parser *httpapi.QueryParamParser, vals url.Values, queryParam string) uuid.UUID {
return httpapi.ParseCustom(parser, vals, uuid.Nil, queryParam, func(v string) (uuid.UUID, error) {
if v == "" {
return uuid.Nil, nil
}
groupID, err := uuid.Parse(v)
if err == nil {
return groupID, nil
}

var groupName string
var org database.Organization
parts := strings.Split(v, "/")
switch len(parts) {
case 1:
dbOrg, err := db.GetDefaultOrganization(ctx)
if err != nil {
return uuid.Nil, xerrors.New("fetching default organization")
}
org = dbOrg
groupName = parts[0]
case 2:
orgName := parts[0]
if err := codersdk.NameValid(orgName); err != nil {
return uuid.Nil, xerrors.Errorf("invalid organization name %w", err)
}
dbOrg, err := db.GetOrganizationByName(ctx, database.GetOrganizationByNameParams{
Name: orgName,
})
if err != nil {
return uuid.Nil, xerrors.Errorf("organization %q either does not exist, or you are unauthorized to view it", orgName)
}
org = dbOrg

groupName = parts[1]

default:
return uuid.Nil, xerrors.New("invalid organization or group name, the filter must be in the pattern of <organization name>/<group name>")
}

if err := codersdk.GroupNameValid(groupName); err != nil {
return uuid.Nil, xerrors.Errorf("invalid group name %w", err)
}

group, err := db.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{
OrganizationID: org.ID,
Name: groupName,
})
if err != nil {
return uuid.Nil, xerrors.Errorf("group %q either does not exist, does not belong to the organization %q, or you are unauthorized to view it", groupName, org.Name)
}
return group.ID, nil
})
}

// splitQueryParameterByDelimiter takes a query string and splits it into the individual elements
// of the query. Each element is separated by a delimiter. All quoted strings are
// kept as a single element.
Expand Down
93 changes: 93 additions & 0 deletionscoderd/searchquery/search_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -312,6 +312,84 @@ func TestSearchWorkspace(t *testing.T) {
},
},
},
{
Name: "SharedWithUser",
Query: `shared_with_user:3dd8b1b8-dff5-4b22-8ae9-c243ca136ecf`,
Setup: func(t *testing.T, db database.Store) {
dbgen.User(t, db, database.User{
ID: uuid.MustParse("3dd8b1b8-dff5-4b22-8ae9-c243ca136ecf"),
})
},
Expected: database.GetWorkspacesParams{
SharedWithUserID: uuid.MustParse("3dd8b1b8-dff5-4b22-8ae9-c243ca136ecf"),
},
},
{
Name: "SharedWithUserByName",
Query: `shared_with_user:wibble`,
Setup: func(t *testing.T, db database.Store) {
dbgen.User(t, db, database.User{
ID: uuid.MustParse("3dd8b1b8-dff5-4b22-8ae9-c243ca136ecf"),
Username: "wibble",
})
},
Expected: database.GetWorkspacesParams{
SharedWithUserID: uuid.MustParse("3dd8b1b8-dff5-4b22-8ae9-c243ca136ecf"),
},
},
{
Name: "SharedWithGroupDefaultOrg",
Query: "shared_with_group:wibble",
Setup: func(t *testing.T, db database.Store) {
org, err := db.GetOrganizationByName(t.Context(), database.GetOrganizationByNameParams{
Name: "coder",
})
require.NoError(t, err)

dbgen.Group(t, db, database.Group{
ID: uuid.MustParse("590f1006-15e6-4b21-a6e1-92e33af8a5c3"),
Name: "wibble",
OrganizationID: org.ID,
})
},
Expected: database.GetWorkspacesParams{
SharedWithGroupID: uuid.MustParse("590f1006-15e6-4b21-a6e1-92e33af8a5c3"),
},
},
{
Name: "SharedWithGroupInOrg",
Query: "shared_with_group:wibble/wobble",
Setup: func(t *testing.T, db database.Store) {
org := dbgen.Organization(t, db, database.Organization{
ID: uuid.MustParse("dbeb1bd5-dce6-459c-ab7b-b7f8b9b10467"),
Name: "wibble",
})
dbgen.Group(t, db, database.Group{
ID: uuid.MustParse("3c831688-0a5a-45a2-a796-f7648874df34"),
Name: "wobble",
OrganizationID: org.ID,
})
},
Expected: database.GetWorkspacesParams{
SharedWithGroupID: uuid.MustParse("3c831688-0a5a-45a2-a796-f7648874df34"),
},
},
{
Name: "SharedWithGroupID",
Query: "shared_with_group:a7d1ba00-53c7-4aa6-92ea-83157dd57480",
Setup: func(t *testing.T, db database.Store) {
org := dbgen.Organization(t, db, database.Organization{
ID: uuid.MustParse("8606620f-fee4-4c4e-83ba-f42db804139a"),
})
dbgen.Group(t, db, database.Group{
ID: uuid.MustParse("a7d1ba00-53c7-4aa6-92ea-83157dd57480"),
OrganizationID: org.ID,
})
},
Expected: database.GetWorkspacesParams{
SharedWithGroupID: uuid.MustParse("a7d1ba00-53c7-4aa6-92ea-83157dd57480"),
},
},

// Failures
{
Expand DownExpand Up@@ -354,6 +432,21 @@ func TestSearchWorkspace(t *testing.T) {
Query: "param:foo:value",
ExpectedErrorContains: "can only contain 1 ':'",
},
{
Name: "SharedWithGroupTooManySegments",
Query: `shared_with_group:acme/devs/extra`,
ExpectedErrorContains: "the filter must be in the pattern of <organization name>/<group name>",
},
{
Name: "SharedWithGroupEmptyOrg",
Query: `shared_with_group:/devs`,
ExpectedErrorContains: "invalid organization name",
},
{
Name: "SharedWithGroupEmptyGroup",
Query: `shared_with_group:acme/`,
ExpectedErrorContains: "organization \"acme\" either does not exist",
},
}

for _, c := range testCases {
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp