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

Commit62a9a0c

Browse files
committed
feat: add shared_with_group search filter
1 parentf53b85b commit62a9a0c

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

‎coderd/searchquery/search.go‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ func Workspaces(ctx context.Context, db database.Store, query string, page coder
227227
filter.OrganizationID=parseOrganization(ctx,db,parser,values,"organization")
228228
filter.Shared=parser.NullableBoolean(values, sql.NullBool{},"shared")
229229
filter.SharedWithUserID=parseUser(ctx,db,parser,values,"shared_with_user")
230+
filter.SharedWithGroupID=parseGroup(ctx,db,parser,values,"shared_with_group")
230231

231232
typeparamMatchstruct {
232233
namestring
@@ -383,6 +384,66 @@ func parseUser(ctx context.Context, db database.Store, parser *httpapi.QueryPara
383384
})
384385
}
385386

387+
// Parse a group filter value into a group UUID.
388+
// Supported formats:
389+
// - <group-uuid>
390+
// - <organization-name>/<group-name>
391+
// - <group-name> (resolved in the default organization)
392+
funcparseGroup(ctx context.Context,db database.Store,parser*httpapi.QueryParamParser,vals url.Values,queryParamstring) uuid.UUID {
393+
returnhttpapi.ParseCustom(parser,vals,uuid.Nil,queryParam,func(vstring) (uuid.UUID,error) {
394+
ifv=="" {
395+
returnuuid.Nil,nil
396+
}
397+
groupID,err:=uuid.Parse(v)
398+
iferr==nil {
399+
returngroupID,nil
400+
}
401+
402+
vargroupNamestring
403+
varorg database.Organization
404+
parts:=strings.Split(v,"/")
405+
switchlen(parts) {
406+
case1:
407+
dbOrg,err:=db.GetDefaultOrganization(ctx)
408+
iferr!=nil {
409+
returnuuid.Nil,xerrors.New("fetching default organization")
410+
}
411+
org=dbOrg
412+
groupName=parts[0]
413+
case2:
414+
orgName:=parts[0]
415+
iferr:=codersdk.NameValid(orgName);err!=nil {
416+
returnuuid.Nil,xerrors.Errorf("invalid organization name %w",err)
417+
}
418+
dbOrg,err:=db.GetOrganizationByName(ctx, database.GetOrganizationByNameParams{
419+
Name:orgName,
420+
})
421+
iferr!=nil {
422+
returnuuid.Nil,xerrors.Errorf("organization %q either does not exist, or you are unauthorized to view it",orgName)
423+
}
424+
org=dbOrg
425+
426+
groupName=parts[1]
427+
428+
default:
429+
returnuuid.Nil,xerrors.New("invalid organization or group name, the filter must be in the pattern of <organization name>/<group name>")
430+
}
431+
432+
iferr:=codersdk.GroupNameValid(groupName);err!=nil {
433+
returnuuid.Nil,xerrors.Errorf("invalid group name %w",err)
434+
}
435+
436+
group,err:=db.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{
437+
OrganizationID:org.ID,
438+
Name:groupName,
439+
})
440+
iferr!=nil {
441+
returnuuid.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)
442+
}
443+
returngroup.ID,nil
444+
})
445+
}
446+
386447
// splitQueryParameterByDelimiter takes a query string and splits it into the individual elements
387448
// of the query. Each element is separated by a delimiter. All quoted strings are
388449
// kept as a single element.

‎codersdk/workspaces.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ type WorkspaceFilter struct {
520520
Shared*bool`json:"shared,omitempty" typescript:"-"`
521521
// SharedWithUser is the username or ID of the user that the workspace is shared with
522522
SharedWithUserstring`json:"shared_with_user,omitempty" typescript:"-"`
523+
// SharedWithGroup is the group name, group ID, or <org name>/<group name> of the group that the workspace is shared with
524+
SharedWithGroupstring`json:"shared_with_group,omitempty" typescript:"-"`
523525
// FilterQuery supports a raw filter query string
524526
FilterQuerystring`json:"q,omitempty"`
525527
}
@@ -549,6 +551,9 @@ func (f WorkspaceFilter) asRequestOption() RequestOption {
549551
iff.SharedWithUser!="" {
550552
params=append(params,fmt.Sprintf("shared_with_user:%q",f.SharedWithUser))
551553
}
554+
iff.SharedWithGroup!="" {
555+
params=append(params,fmt.Sprintf("shared_with_group:%q",f.SharedWithGroup))
556+
}
552557
iff.FilterQuery!="" {
553558
// If custom stuff is added, just add it on here.
554559
params=append(params,f.FilterQuery)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp