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

Commit79140ca

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

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

‎coderd/searchquery/search.go‎

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