Skip to content

Commit

Permalink
Merge pull request #340 from nemunaire/integration-localfs-ui
Browse files Browse the repository at this point in the history
Disallow adding/editing localfs integration from ui
  • Loading branch information
ddvk authored Nov 18, 2024
2 parents 70f801d + c670131 commit 3371a3c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
26 changes: 13 additions & 13 deletions internal/integrations/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions internal/ui/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion ui/src/pages/Integrations/IntegrationModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export default function IntegrationModal(params) {
<div>
<Alert variant="danger" hidden={!formErrors.error}>
<Alert.Heading>An Error Occurred</Alert.Heading>
{formErrors.error}
<div style={{'white-space': 'pre-wrap'}}>
{formErrors.error}
</div>
</Alert>

<Form.Label>IntegrationID</Form.Label>
Expand Down
4 changes: 3 additions & 1 deletion ui/src/pages/Integrations/NewIntegrationModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export default function IntegrationProfileModal(params) {
<Card.Body>
<Alert variant="danger" hidden={!formErrors.error}>
<Alert.Heading>An Error Occurred</Alert.Heading>
{formErrors.error}
<div style={{'white-space': 'pre-wrap'}}>
{formErrors.error}
</div>
</Alert>

<Alert variant="info" hidden={!formInfo.message}>
Expand Down
3 changes: 3 additions & 0 deletions ui/src/services/api.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
}
Expand Down

0 comments on commit 3371a3c

Please sign in to comment.