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

Commit6cff66f

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

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

‎coderd/searchquery/search.go‎

Lines changed: 60 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,65 @@ func parseUser(ctx context.Context, db database.Store, parser *httpapi.QueryPara
383384
})
384385
}
385386

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