From 7a4f596fffdb4dd6eb820d650f034c3204a47116 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 18 Nov 2024 07:51:17 +0100 Subject: [PATCH 1/3] ui: If error as return as json, parse them --- ui/src/services/api.service.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/src/services/api.service.js b/ui/src/services/api.service.js index a8a07ef5..c28a7adf 100644 --- a/ui/src/services/api.service.js +++ b/ui/src/services/api.service.js @@ -169,6 +169,9 @@ function handleError(r) { window.location.reload(true); return } + if (r.headers.get("Content-Type").startsWith("application/json")) { + return r.json().then(d => {throw new Error(d.error)}); + } if (r.status === 400) { return r.text().then(text => {throw new Error(text)}) } From 6143af363cfa2dd4215eb0fee516b25cca3faa11 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 18 Nov 2024 07:51:56 +0100 Subject: [PATCH 2/3] Expose integration providers' name --- internal/integrations/integrations.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/integrations/integrations.go b/internal/integrations/integrations.go index 42423f71..e850c629 100644 --- a/internal/integrations/integrations.go +++ b/internal/integrations/integrations.go @@ -13,11 +13,11 @@ import ( ) const ( - ftpProvider = "ftp" - webdavProvider = "webdav" - dropboxProvider = "dropbox" - googleProvider = "google" - localfsProvider = "localfs" + FtpProvider = "ftp" + WebdavProvider = "webdav" + DropboxProvider = "dropbox" + GoogleProvider = "google" + LocalfsProvider = "localfs" ) // IntegrationProvider abstracts 3rd party integrations @@ -39,13 +39,13 @@ func GetIntegrationProvider(storer storage.UserStorer, uid, integrationid string continue } switch intg.Provider { - case dropboxProvider: + case DropboxProvider: return newDropbox(intg), nil - case ftpProvider: + case FtpProvider: return newFTP(intg), nil - case localfsProvider: + case LocalfsProvider: return newLocalFS(intg), nil - case webdavProvider: + case WebdavProvider: return newWebDav(intg), nil } } @@ -56,13 +56,13 @@ func GetIntegrationProvider(storer storage.UserStorer, uid, integrationid string // fix the name func fixProviderName(n string) string { switch n { - case ftpProvider: + case FtpProvider: fallthrough - case dropboxProvider: + case DropboxProvider: return "Dropbox" - case googleProvider: + case GoogleProvider: fallthrough - case webdavProvider: + case WebdavProvider: return "GoogleDrive" default: return n From c670131c75edfc851f74bdbdc00d52cdb88851c4 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 18 Nov 2024 07:55:53 +0100 Subject: [PATCH 3/3] Disallow adding/editing localfs integration from ui --- internal/ui/handlers.go | 22 +++++++++++++++++++ ui/src/pages/Integrations/IntegrationModal.js | 4 +++- .../pages/Integrations/NewIntegrationModal.js | 4 +++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/internal/ui/handlers.go b/internal/ui/handlers.go index 5d752386..bfc72e9f 100644 --- a/internal/ui/handlers.go +++ b/internal/ui/handlers.go @@ -14,6 +14,7 @@ import ( "github.com/golang-jwt/jwt/v4" "github.com/google/uuid" log "github.com/sirupsen/logrus" + "gopkg.in/yaml.v3" ) const ( @@ -529,6 +530,16 @@ func (app *ReactAppWrapper) listIntegrations(c *gin.Context) { c.JSON(http.StatusOK, user.Integrations) } +func warnLocalfsEdition(c *gin.Context, int *model.IntegrationConfig) { + s, err := yaml.Marshal(gin.H{"integrations": []*model.IntegrationConfig{int}}) + if err != nil { + log.Error("error updating user", err) + c.AbortWithStatus(http.StatusInternalServerError) + return + } + c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "To avoid security issues with local directory integration, you have to manually edit your .userprofile file:\n\n" + string(s)}) +} + func (app *ReactAppWrapper) createIntegration(c *gin.Context) { int := model.IntegrationConfig{} if err := c.ShouldBindJSON(&int); err != nil { @@ -537,6 +548,12 @@ func (app *ReactAppWrapper) createIntegration(c *gin.Context) { return } + if int.Provider == integrations.LocalfsProvider { + int.ID = uuid.NewString() + warnLocalfsEdition(c, &int) + return + } + uid := c.GetString(userIDContextKey) user, err := app.userStorer.GetUser(uid) @@ -590,6 +607,11 @@ func (app *ReactAppWrapper) updateIntegration(c *gin.Context) { return } + if int.Provider == integrations.LocalfsProvider { + warnLocalfsEdition(c, &int) + return + } + uid := c.GetString(userIDContextKey) intid := common.ParamS(intIDParam, c) diff --git a/ui/src/pages/Integrations/IntegrationModal.js b/ui/src/pages/Integrations/IntegrationModal.js index e4c89843..ac6cbfc4 100644 --- a/ui/src/pages/Integrations/IntegrationModal.js +++ b/ui/src/pages/Integrations/IntegrationModal.js @@ -71,7 +71,9 @@ export default function IntegrationModal(params) {
IntegrationID diff --git a/ui/src/pages/Integrations/NewIntegrationModal.js b/ui/src/pages/Integrations/NewIntegrationModal.js index 68965a36..c88d908d 100644 --- a/ui/src/pages/Integrations/NewIntegrationModal.js +++ b/ui/src/pages/Integrations/NewIntegrationModal.js @@ -54,7 +54,9 @@ export default function IntegrationProfileModal(params) {