Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ed6b16217 | ||
|
|
c6d22b3939 |
No files matched your search
@@ -4,14 +4,14 @@
|
|||||||
<h3>Homarr</h3>
|
<h3>Homarr</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
**Thank you for your contribution. Please ensure that your pull request meets the following requirements:**
|
**Thank you for your contribution. Please ensure that your pull request meets the following pull request:**
|
||||||
|
|
||||||
- [ ] Relevant checks pass without warnings or errors
|
- [ ] Builds without warnings or errors (`pnpm build`, autofix with `pnpm format:fix`)
|
||||||
- [ ] Pull request targets the intended base branch (`dev` by default; `release/v2` for v2 release work)
|
- [ ] Pull request targets `dev` branch
|
||||||
- [ ] Commits follow the [conventional commits guideline](https://www.conventionalcommits.org/en/v1.0.0/)
|
- [ ] Commits follow the [conventional commits guideline](https://www.conventionalcommits.org/en/v1.0.0/)
|
||||||
- [ ] No shorthand variable names are used (for example, `x`, `y`, `i`, or abbreviations)
|
- [ ] No shorthand variable names are used (eg. `x`, `y`, `i` or any abbrevation)
|
||||||
- [ ] User-facing changes include matching documentation updates under `apps/docs`
|
- [ ] Documentation is up to date. Create a pull request [here](https://github.com/homarr-labs/documentation/).
|
||||||
- [ ] When using AI, no temporary files are checked in and the code style follows the rest of the project
|
- [ ] When using AI; No temp files are checked in, the code style follows the rest of the project
|
||||||
|
|
||||||
**When contributing a new integration or widget:**
|
**When contributing a new integration or widget:**
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
export const createNextcloudCalendarServerUrl = (integrationUrl: string) => {
|
||||||
|
const calendarServerUrl = new URL(integrationUrl);
|
||||||
|
const integrationPath = calendarServerUrl.pathname.replace(/\/+$/, "");
|
||||||
|
const davPath = "/remote.php/dav";
|
||||||
|
|
||||||
|
calendarServerUrl.pathname = integrationPath.endsWith(davPath)
|
||||||
|
? `${integrationPath}/`
|
||||||
|
: `${integrationPath}${davPath}/`;
|
||||||
|
calendarServerUrl.search = "";
|
||||||
|
calendarServerUrl.hash = "";
|
||||||
|
|
||||||
|
return calendarServerUrl.toString();
|
||||||
|
};
|
||||||
@@ -21,6 +21,7 @@ import type { ICalendarIntegration } from "../interfaces/calendar/calendar-integ
|
|||||||
import type { CalendarEvent } from "../interfaces/calendar/calendar-types";
|
import type { CalendarEvent } from "../interfaces/calendar/calendar-types";
|
||||||
import type { Notification } from "../interfaces/notifications/notification-types";
|
import type { Notification } from "../interfaces/notifications/notification-types";
|
||||||
import type { INotificationsIntegration } from "../interfaces/notifications/notifications-integration";
|
import type { INotificationsIntegration } from "../interfaces/notifications/notifications-integration";
|
||||||
|
import { createNextcloudCalendarServerUrl } from "./nextcloud-url";
|
||||||
|
|
||||||
// Register all existing timezones
|
// Register all existing timezones
|
||||||
if (ICAL.TimezoneService.count === 0) {
|
if (ICAL.TimezoneService.count === 0) {
|
||||||
@@ -189,7 +190,7 @@ export class NextcloudIntegration extends Integration implements ICalendarIntegr
|
|||||||
|
|
||||||
private async createCalendarClientAsync(agent?: Agent) {
|
private async createCalendarClientAsync(agent?: Agent) {
|
||||||
return new DAVClient({
|
return new DAVClient({
|
||||||
serverUrl: this.integration.url,
|
serverUrl: createNextcloudCalendarServerUrl(this.integration.url),
|
||||||
credentials: {
|
credentials: {
|
||||||
username: this.getSecretValue("username"),
|
username: this.getSecretValue("username"),
|
||||||
password: this.getSecretValue("password"),
|
password: this.getSecretValue("password"),
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import type { Agent } from "node:https";
|
||||||
|
import { DAVClient } from "tsdav";
|
||||||
|
import { beforeEach, describe, expect, test, vi } from "vitest";
|
||||||
|
|
||||||
|
import { NextcloudIntegration } from "../nextcloud.integration";
|
||||||
|
|
||||||
|
vi.mock("tsdav", () => ({ DAVClient: vi.fn() }));
|
||||||
|
|
||||||
|
interface NextcloudCalendarClientFactory {
|
||||||
|
createCalendarClientAsync(agent: Agent): Promise<unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("NextcloudIntegration", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.mocked(DAVClient).mockClear();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uses a calendar server URL that preserves the integration subpath", async () => {
|
||||||
|
const integration = new NextcloudIntegration({
|
||||||
|
id: "integration-id",
|
||||||
|
name: "Nextcloud",
|
||||||
|
url: "https://example.com/nextcloud",
|
||||||
|
externalUrl: null,
|
||||||
|
decryptedSecrets: [
|
||||||
|
{ kind: "username", value: "admin" },
|
||||||
|
{ kind: "password", value: "password" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await (integration as unknown as NextcloudCalendarClientFactory).createCalendarClientAsync({} as Agent);
|
||||||
|
|
||||||
|
expect(DAVClient).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
serverUrl: "https://example.com/nextcloud/remote.php/dav/",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
|
import { createNextcloudCalendarServerUrl } from "../nextcloud-url";
|
||||||
|
|
||||||
|
describe("createNextcloudCalendarServerUrl", () => {
|
||||||
|
test("uses the DAV endpoint for a root installation", () => {
|
||||||
|
expect(createNextcloudCalendarServerUrl("https://cloud.example.com")).toBe(
|
||||||
|
"https://cloud.example.com/remote.php/dav/",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("preserves the base path for a subpath installation", () => {
|
||||||
|
expect(createNextcloudCalendarServerUrl("https://example.com/nextcloud")).toBe(
|
||||||
|
"https://example.com/nextcloud/remote.php/dav/",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("does not duplicate a trailing slash", () => {
|
||||||
|
expect(createNextcloudCalendarServerUrl("https://example.com/nextcloud/")).toBe(
|
||||||
|
"https://example.com/nextcloud/remote.php/dav/",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("does not duplicate an existing DAV endpoint", () => {
|
||||||
|
expect(createNextcloudCalendarServerUrl("https://example.com/nextcloud/remote.php/dav")).toBe(
|
||||||
|
"https://example.com/nextcloud/remote.php/dav/",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user