Skip to content

Commit

Permalink
fix(Global Search): add support for is_project_resource query param
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrizio Leoni <[email protected]>
  • Loading branch information
fabrizio-leoni authored May 28, 2024
1 parent 6a88f9a commit c1aa9c7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
26 changes: 26 additions & 0 deletions globalsearchv2/global_search_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ func (globalSearch *GlobalSearchV2) SearchWithContext(ctx context.Context, searc
if searchOptions.CanTag != nil {
builder.AddQuery("can_tag", fmt.Sprint(*searchOptions.CanTag))
}
if searchOptions.IsProjectResource != nil {
builder.AddQuery("is_project_resource", fmt.Sprint(*searchOptions.IsProjectResource))
}

body := make(map[string]interface{})
if searchOptions.Query != nil {
Expand Down Expand Up @@ -488,6 +491,12 @@ type SearchOptions struct {
// only resources that user has permissions for tagging are returned (_for administrators only_).
CanTag *string `json:"can_tag,omitempty"`

// Determines if documents belonging to Project family should be included in result set or not. Possible values are
// false (default), true or any. If false, documents belonging to all families except Project are returned; if true,
// only documents belonging to Project family are returned; if any, documents of any family are returned. Only
// authorized ServiceIds can use this query parameter.
IsProjectResource *string `json:"is_project_resource,omitempty"`

// Allows users to set headers on API requests
Headers map[string]string
}
Expand Down Expand Up @@ -531,6 +540,17 @@ const (
SearchOptionsCanTagTrueConst = "true"
)

// Constants associated with the SearchOptions.IsProjectResource property.
// Determines if documents belonging to Project family should be included in result set or not. Possible values are
// false (default), true or any. If false, documents belonging to all families except Project are returned; if true,
// only documents belonging to Project family are returned; if any, documents of any family are returned. Only
// authorized ServiceIds can use this query parameter.
const (
SearchOptionsIsProjectResourceAnyConst = "any"
SearchOptionsIsProjectResourceFalseConst = "false"
SearchOptionsIsProjectResourceTrueConst = "true"
)

// NewSearchOptions : Instantiate SearchOptions
func (*GlobalSearchV2) NewSearchOptions() *SearchOptions {
return &SearchOptions{}
Expand Down Expand Up @@ -620,6 +640,12 @@ func (_options *SearchOptions) SetCanTag(canTag string) *SearchOptions {
return _options
}

// SetIsProjectResource : Allow user to set IsProjectResource
func (_options *SearchOptions) SetIsProjectResource(isProjectResource string) *SearchOptions {
_options.IsProjectResource = core.StringPtr(isProjectResource)
return _options
}

// SetHeaders : Allow user to set Headers
func (options *SearchOptions) SetHeaders(param map[string]string) *SearchOptions {
options.Headers = param
Expand Down
10 changes: 10 additions & 0 deletions globalsearchv2/global_search_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
Expect(req.URL.Query()["is_public"]).To(Equal([]string{"false"}))
Expect(req.URL.Query()["impersonate_user"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["can_tag"]).To(Equal([]string{"false"}))
Expect(req.URL.Query()["is_project_resource"]).To(Equal([]string{"false"}))
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
fmt.Fprint(res, `} this is not valid json {`)
Expand Down Expand Up @@ -214,6 +215,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
searchOptionsModel.IsPublic = core.StringPtr("false")
searchOptionsModel.ImpersonateUser = core.StringPtr("testString")
searchOptionsModel.CanTag = core.StringPtr("false")
searchOptionsModel.IsProjectResource = core.StringPtr("false")
searchOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
// Expect response parsing to fail since we are receiving a text/plain response
result, response, operationErr := globalSearchService.Search(searchOptionsModel)
Expand Down Expand Up @@ -272,6 +274,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
Expect(req.URL.Query()["is_public"]).To(Equal([]string{"false"}))
Expect(req.URL.Query()["impersonate_user"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["can_tag"]).To(Equal([]string{"false"}))
Expect(req.URL.Query()["is_project_resource"]).To(Equal([]string{"false"}))
// Sleep a short time to support a timeout test
time.Sleep(100 * time.Millisecond)

Expand Down Expand Up @@ -306,6 +309,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
searchOptionsModel.IsPublic = core.StringPtr("false")
searchOptionsModel.ImpersonateUser = core.StringPtr("testString")
searchOptionsModel.CanTag = core.StringPtr("false")
searchOptionsModel.IsProjectResource = core.StringPtr("false")
searchOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation with a Context to test a timeout error
Expand Down Expand Up @@ -370,6 +374,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
Expect(req.URL.Query()["is_public"]).To(Equal([]string{"false"}))
Expect(req.URL.Query()["impersonate_user"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["can_tag"]).To(Equal([]string{"false"}))
Expect(req.URL.Query()["is_project_resource"]).To(Equal([]string{"false"}))
// Set mock response
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
Expand Down Expand Up @@ -406,6 +411,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
searchOptionsModel.IsPublic = core.StringPtr("false")
searchOptionsModel.ImpersonateUser = core.StringPtr("testString")
searchOptionsModel.CanTag = core.StringPtr("false")
searchOptionsModel.IsProjectResource = core.StringPtr("false")
searchOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation with valid options model (positive test)
Expand Down Expand Up @@ -439,6 +445,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
searchOptionsModel.IsPublic = core.StringPtr("false")
searchOptionsModel.ImpersonateUser = core.StringPtr("testString")
searchOptionsModel.CanTag = core.StringPtr("false")
searchOptionsModel.IsProjectResource = core.StringPtr("false")
searchOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
// Invoke operation with empty URL (negative test)
err := globalSearchService.SetServiceURL("")
Expand Down Expand Up @@ -486,6 +493,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
searchOptionsModel.IsPublic = core.StringPtr("false")
searchOptionsModel.ImpersonateUser = core.StringPtr("testString")
searchOptionsModel.CanTag = core.StringPtr("false")
searchOptionsModel.IsProjectResource = core.StringPtr("false")
searchOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation
Expand Down Expand Up @@ -524,6 +532,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
searchOptionsModel.SetIsPublic("false")
searchOptionsModel.SetImpersonateUser("testString")
searchOptionsModel.SetCanTag("false")
searchOptionsModel.SetIsProjectResource("false")
searchOptionsModel.SetHeaders(map[string]string{"foo": "bar"})
Expect(searchOptionsModel).ToNot(BeNil())
Expect(searchOptionsModel.Query).To(Equal(core.StringPtr("testString")))
Expand All @@ -540,6 +549,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
Expect(searchOptionsModel.IsPublic).To(Equal(core.StringPtr("false")))
Expect(searchOptionsModel.ImpersonateUser).To(Equal(core.StringPtr("testString")))
Expect(searchOptionsModel.CanTag).To(Equal(core.StringPtr("false")))
Expect(searchOptionsModel.IsProjectResource).To(Equal(core.StringPtr("false")))
Expect(searchOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"}))
})
})
Expand Down

0 comments on commit c1aa9c7

Please sign in to comment.