Misc fixes for handling groups (#4195)

A bunch of places where we missed handling groups
<!-- PR description-->

---

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abin Simon 2023-09-07 12:06:18 +05:30 committed by GitHub
parent f742318319
commit eb8f3131f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 37 deletions

View File

@ -10,7 +10,7 @@ func IsMetadataFile(p path.Path) bool {
case path.OneDriveService: case path.OneDriveService:
return metadata.HasMetaSuffix(p.Item()) return metadata.HasMetaSuffix(p.Item())
case path.SharePointService: case path.SharePointService, path.GroupsService:
return p.Category() == path.LibrariesCategory && metadata.HasMetaSuffix(p.Item()) return p.Category() == path.LibrariesCategory && metadata.HasMetaSuffix(p.Item())
default: default:

View File

@ -73,6 +73,11 @@ var (
category: path.PagesCategory, category: path.PagesCategory,
expected: assert.Falsef, expected: assert.Falsef,
}, },
{
service: path.GroupsService,
category: path.LibrariesCategory,
expected: assert.Truef,
},
} }
) )

View File

@ -47,8 +47,8 @@ func (d *Details) add(
// Use the item name and the path for the ShortRef. This ensures that renames // Use the item name and the path for the ShortRef. This ensures that renames
// within a directory generate unique ShortRefs. // within a directory generate unique ShortRefs.
if info.infoType() == OneDriveItem || info.infoType() == SharePointLibrary { if info.infoType() == OneDriveItem || info.infoType() == SharePointLibrary {
if info.OneDrive == nil && info.SharePoint == nil { if info.OneDrive == nil && info.SharePoint == nil && info.Groups == nil {
return entry, clues.New("item is not SharePoint or OneDrive type") return entry, clues.New("item is not Groups, SharePoint or OneDrive type")
} }
// clean metadata suffixes from item refs // clean metadata suffixes from item refs

View File

@ -207,32 +207,51 @@ func exchangeEntry(t *testing.T, id string, size int, it ItemType) Entry {
} }
} }
func oneDriveishEntry(t *testing.T, id string, size int, it ItemType) Entry { func oneDriveishEntry(t *testing.T, id string, size int, it ItemType, service path.ServiceType) Entry {
service := path.OneDriveService var (
category := path.FilesCategory category path.CategoryType
info := ItemInfo{ info ItemInfo
OneDrive: &OneDriveInfo{ )
ItemName: "bar",
DriveID: "drive-id",
DriveName: "drive-name",
Modified: time.Now(),
ItemType: it,
Size: int64(size),
},
}
if it == SharePointLibrary { switch it {
service = path.SharePointService case OneDriveItem:
category = path.FilesCategory
info = ItemInfo{
OneDrive: &OneDriveInfo{
ItemName: "bar",
DriveID: "drive-id",
DriveName: "drive-name",
Modified: time.Now(),
ItemType: it,
Size: int64(size),
},
}
case SharePointLibrary:
category = path.LibrariesCategory category = path.LibrariesCategory
info.OneDrive = nil switch service {
info.SharePoint = &SharePointInfo{ case path.SharePointService:
ItemName: "bar", info = ItemInfo{
DriveID: "drive-id", SharePoint: &SharePointInfo{
DriveName: "drive-name", ItemName: "bar",
Modified: time.Now(), DriveID: "drive-id",
ItemType: it, DriveName: "drive-name",
Size: int64(size), Modified: time.Now(),
ItemType: it,
Size: int64(size),
},
}
case path.GroupsService:
info = ItemInfo{
Groups: &GroupsInfo{
ItemName: "bar",
DriveID: "drive-id",
DriveName: "drive-name",
Modified: time.Now(),
ItemType: it,
Size: int64(size),
},
}
} }
} }
@ -277,21 +296,25 @@ func (suite *DetailsUnitSuite) TestDetailsAdd_NoLocationFolders() {
}, },
{ {
name: "OneDrive File", name: "OneDrive File",
entry: oneDriveishEntry(t, itemID, 42, OneDriveItem), entry: oneDriveishEntry(t, itemID, 42, OneDriveItem, path.OneDriveService),
}, },
{ {
name: "SharePoint File", name: "SharePoint File",
entry: oneDriveishEntry(t, itemID, 42, SharePointLibrary), entry: oneDriveishEntry(t, itemID, 42, SharePointLibrary, path.SharePointService),
}, },
{ {
name: "Legacy SharePoint File", name: "Legacy SharePoint File",
entry: func() Entry { entry: func() Entry {
res := oneDriveishEntry(t, itemID, 42, SharePointLibrary) res := oneDriveishEntry(t, itemID, 42, SharePointLibrary, path.SharePointService)
res.SharePoint.ItemType = OneDriveItem res.SharePoint.ItemType = OneDriveItem
return res return res
}(), }(),
}, },
{
name: "Group SharePoint File",
entry: oneDriveishEntry(t, itemID, 42, SharePointLibrary, path.GroupsService),
},
} }
for _, test := range table { for _, test := range table {
@ -333,11 +356,11 @@ func (suite *DetailsUnitSuite) TestDetailsAdd_LocationFolders() {
t := suite.T() t := suite.T()
exchangeMail1 := exchangeEntry(t, "foo1", 42, ExchangeMail) exchangeMail1 := exchangeEntry(t, "foo1", 42, ExchangeMail)
oneDrive1 := oneDriveishEntry(t, "foo1", 42, OneDriveItem) oneDrive1 := oneDriveishEntry(t, "foo1", 42, OneDriveItem, path.OneDriveService)
sharePoint1 := oneDriveishEntry(t, "foo1", 42, SharePointLibrary) sharePoint1 := oneDriveishEntry(t, "foo1", 42, SharePointLibrary, path.SharePointService)
sharePointLegacy1 := oneDriveishEntry(t, "foo1", 42, SharePointLibrary) sharePointLegacy1 := oneDriveishEntry(t, "foo1", 42, SharePointLibrary, path.SharePointService)
sharePointLegacy1.SharePoint.ItemType = OneDriveItem sharePointLegacy1.SharePoint.ItemType = OneDriveItem
group1 := oneDriveishEntry(t, "foo1", 42, SharePointLibrary, path.GroupsService)
// Sleep for a little so we get a larger difference in mod times between the // Sleep for a little so we get a larger difference in mod times between the
// earlier and later entries. // earlier and later entries.
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
@ -611,6 +634,33 @@ func (suite *DetailsUnitSuite) TestDetailsAdd_LocationFolders() {
res = append(res, e) res = append(res, e)
} }
return res
},
},
{
name: "One Group SharePoint Item",
entries: func() []Entry {
e := group1
ei := *group1.Groups
e.Groups = &ei
return []Entry{e}
},
expectedDirs: func() []Entry {
res := []Entry{}
for _, entry := range oneDriveishFolders {
e := entry
ei := *entry.Folder
e.Folder = &ei
e.Folder.DataType = SharePointLibrary
e.Folder.Size = group1.Groups.Size
e.Folder.Modified = group1.Groups.Modified
res = append(res, e)
}
return res return res
}, },
}, },

