Skip to content

237 task remove functionality that does the job of the identity provider idp#238

Merged
maneeshaxyz merged 22 commits intomainfrom
237-task-remove-functionality-that-does-the-job-of-the-identity-provider-idp
Mar 17, 2026
Merged

237 task remove functionality that does the job of the identity provider idp#238
maneeshaxyz merged 22 commits intomainfrom
237-task-remove-functionality-that-does-the-job-of-the-identity-provider-idp

Conversation

@Aravinda-HWK
Copy link
Copy Markdown
Collaborator

📌 Description

This PR is to remove the user and domain tables and remove the user_id fields from the other tables from user databases.


🔍 Changes Made

  • Remove users table from the shared.db
  • Remove domains table from the shared.db
  • Remove user_id from the user database tables.

✅ Checklist (Email System)

  • Core IMAP commands tested (LOGIN, CAPABILITY, LIST, SELECT, FETCH, LOGOUT).
  • Authentication is tested.
  • Docker build & run validated.
  • Configuration loading verified for default and custom paths.
  • Persistent storage with Docker volume verified.
  • Error handling and logging verified
  • Documentation updated (README, config samples).

🧪 Testing Instructions

To test the server, use the instructions in the README in the test directory.


📷 Screenshots / Logs (if applicable)


⚠️ Notes for Reviewers

- Updated the ServerInterface and related implementations to retrieve user databases using email addresses instead of user IDs.
- Modified middleware, selection handlers, and server methods to accommodate the new email-based user identification.
- Adjusted test helpers and integration tests to reflect changes in user identification, ensuring compatibility with the new schema.
…abase functions

- Updated functions to eliminate the user_id parameter for mailbox operations in per-user databases.
- Adjusted related database queries and function signatures across the codebase.
- Modified tests to reflect changes in mailbox retrieval and creation logic.
- Ensured consistency in handling mailbox operations without relying on user_id, simplifying the code and improving readability.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the user management and database interaction logic by externalizing user identity. Instead of maintaining internal users and domains tables, the system now relies on an external Identity Provider (IDP) for user authentication and identification, using the full email address as the primary identifier. This change simplifies the database schema, reduces internal data redundancy, and aligns the system with modern identity management practices, making it more scalable and easier to integrate with external authentication services.

Highlights

  • Database Schema Simplification: Removed the users and domains tables from the shared database, as user identity is now managed externally by an Identity Provider (IDP). This streamlines the core database schema.
  • User Identification Shift: Transitioned user identification from internal integer user_id and domain_id to the full email address (string) across the application. This impacts how user-specific databases are accessed and managed.
  • Per-User Database Updates: Modified per-user database schemas (mailboxes, aliases, subscriptions, deliveries) to remove user_id and domain_id columns, relying solely on the email-scoped nature of these databases. Unique constraints were updated accordingly.
  • API and Logic Refactoring: Updated DBManager and various server-side functions (authentication, mailbox management, message handling, UID commands) to accept and utilize the email string for user identification instead of user_id. This includes changes to function signatures and internal data structures like userDBCache.
  • Legacy Compatibility: Introduced ensureLegacyIdentityTables and normalizeUserIdentity helpers in sqlite.go and testing_support.go to maintain compatibility with older tests or components that might still expect user_id or domain_id based operations, ensuring a smoother transition.
Changelog
  • docs/README.md
    • Updated the description of the data volume path to reflect the new user database naming convention.
  • internal/db/db_manager.go
    • Changed the key type of userDBCache from int64 (userID) to string (email).
    • Updated GetUserDB method to accept an email string instead of userID.
    • Removed the userID parameter from initUserDB and related calls.
    • Removed calls to createDomainsTable and createUsersTable during shared database initialization.
  • internal/db/db_manager_test.go
    • Added a helper function testEmailFromID to generate email strings from integer IDs for testing.
    • Updated all calls to GetUserDB to use email strings instead of integer user IDs.
    • Removed checks for idx_mailboxes_user and idx_subscriptions_user indexes which are no longer relevant.
  • internal/db/sqlite.go
    • Removed createDomainsTable and createUsersTable functions.
    • Modified createRoleMailboxesTable to remove domain_id column and its foreign key constraint.
    • Modified createUserRoleAssignmentsTable to use user_email (TEXT) instead of user_id (INTEGER) and removed assigned_by column and its foreign key.
    • Added ensureLegacyIdentityTables to lazily create domains and users tables for backward compatibility in tests.
    • Updated CreateDomain, GetDomainByName, CreateUser, GetUserByUsername, UserExists to call ensureLegacyIdentityTables.
    • Changed AssignUserToRoleMailbox, UnassignUserFromRoleMailbox, GetUserRoleAssignments, IsUserAssignedToRoleMailbox to accept user interface{} and use normalizeUserIdentity.
    • Added GetRoleMailboxAssignedEmail and a legacy GetRoleMailboxAssignedUser for compatibility.
    • Removed the userID parameter from createDefaultMailboxes.
    • Updated createSharedIndexes and createUserIndexes to remove deprecated user and domain specific indexes.
  • internal/db/user_schema.go
    • Updated comments to clarify that per-user databases are scoped by email and do not store user IDs.
    • Removed user_id column and UNIQUE(user_id, name) constraint from mailboxes table, replacing with UNIQUE(name).
    • Removed domain_id and destination_user_id from aliases table, replacing with destination_email and UNIQUE(alias).
    • Removed user_id column and UNIQUE(user_id, mailbox_name) constraint from subscriptions table, replacing with UNIQUE(mailbox_name).
    • Removed user_id column from deliveries table.
    • Updated all per-user mailbox management functions (e.g., CreateMailboxPerUser, GetMailboxByNamePerUser, DeleteMailboxPerUser) to remove userID parameters and adapt to the new schema.
  • internal/db/user_schema_test.go
    • Updated test calls to per-user mailbox management functions to remove userID parameters, aligning with the new schema.
  • internal/delivery/lmtp/session_test.go
    • Removed explicit domain and user creation, now directly initializes the user database using the email address.
  • internal/delivery/storage/storage.go
    • Removed logic for extracting username and domain from recipient email.
    • Removed calls to db.GetOrCreateDomain and db.GetOrCreateUser.
    • Updated DeliverMessage to use the full recipient email directly for dbManager.GetUserDB.
    • Removed targetUserID variable and its usage.
    • Updated db.RecordDeliveryPerUser call to remove the userIDNull parameter.
    • Simplified CheckUserExists and CheckRecipientExists to always return true, indicating identity is handled by the IDP.
    • Updated GetUserQuota, GetMessageCount, GetMessageCountInFolder to use email instead of username and removed userID from database queries.
    • Simplified CreateUserIfNotExists to directly call dbManager.GetUserDB with the email address.
  • internal/models/state.go
    • Added a new Email field to ClientState to store the full email address from the IDP.
    • Marked UserID and DomainID fields as deprecated.
  • internal/server/auth/auth.go
    • Updated ServerDeps interface for EnsureUserAndMailboxes to accept an email string.
    • Modified authenticateUser to use the full email for EnsureUserAndMailboxes and db.GetUserRoleAssignments.
    • Updated ClientState to set the new Email field and removed setting of UserID and DomainID.
  • internal/server/extension/extension.go
    • Updated ServerDeps interface for GetUserDB to accept an email string.
    • Modified HandleNoop and HandleIdle to use state.Email when calling deps.GetUserDB.
  • internal/server/mailbox/mailbox.go
    • Updated ServerDeps interface for GetUserDB to accept an email string.
    • Modified HandleList, HandleCreate, HandleDelete, HandleRename, HandleSubscribe, HandleUnsubscribe, HandleStatus to use state.Email for deps.GetUserDB and removed userID parameters from calls to db functions.
  • internal/server/message/fetch.go
    • Updated calls to deps.GetSelectedDB to no longer expect a targetUserID return value.
  • internal/server/message/message.go
    • Updated ServerDeps interface for GetUserDB to accept an email string and GetSelectedDB to no longer return targetUserID.
    • Modified HandleSearch and its helper functions (evaluateSearchCriteria, matchesSearchCriteria, evaluateTokens, matchesHeaderOrBody, matchesHeader, matchesSize, matchesSentDate) to use email instead of userID.
    • Updated HandleStore, HandleCopy, MoveMessageToMailbox, HandleAppendWithReader, HandleAppend, HandleExpunge, HandleCheck to use state.Email for deps.GetUserDB and removed userID parameters from db function calls.
  • internal/server/middleware/checks.go
    • Updated ServerInterface for GetUserDB to accept an email string and GetSelectedDB to no longer return targetUserID.
    • Modified WithUserDB to use state.Email when calling server.GetUserDB.
  • internal/server/middleware/checks_test.go
    • Updated MockServer methods GetUserDB and GetSelectedDB to reflect the new email parameter and removed targetUserID return value.
  • internal/server/selection/selection.go
    • Updated ServerDeps interface for GetUserDB to accept an email string.
    • Modified HandleSelect to use state.Email for deps.GetUserDB and db.IsUserAssignedToRoleMailbox, and removed the targetUserID variable.
    • Modified HandleClose to use state.Email for deps.GetUserDB.
  • internal/server/server.go
    • Updated EnsureUserAndMailboxes to accept an email string and return error (no userID, domainID).
    • Updated GetUserDB to accept an email string.
    • Updated GetSelectedDB to no longer return userID and to use state.Email for s.dbManager.GetUserDB.
  • internal/server/testing_support.go
    • Updated CreateTestUser to directly use the email for user creation and database initialization.
    • Updated InsertTestMail and CreateMailbox to use the email for user identification.
    • Updated SubscribeToMailbox to use the email for user identification.
    • Deprecated GetUserID as numeric user IDs are no longer central.
    • Updated SetupAuthenticatedState to use email and set state.Email.
    • Updated GetUserDB to accept an email string.
    • Updated GetMailboxID to construct an email from userID for legacy compatibility.
    • Updated UpdateMessageFlags and GetUserDBFromManager to use email.
    • Updated GetUserDBByID to construct an email from userID for legacy compatibility.
  • internal/server/uid/uid.go
    • Updated ServerDeps interface for GetUserDB to accept an email string and GetSelectedDB to no longer return targetUserID.
    • Modified handleUIDFetch, handleUIDSearch, handleUIDStore, handleUIDCopy, handleUIDExpunge to use GetSelectedDB without targetUserID and message.MoveMessageToMailbox without userID.
  • test/helpers/database.go
    • Updated TestData struct to include Email and set UserID and DomainID to 0.
    • Modified SeedTestData and CreateTestUser to use email directly for user creation and database initialization, removing userID/domainID logic.
    • Modified CreateTestMailbox to accept email instead of userID.
    • Updated AssertDatabaseExists to accept a string identifier instead of an int64 id for database path verification.
  • test/integration/db/database_integration_test.go
    • Updated helpers.AssertDatabaseExists calls to use the new string identifier.
    • Modified helpers.SeedTestData and helpers.CreateTestUser calls to align with the email-based user identification.
    • Removed test assertions related to UserID and DomainID in CreateTestUser test.
    • Updated dbManager.GetUserDB and db.GetUserMailboxesPerUser calls to use email.
    • Updated helpers.CreateTestMailbox calls to use email.
  • test/integration/delivery/lmtp_integration_test.go
    • Updated dbm.GetUserDB and db.GetMailboxByNamePerUser calls to use email.
    • Updated helpers.CreateTestUser calls to align with the email-based user identification.
  • test/integration/server/imap_integration_test.go
    • Updated helpers.CreateTestMailbox calls to use email.
    • Updated dbManager.GetUserDB and db.GetMailboxByNamePerUser calls to use email.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 13, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively removes local user and domain management, shifting to an identity provider-based approach. The changes are comprehensive, replacing user_id with email-based identification throughout the database, server logic, and tests. The use of compatibility shims for legacy test support is well-executed. My review includes two main points: one regarding an unused function parameter that should be removed for code clarity, and a more significant concern about a change that could lead to creating storage for non-existent users, which poses a potential operational risk.

Comment thread internal/delivery/storage/storage.go Outdated
Comment thread internal/db/sqlite.go Outdated
Aravinda-HWK and others added 14 commits March 14, 2026 09:56
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
… and enhance resolveStateEmail for test user handling
Copy link
Copy Markdown
Member

@maneeshaxyz maneeshaxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@maneeshaxyz maneeshaxyz merged commit 44fd04f into main Mar 17, 2026
6 checks passed
@Aravinda-HWK Aravinda-HWK deleted the 237-task-remove-functionality-that-does-the-job-of-the-identity-provider-idp branch March 20, 2026 05:58
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.

[TASK] Remove functionality that does the job of the Identity Provider (IDP).

3 participants