mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
fix: Persist every previous team subdomain (#14022)
The savePreviousSubdomain hook mutated the existing array in place, so Sequelize did not detect the change and only the first previous subdomain was ever written to the database.
This commit is contained in:
1 parent
bc24a28182
commit
deb7d92367
2 files changed
+23
-8
No files matched your search
@@ -118,6 +118,21 @@ describe("Team", () => {
|
||||
expect(team.previousSubdomains?.[0]).toEqual(originalSubdomain);
|
||||
expect(team.previousSubdomains?.[1]).toEqual(subdomain);
|
||||
});
|
||||
|
||||
it("should persist every previous subdomain", async () => {
|
||||
const id = randomUUID();
|
||||
const subdomains = [1, 2, 3, 4, 5].map((n) => `sub${n}-${id}`);
|
||||
const team = await buildTeam({ subdomain: subdomains[0] });
|
||||
|
||||
for (const subdomain of subdomains.slice(1)) {
|
||||
await team.update({ subdomain });
|
||||
}
|
||||
|
||||
await team.reload();
|
||||
expect(team.previousSubdomains).toEqual(subdomains.slice(1, 4));
|
||||
expect((await Team.findBySubdomain(subdomains[3]))?.id).toEqual(team.id);
|
||||
expect(await Team.findBySubdomain(subdomains[0])).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("publicAvatarUrl", () => {
|
||||
|
||||
@@ -536,15 +536,15 @@ class Team extends ParanoidModel<
|
||||
static async savePreviousSubdomain(model: Team) {
|
||||
const previousSubdomain = model.previous("subdomain");
|
||||
if (previousSubdomain && previousSubdomain !== model.subdomain) {
|
||||
model.previousSubdomains = model.previousSubdomains || [];
|
||||
const previousSubdomains = model.previousSubdomains || [];
|
||||
|
||||
if (!model.previousSubdomains.includes(previousSubdomain)) {
|
||||
// Add the previous subdomain to the list of previous subdomains
|
||||
// upto a maximum of 3 previous subdomains
|
||||
model.previousSubdomains.push(previousSubdomain);
|
||||
if (model.previousSubdomains.length > 3) {
|
||||
model.previousSubdomains.shift();
|
||||
}
|
||||
if (!previousSubdomains.includes(previousSubdomain)) {
|
||||
// Assign a new array, Sequelize does not detect in-place mutation.
|
||||
// Keep up to a maximum of 3 previous subdomains.
|
||||
model.previousSubdomains = [
|
||||
...previousSubdomains,
|
||||
previousSubdomain,
|
||||
].slice(-3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user