View File

@ -17,7 +17,6 @@ func NewGroupsLocationIDer(
driveID string, driveID string,
escapedFolders ...string, escapedFolders ...string,
) (uniqueLoc, error) { ) (uniqueLoc, error) {
// TODO(meain): path fixes
if err := path.ValidateServiceAndCategory(path.GroupsService, category); err != nil { if err := path.ValidateServiceAndCategory(path.GroupsService, category); err != nil {
return uniqueLoc{}, clues.Wrap(err, "making groups LocationIDer") return uniqueLoc{}, clues.Wrap(err, "making groups LocationIDer")
} }
@ -26,12 +25,12 @@ func NewGroupsLocationIDer(
prefixElems := 1 prefixElems := 1
if driveID != "" { // non sp paths don't have driveID if driveID != "" { // non sp paths don't have driveID
pb.Append(driveID) pb = pb.Append(driveID)
prefixElems = 2 prefixElems = 2
} }
pb.Append(escapedFolders...) pb = pb.Append(escapedFolders...)
return uniqueLoc{pb, prefixElems}, nil return uniqueLoc{pb, prefixElems}, nil
} }
@ -125,7 +124,6 @@ func (i *GroupsInfo) uniqueLocation(baseLoc *path.Builder) (*uniqueLoc, error) {
} }
func (i *GroupsInfo) updateFolder(f *FolderInfo) error { func (i *GroupsInfo) updateFolder(f *FolderInfo) error {
// TODO(meain): path updates if any
if i.ItemType == SharePointLibrary { if i.ItemType == SharePointLibrary {
return updateFolderWithinDrive(SharePointLibrary, i.DriveName, i.DriveID, f) return updateFolderWithinDrive(SharePointLibrary, i.DriveName, i.DriveID, f)
} }