filter out personal sites (#1554)
## Description Adds a server-side filter that removes all personal (aka: oneDrive) sites from the drive retrieval. The approach is not my preferred method. I'd rather have used a filter in the query parameters. In fact, I have a functioning query in postman: `$filter=NOT contains(webUrl, 'sharepoint.com/personal/')` But I can't seem to get the graph client query to build when I add that to the query params. ## Type of change - [x] 🌻 Feature ## Issue(s) * #1506 ## Test Plan - [x] 💚 E2E
This commit is contained in:
parent
162713dc54
commit
d6522e01ae
@ -220,6 +220,8 @@ func (gc *GraphConnector) setTenantSites(ctx context.Context) error {
|
||||
|
||||
var errKnownSkippableCase = errors.New("case is known and skippable")
|
||||
|
||||
const personalSitePath = "sharepoint.com/personal/"
|
||||
|
||||
// Transforms an interface{} into a key,value pair representing
|
||||
// siteName:siteID.
|
||||
func identifySite(item any) (string, string, error) {
|
||||
@ -237,6 +239,12 @@ func identifySite(item any) (string, string, error) {
|
||||
return "", "", errors.Errorf("no name for Site: %s", *m.GetId())
|
||||
}
|
||||
|
||||
// personal (ie: oneDrive) sites have to be filtered out server-side.
|
||||
url := m.GetWebUrl()
|
||||
if url != nil && strings.Contains(*url, personalSitePath) {
|
||||
return "", "", errKnownSkippableCase
|
||||
}
|
||||
|
||||
return *m.GetName(), *m.GetId(), nil
|
||||
}
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ func (suite *GraphConnectorIntegrationSuite) TestSetTenantUsers() {
|
||||
|
||||
newConnector.graphService = *service
|
||||
|
||||
suite.Equal(len(newConnector.Users), 0)
|
||||
suite.Empty(len(newConnector.Users))
|
||||
err = newConnector.setTenantUsers(ctx)
|
||||
suite.NoError(err)
|
||||
suite.Less(0, len(newConnector.Users))
|
||||
@ -93,6 +93,10 @@ func (suite *GraphConnectorIntegrationSuite) TestSetTenantSites() {
|
||||
err = newConnector.setTenantSites(ctx)
|
||||
suite.NoError(err)
|
||||
suite.Less(0, len(newConnector.Sites))
|
||||
|
||||
for _, site := range newConnector.Sites {
|
||||
suite.NotContains("sharepoint.com/personal/", site)
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() {
|
||||
|
||||
@ -10,6 +10,8 @@ import (
|
||||
)
|
||||
|
||||
// GetAllSitesForTenant makes a GraphQuery request retrieving all sites in the tenant.
|
||||
// Due to restrictions in filter capabilities for site queries, the returned iterable
|
||||
// will contain all personal sites for all users in the org.
|
||||
func GetAllSitesForTenant(ctx context.Context, gs graph.Service) (absser.Parsable, error) {
|
||||
options := &mssite.SitesRequestBuilderGetRequestConfiguration{
|
||||
QueryParameters: &mssite.SitesRequestBuilderGetQueryParameters{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user