From 7811d57bb4bf695ef6c9120e57ca35bcba1258ea Mon Sep 17 00:00:00 2001 From: Christian Hueller Date: Fri, 22 Nov 2024 21:45:01 +0100 Subject: [PATCH] Add handling of Personal Access Token in Confluence data connector --- .../utils/extensions/Confluence/index.js | 20 ++++++--- .../Connectors/Confluence/index.jsx | 45 +++++++++++++++++-- frontend/src/models/dataConnector.js | 2 + 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/collector/utils/extensions/Confluence/index.js b/collector/utils/extensions/Confluence/index.js index c8ab9b03c3..686f789613 100644 --- a/collector/utils/extensions/Confluence/index.js +++ b/collector/utils/extensions/Confluence/index.js @@ -18,15 +18,16 @@ async function loadConfluence( spaceKey = null, username = null, accessToken = null, + personalAccessToken = null, cloud = true, }, response ) { - if (!baseUrl || !spaceKey || !username || !accessToken) { + if (!accessToken && !personalAccessToken || accessToken && !username || personalAccessToken && username) { return { success: false, reason: - "You need either a username and access token, or a personal access token (PAT), to use the Confluence connector.", + "You need either a username and access token, or only a personal access token (PAT), to use the Confluence connector.", }; } @@ -51,6 +52,7 @@ async function loadConfluence( spaceKey, username, accessToken, + personalAccessToken, cloud, }); @@ -98,7 +100,7 @@ async function loadConfluence( description: doc.metadata.title, docSource: `${origin} Confluence`, chunkSource: generateChunkSource( - { doc, baseUrl: origin, spaceKey, accessToken, username, cloud }, + { doc, baseUrl: origin, spaceKey, accessToken, personalAccessToken, username, cloud }, response.locals.encryptionWorker ), published: new Date().toLocaleString(), @@ -137,14 +139,14 @@ async function fetchConfluencePage({ spaceKey, username, accessToken, + personalAccessToken, cloud = true, }) { - if (!pageUrl || !baseUrl || !spaceKey || !username || !accessToken) { + if (!accessToken && !personalAccessToken || accessToken && !username || personalAccessToken && username) { return { success: false, - content: null, reason: - "You need either a username and access token, or a personal access token (PAT), to use the Confluence connector.", + "You need either a username and access token, or only a personal access token (PAT), to use the Confluence connector.", }; } @@ -170,6 +172,7 @@ async function fetchConfluencePage({ spaceKey, username, accessToken, + personalAccessToken, cloud, }); @@ -234,9 +237,12 @@ function validBaseUrl(baseUrl) { * @returns {string} */ function generateChunkSource( - { doc, baseUrl, spaceKey, accessToken, username, cloud }, + { doc, baseUrl, spaceKey, accessToken, personalAccessToken, username, cloud }, encryptionWorker ) { + if (personalAccessToken) { + accessToken = personalAccessToken; + } const payload = { baseUrl, spaceKey, diff --git a/frontend/src/components/Modals/ManageWorkspace/DataConnectors/Connectors/Confluence/index.jsx b/frontend/src/components/Modals/ManageWorkspace/DataConnectors/Connectors/Confluence/index.jsx index 77158dc9be..6e37b02489 100644 --- a/frontend/src/components/Modals/ManageWorkspace/DataConnectors/Connectors/Confluence/index.jsx +++ b/frontend/src/components/Modals/ManageWorkspace/DataConnectors/Connectors/Confluence/index.jsx @@ -26,6 +26,7 @@ export default function ConfluenceOptions() { spaceKey: form.get("spaceKey"), username: form.get("username"), accessToken: form.get("accessToken"), + personalAccessToken: form.get("personalAccessToken"), cloud: form.get("isCloud") === "true", }); @@ -133,7 +134,7 @@ export default function ConfluenceOptions() { name="username" className="bg-theme-settings-input-bg text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5" placeholder="jdoe@example.com" - required={true} + required={false} autoComplete="off" spellCheck={false} /> @@ -157,7 +158,7 @@ export default function ConfluenceOptions() { clickable={true} >

- You need to provide an access token for authentication. + You need to provide a username and access token or a personal access token for authentication. You can generate an access token{" "} + +

+
+ +

+ Personal access token for authentication. +

+
+ diff --git a/frontend/src/models/dataConnector.js b/frontend/src/models/dataConnector.js index 30c17fb12c..cbdc086eb2 100644 --- a/frontend/src/models/dataConnector.js +++ b/frontend/src/models/dataConnector.js @@ -136,6 +136,7 @@ const DataConnector = { spaceKey, username, accessToken, + personalAccessToken, cloud, }) { return await fetch(`${API_BASE}/ext/confluence`, { @@ -146,6 +147,7 @@ const DataConnector = { spaceKey, username, accessToken, + personalAccessToken, cloud, }), })