Skip to content

feat: add InstanceSessionManager (switch + logout) and route forced logout through it - #681

Merged
RawanMatar89 merged 2 commits into
openedx:developfrom
zeit-labs:infra/08-session-lifecycle
Sep 22, 2026
Merged

RawanMatar89 merged 2 commits into
openedx:developfrom
zeit-labs:infra/08-session-lifecycle

Conversation

@RawanMatar89

Copy link
Copy Markdown
Contributor

Base

Stacked on infra/07-coredata-downloads-scoping.

What's in this PR

Implements infra-only — no Presentation-layer files touched.

Logout no longer wipes a session's cached content, only its actual session state.

  • InstanceSessionManagerProtocol splits into two methods:
    • switchActiveInstance(to:) — pure selection change, no teardown at all. Not called from anywhere yet (no picker UI exists), but built now.
    • logoutCurrentInstance() — cancels in-flight downloads, unregisters this device's push token, clears storage (Keychain tokens/cached user), then clears the instance selection last. Deliberately does not clear CoreData rows or delete downloaded files — a later re-login to the same instance resumes fast instead of re-fetching everything.
  • AppDelegate.didUserLogout now calls logoutCurrentInstance() instead of the three separate .clear() / .deleteAllProgress() / .deleteAll() calls it used to make inline.
  • New Core/Core/Configuration/PushTokenUnregistering.swift: a small protocol so logoutCurrentInstance() can call an app-target push-unregister step without depending on push/Firebase wiring (a later PR) landing first. InstanceSessionManager takes it as an optional dependency (nil today, so the step is simply skipped) rather than the reference implementation's required-protocol-with-default-no-op-extension shape, since nothing conforms to it yet and an optional avoids forcing a placeholder DI registration for a capability nobody can exercise yet.
  • CoreDataHandlerProtocol.clear(instanceKey:) / DatabaseManager's implementation are kept as built, but are no longer called by logout — left in place as general per-instance infra (e.g. a future explicit "remove this instance's data" action), not dead-ended.
  • Wired InstanceSessionManagerProtocol through AppAssembly.
  • InstanceSessionManagerTests covers: switch does no teardown, logout tears down session state but not cached content, and logout still completes when no push conformance is wired.
  • CoreDataHandlerProtocol gains clear(instanceKey:), implemented in DatabaseManager via one NSBatchDeleteRequest per instanceKey-scoped entity (CDDownloadData, CDOfflineProgress, CDCourseItem, CDDownloadCoursePreview) against the shared merged store.

…ogout through it

Implements infra-only -- no Presentation-layer files touched.

logout no longer wipes a session's cached content, only its actual session state.

- InstanceSessionManagerProtocol splits into two methods:
  - switchActiveInstance(to:) -- pure selection change, no teardown at all.
    Not called from anywhere yet (no picker UI exists), but built now.
  - logoutCurrentInstance() -- cancels in-flight downloads, unregisters this
    device's push token, clears storage (Keychain tokens/cached user), then
    clears the instance selection last. Deliberately does NOT clear CoreData
    rows or delete downloaded files -- a later re-login to the same instance
    resumes fast instead of re-fetching everything.
- AppDelegate.didUserLogout now calls logoutCurrentInstance() instead of the
  three separate .clear()/.deleteAllProgress()/.deleteAll() calls it used to
  make inline.
- New Core/Core/Configuration/PushTokenUnregistering.swift: a small protocol
  so logoutCurrentInstance() can call an app-target push-unregister step
  without depending on push/Firebase wiring (a later PR) landing first.
  InstanceSessionManager takes it as an optional dependency (nil today, so
  the step is simply skipped) rather than the reference implementation's
  required-protocol-with-default-no-op-extension shape, since nothing
  conforms to it yet and an optional avoids forcing a placeholder DI
  registration for a capability nobody can exercise yet.
- CoreDataHandlerProtocol.clear(instanceKey:) / DatabaseManager's
  implementation are kept as built, but are no longer called by
  logout -- left in place as general per-instance infra (e.g. a future
  explicit "remove this instance's data" action), not dead-ended.
- Wired InstanceSessionManagerProtocol through AppAssembly.
- InstanceSessionManagerTests covers: switch does no teardown, logout tears
  down session state but not cached content, and logout still completes
  when no push conformance is wired.
- CoreDataHandlerProtocol gains clear(instanceKey:), implemented in
  DatabaseManager via one NSBatchDeleteRequest per instanceKey-scoped entity
  (CDDownloadData, CDOfflineProgress, CDCourseItem, CDDownloadCoursePreview)
  against the shared merged store.
…-lifecycle

# Conflicts:
#	Core/Core.xcodeproj/project.pbxproj
@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Sep 21, 2026
@openedx-webhooks

openedx-webhooks commented Sep 21, 2026

Copy link
Copy Markdown

Thanks for the pull request, @RawanMatar89!

This repository is currently maintained by @openedx/openedx-mobile-maintainers.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Sep 21, 2026
@RawanMatar89
RawanMatar89 marked this pull request as ready for review September 21, 2026 18:04
@RawanMatar89
RawanMatar89 merged commit a96a874 into openedx:develop Sep 22, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in Contributions Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants