[PB-6134]: feat/stalwart admin api principals#7
Conversation
e31054d to
1a01822
Compare
| const principalName = this.requirePrincipalName(account); | ||
|
|
||
| await this.provider.removeAddress(principalName, address); | ||
| await Promise.all([ | ||
| this.addresses.deleteProviderLink(addressRecord.id), | ||
| this.addresses.delete(addressRecord.id), | ||
| ]); | ||
|
|
||
| this.logger.log( | ||
| `Removed address '${address}' from account '${driveUserUuid}'`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
It is somehow hard to wrap my head around this concept as you're using stalwart's implementation names (principal name) in the bussiness layer instead of our domain names such as mainAddress/primaryAddress, I may be wrong tho.
There was a problem hiding this comment.
you are right, my bad. some methods existed before creating our domain names and missed renaming variables creating this odd mix of domain names and stalwart names. addressed
| @@ -0,0 +1,91 @@ | |||
| import { Injectable, Logger } from '@nestjs/common'; | |||
There was a problem hiding this comment.
A quick tip if you feel this module gets too big: instead of /modules/infrastructure, you can create a infrastructure folder in the module that requires this service.
Each module can have its own bussiness (usecases), infrastructure (external services, controllers), domain layers it you think things get too crazy. We do not follow a hardcore ports/adapters structure as we tend to be more pragmatic, so it is always up to you @jzunigax2
There was a problem hiding this comment.
hmm lets wait and see how it evolves, I would think we wont need to add much to /infrastructure
| async delete(id: string): Promise<void> { | ||
| await this.addressModel.destroy({ where: { id } }); | ||
| } |
There was a problem hiding this comment.
Beware of hard deletes here. We're handling emails so we might want to use soft deletes just in case. You can enable the paranoid option so sequelize handles automatically this for you (by setting a deleted_at), you'll probably need to modify your existent migrations tho
There was a problem hiding this comment.
I suggested the paranoid option but let's see what @sg-gs thinks
There was a problem hiding this comment.
paranoid sounds good, I added it to mail-addresses and mail-accounts. let me know if that sounds good to you
sg-gs
left a comment
There was a problem hiding this comment.
There are js imports across multiple files @jzunigax2.
Btw, there is a ton heck of code here, let's avoid this gigantic PRs
|
|
||
| export interface MailAccountAttributes { | ||
| id: string; | ||
| driveUserUuid: string; |
There was a problem hiding this comment.
The user's uuid is common over all the services (drive, network, payments, meet...), therefore, this wording is not accurate. It's better to use userId, as also the format is something not relevant, as the type itself clarifies that is not the incremental id, that btw, we will eventually remove
There was a problem hiding this comment.
you are right, addressed
| address: string; | ||
| domainId: string; | ||
| isDefault: boolean; | ||
| providerExternalId: string | null; |
There was a problem hiding this comment.
right, it really should never be.. Made it non-nullable. Each address always has a provider link
| export interface MailDomainAttributes { | ||
| id: string; | ||
| domain: string; | ||
| status: string; |
There was a problem hiding this comment.
added MailDomainStatus enum with Active and Inactive values
| @@ -0,0 +1,43 @@ | |||
| import { Injectable } from '@nestjs/common'; | |||
| import { InjectModel } from '@nestjs/sequelize'; | |||
| import { MailAccount } from '../domain/mail-account.domain.js'; | |||
There was a problem hiding this comment.
Shouldn't this be typescript files?
| private readonly accountModel: typeof MailAccountModel, | ||
| ) {} | ||
|
|
||
| async findByDriveUserUuid(uuid: string): Promise<MailAccount | null> { |
| ): Promise<void> { | ||
| // Stalwart uses the principal name as the login. | ||
| // Changing the primary address means renaming the principal. | ||
| // Current REST API does not support rename — we must recreate. |
There was a problem hiding this comment.
Maybe we should use a principal handled by us consisting on the user uuid and the mail extension so we prevent these things. Also, which are the consequences of recreating? Would other addresses or the mailbox be deleted from Stalwart?
There was a problem hiding this comment.
recreating would lose all stored emails and mailbox data since the new principal gets a fresh internal id. however this isn't actually needed this was left over code from an earlier iteration, each address is its own principal, so there's no rename scneario now.
Removed setPrimaryAddress from the provider entirely, it's now a DB-only operation. Also removed addAddress/removeAddress from the port since adding/removing an address means creating/deleting a whole principal via createAccount/deleteAccount rather than adding them as aliasses.
There was a problem hiding this comment.
Yeah, it's better, if possible, to decouple a rename on our UI to a rename on the Mail tool itself, if possible
5046358 to
2919836
Compare
hey @sg-gs the project uses nodenext for compiler options as for the big PR you are right, my bad. initially this was supposed to only include the stalwart api abstraction and I made the mistake to keep building on top of this to see how it would shape out |
- Added AccountProvider interface for managing email accounts with methods for creating, deleting, and updating accounts and addresses. - Implemented StalwartAccountProvider class to interact with the Stalwart service for account management. - Introduced CreateAccountParams and AccountInfo types for structured account data handling. - Created StalwartService to manage API interactions with the Stalwart backend, including principal creation, retrieval, and updates. - Established StalwartModule to provide the StalwartAccountProvider as a dependency for other modules.
- Replaced adminToken with adminUser and adminSecret in the configuration. - Updated StalwartService to use basic authentication with adminUser and adminSecret instead of bearer token. - Adjusted headers method to include basic auth credentials for API requests.
- Introduced AccountProvider interface for managing email accounts, including methods for creating, deleting, and updating accounts and addresses. - Added AccountService to handle business logic for account operations, including address management and primary address setting. - Created repositories for account, address, and domain management, integrating with Sequelize for data persistence. - Defined domain models for MailAccount, MailAddress, and MailDomain to structure account-related data. - Updated .env.template to include new configuration parameters for Stalwart account management.
- Introduced comprehensive unit tests for AccountService, covering account retrieval, deletion, and address management functionalities. - Added unit tests for StalwartAccountProvider, validating account creation, deletion, and address manipulation methods. - Updated ESLint configuration to disable unbound-method rule for test files. - Enhanced test fixtures to support new account and address attributes for improved test coverage.
…ables - Introduced migrations to add a nullable deleted_at column to both mail_accounts and mail_addresses tables for soft deletion functionality. - Updated the MailAccount and MailAddress models to include the deletedAt field with paranoid option enabled for Sequelize. - Refactored AccountService to replace references from principalName to providerAccountId for consistency in account management.
- Created a migration to rename the column drive_user_uuid to user_id in the mail_accounts table for improved clarity and consistency. - Updated related code in seeders, services, and repositories to reflect the new user_id field. - Adjusted unit tests to ensure proper functionality with the updated user identification method.
…hods - Removed addAddress, removeAddress, and setPrimaryAddress methods from the AccountProvider interface and StalwartAccountProvider implementation to streamline account management. - Updated AccountService to handle address management directly, ensuring proper deletion and linking of addresses during account operations. - Adjusted related unit tests to reflect the changes in address handling and account deletion processes.
3efc3a3 to
ec2b9e9
Compare
|


Uh oh!
There was an error while loading. Please reload this page.