Skip to content

feat(offboarding): copy a leaver's OneDrive to recipients before licences are removed - #1281

Open
redanthrax wants to merge 1 commit into
CyberDrain:devfrom
redanthrax:6-onedrive-copy-to-user
Open

redanthrax wants to merge 1 commit into
CyberDrain:devfrom
redanthrax:6-onedrive-copy-to-user

Conversation

@redanthrax

@redanthrax redanthrax commented Nov 13, 2026 •

Copy link
Copy Markdown

Copies a leaver's OneDrive to one or more recipients during offboarding, and only removes the leaver's licences once the copy is confirmed. Offboarding without the new option is unchanged.

What it does

  • Copies the leaver's OneDrive into a /<leaver UPN>/ folder in each recipient's OneDrive. Name clashes keep both files, so nothing is overwritten.
  • Offboarding wizard: new Copy OneDrive to user(s) option. It requires Disable sign in and can't be combined with Delete user. If Remove licenses is also selected, licence removal waits until the copy completes, checking every 30 minutes for up to 13 days. If the copy fails, the licences are kept and an error is logged. Re-running only the licence step finds the same copy.
Endpoint Permission
POST ExecOneDriveCopyToUser {tenantFilter, leaver, recipients[], includeVersionHistory?} Identity.OneDrive.ReadWrite
GET ListOneDriveCopyToUser?tenantFilter=&OperationId= Identity.OneDrive.Read

Checks

A copy is refused (400) if:

  • the leaver is still enabled;
  • either user has no OneDrive;
  • a recipient is unlicensed, a guest or external user, short on space, or already has a file named like the copy folder;
  • there are more than 10 recipients, or the leaver's OneDrive has more than 1,000 root items or 100,000 items in total.

How it works

  • Uses SharePoint CreateCopyJobs. SharePoint groups the items into jobs itself.
  • The leaver's OneDrive is counted first (Graph delta). A recipient is only Completed when every job finished without errors and at least that many files were copied. Fewer files is Failed. More files, or a byte total that differs, completes with a warning.
  • On a Craft host too old to run offboarding steps in order, the licence step can run before the copy exists; it then keeps the licences.
  • Status checks hit SharePoint at most once a minute per copy.

Testing

  • Pester: 585 tests for the new code, offboarding, library copy, roles and the API docs, all passing.
  • Live, on a licensed tenant: the API copy and the wizard run both worked. Existing files were kept, and the copy arrived renamed (notes1.txt). The licence was removed after the copy completed.
  • The exact totals held live for .docx, .xlsx and .pptx files with document properties and for a OneNote notebook (12/12 files, bytes identical). Status polling works with the tenant's domain or id.

…nces are removed

Copies a leaver's OneDrive root into a /<leaver UPN> folder at the root of one or more recipients'
OneDrives, and holds licence removal until the copy is confirmed complete.

- ExecOneDriveCopyToUser (start) and ListOneDriveCopyToUser (status), with new permissions
  Identity.OneDrive.ReadWrite / Identity.OneDrive.Read so an API client can be given only this.
- SharePoint CreateCopyJobs for the root items (SharePoint may bundle several items into one job),
  KeepBoth on name conflicts (nothing overwritten), version history optional. The leaver's whole
  OneDrive is counted first (Graph delta) for file and byte totals. Limits: 1-1000 root items,
  100,000 items in total, up to 10 recipients.
- Refused before anything is written: leaver not disabled, leaver or recipient without OneDrive,
  recipient unlicensed, guest or other-organisation recipient, other tenant, not enough free space,
  or a recipient with a file named like the copy folder.
- Status per recipient (Queued / InProgress / Completed / Failed) with items, bytes and errors.
  SharePoint is polled at most once per 60 s per operation (ETag-claimed), with a capped, rotating
  set of jobs per call. Completed needs every job confirmed by SharePoint with no errors (errors
  accumulate across checks) and at least as many files copied as were counted; fewer is Failed.
  More files, or a byte total that differs, completes with a warning.
- Offboarding wizard option "Copy OneDrive to user(s)" (requires Disable sign in). The copy runs
  before licence removal; licences are removed only once that run's own copy completes, via a
  30-minute follow-up task, and are kept on failure, a missing copy or after 13 days. The copy id
  is kept with the offboarding task so re-running only the licence step finds it; the copy step
  waits briefly for the sign-in block to show before refusing; copy + Delete user is refused.
- Copy records are keyed by the tenant's id, so status works with the domain or the id.
- Offboarding without the option is unchanged; library copy helpers gain optional -TableName and
  -IgnoreVersionHistory with the old defaults.
- Pester tests for the endpoints, core functions, offboarding step and licence gate; openapi.json.
@redanthrax
redanthrax force-pushed the 6-onedrive-copy-to-user branch from 9b76999 to 095d154 Compare November 14, 2026 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant