Skip to content

Commit

Permalink
Fix outdated customer customizations
Browse files Browse the repository at this point in the history
Reload Customer and on full login to always have up-to-date
customizations

Close #8029
  • Loading branch information
charlag committed Nov 26, 2024
1 parent 9043a51 commit c019694
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
17 changes: 7 additions & 10 deletions src/common/api/main/LoginController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { DeferredObject, lazy, lazyAsync } from "@tutao/tutanota-utils"
import { assertNotNull, defer } from "@tutao/tutanota-utils"
import { assertMainOrNodeBoot } from "../common/Env"
import type { UserController, UserControllerInitData } from "./UserController"
import { getWhitelabelCustomizations } from "../../../common/misc/WhitelabelCustomizations"
import { getWhitelabelCustomizations } from "../../misc/WhitelabelCustomizations.js"
import { NotFoundError } from "../common/error/RestError"
import { client } from "../../misc/ClientDetector"
import type { LoginFacade, NewSessionData } from "../worker/facades/LoginFacade"
Expand All @@ -13,6 +13,7 @@ import { SessionType } from "../common/SessionType"
import { ExternalUserKeyDeriver } from "../../misc/LoginUtils.js"
import { UnencryptedCredentials } from "../../native/common/generatedipc/UnencryptedCredentials.js"
import { PageContextLoginListener } from "./PageContextLoginListener.js"
import { CacheMode } from "../worker/rest/EntityRestClient.js"

assertMainOrNodeBoot()

Expand All @@ -33,6 +34,7 @@ export type ResumeSessionResult = { type: "success" } | { type: "error"; reason:

export class LoginController {
private userController: UserController | null = null
// they are FeatureType but we might not be aware of newer values for it, so it is not just FeatureType
private customizations: NumberString[] | null = null
private partialLogin: DeferredObject<void> = defer()
private _isWhitelabel: boolean = !!getWhitelabelCustomizations(window)
Expand Down Expand Up @@ -211,15 +213,10 @@ export class LoginController {
return this.customizations != null ? this.customizations.indexOf(feature) !== -1 : false
}

loadCustomizations(): Promise<void> {
if (this.isInternalUserLoggedIn()) {
return this.getUserController()
.loadCustomer()
.then((customer) => {
this.customizations = customer.customizations.map((f) => f.feature)
})
} else {
return Promise.resolve()
async loadCustomizations(cacheMode: CacheMode = CacheMode.Cache): Promise<void> {
if (this.getUserController().isInternalUser()) {
const customer = await this.getUserController().loadCustomer(cacheMode)
this.customizations = customer.customizations.map((f) => f.feature)
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/common/api/main/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { IServiceExecutor } from "../common/ServiceRequest.js"
import { isCustomizationEnabledForCustomer } from "../common/utils/CustomerUtils.js"
import { EntityUpdateData, isUpdateForTypeRef } from "../common/utils/EntityUpdateUtils.js"
import { isGlobalAdmin, isInternalUser } from "../common/utils/UserUtils.js"
import { CacheMode } from "../worker/rest/EntityRestClient.js"

assertMainOrNode()

Expand Down Expand Up @@ -110,8 +111,8 @@ export class UserController {
return isInternalUser(this.user)
}

loadCustomer(): Promise<Customer> {
return this.entityClient.load(CustomerTypeRef, neverNull(this.user.customer))
loadCustomer(cacheMode: CacheMode = CacheMode.Cache): Promise<Customer> {
return this.entityClient.load(CustomerTypeRef, assertNotNull(this.user.customer), { cacheMode })
}

async loadCustomerInfo(): Promise<CustomerInfo> {
Expand Down
7 changes: 7 additions & 0 deletions src/mail-app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { SettingsViewAttrs } from "../common/settings/Interfaces.js"
import { disableErrorHandlingDuringLogout, handleUncaughtError } from "../common/misc/ErrorHandler.js"
import { AppType } from "../common/misc/ClientConstants.js"
import { ContactModel } from "../common/contactsFunctionality/ContactModel.js"
import { CacheMode } from "../common/api/worker/rest/EntityRestClient.js"

assertMainOrNodeBoot()
bootFinished()
Expand Down Expand Up @@ -139,6 +140,12 @@ import("./translations/en.js")
async onFullLoginSuccess() {
await mailLocator.groupManagementFacade.migrateLocalAdminsToGlobalAdmins()

// We might have outdated Customer features, force reload the customer to make sure the customizations are up-to-date
if (isOfflineStorageAvailable()) {
await mailLocator.logins.loadCustomizations(CacheMode.Bypass)
m.redraw()
}

if (mailLocator.mailModel.canManageLabels() && !mailLocator.logins.getUserController().props.defaultLabelCreated) {
const mailboxDetail = await mailLocator.mailboxModel.getMailboxDetails()

Expand Down

0 comments on commit c019694

Please sign in to comment.