mirror of
https://github.com/outline/outline.git
synced 2026-11-23 06:11:04 +03:00
Remove settings from integration presenter (#12770)
* Remove settings from integration presenter * refactor
This commit is contained in:
1 parent
3d9789e8cf
commit
e1a6c986b7
3 files changed
+93
-1
No files matched your search
@@ -84,6 +84,52 @@ class Integration<T = unknown> extends ParanoidModel<
|
||||
@Column(DataType.UUID)
|
||||
authenticationId: string;
|
||||
|
||||
// methods
|
||||
|
||||
/**
|
||||
* The subset of settings that are safe to expose to clients. Each integration
|
||||
* type opts-in to the specific fields its client consumes, so sensitive values
|
||||
* such as webhook URLs are never serialized by default.
|
||||
*
|
||||
* @returns the client-safe settings, or undefined when none are exposed.
|
||||
*/
|
||||
public presentSettings() {
|
||||
switch (this.type) {
|
||||
case IntegrationType.Embed: {
|
||||
const settings = this
|
||||
.settings as IntegrationSettings<IntegrationType.Embed>;
|
||||
return {
|
||||
url: settings?.url,
|
||||
github: settings?.github,
|
||||
gitlab: settings?.gitlab,
|
||||
linear: settings?.linear,
|
||||
diagrams: settings?.diagrams,
|
||||
};
|
||||
}
|
||||
case IntegrationType.Analytics: {
|
||||
const settings = this
|
||||
.settings as IntegrationSettings<IntegrationType.Analytics>;
|
||||
return {
|
||||
measurementId: settings?.measurementId,
|
||||
instanceUrl: settings?.instanceUrl,
|
||||
scriptName: settings?.scriptName,
|
||||
};
|
||||
}
|
||||
case IntegrationType.Post: {
|
||||
const settings = this
|
||||
.settings as IntegrationSettings<IntegrationType.Post>;
|
||||
return { channel: settings?.channel };
|
||||
}
|
||||
case IntegrationType.LinkedAccount: {
|
||||
const settings = this
|
||||
.settings as IntegrationSettings<IntegrationType.LinkedAccount>;
|
||||
return { figma: settings?.figma };
|
||||
}
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// hooks
|
||||
|
||||
@AfterDestroy
|
||||
|
||||
@@ -9,7 +9,7 @@ export default function presentIntegration(integration: Integration) {
|
||||
authenticationId: integration.authenticationId,
|
||||
service: integration.service,
|
||||
events: integration.events,
|
||||
settings: integration.settings,
|
||||
settings: integration.presentSettings(),
|
||||
createdAt: integration.createdAt,
|
||||
updatedAt: integration.updatedAt,
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { IntegrationSettings } from "@shared/types";
|
||||
import { IntegrationService, IntegrationType } from "@shared/types";
|
||||
import type { User } from "@server/models";
|
||||
import Integration from "@server/models/Integration";
|
||||
@@ -211,3 +212,48 @@ describe("#integrations.delete", () => {
|
||||
expect(intg?.deletedAt).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#integrations.list", () => {
|
||||
it("should not expose the webhook url of post integrations", async () => {
|
||||
const admin = await buildAdmin();
|
||||
await buildIntegration({
|
||||
userId: admin.id,
|
||||
teamId: admin.teamId,
|
||||
service: IntegrationService.Slack,
|
||||
type: IntegrationType.Post,
|
||||
settings: {
|
||||
url: "https://hooks.slack.com/services/secret",
|
||||
channel: "#general",
|
||||
channelId: "C123",
|
||||
} as IntegrationSettings<IntegrationType.Post>,
|
||||
});
|
||||
|
||||
const res = await server.post("/api/integrations.list", admin);
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.length).toEqual(1);
|
||||
// Only the opted-in channel field is exposed, never the webhook url.
|
||||
expect(body.data[0].settings.url).toBeUndefined();
|
||||
expect(body.data[0].settings.channel).toEqual("#general");
|
||||
});
|
||||
|
||||
it("should expose the public settings of embed integrations", async () => {
|
||||
const team = await buildTeam();
|
||||
const member = await buildUser({ teamId: team.id });
|
||||
await buildIntegration({
|
||||
userId: member.id,
|
||||
teamId: team.id,
|
||||
service: IntegrationService.Diagrams,
|
||||
type: IntegrationType.Embed,
|
||||
settings: { url: "https://example.com" },
|
||||
});
|
||||
|
||||
const res = await server.post("/api/integrations.list", member);
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.length).toEqual(1);
|
||||
expect(body.data[0].settings.url).toEqual("https://example.com");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user