2020-12-03 05:38:00 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
|
|
|
|
|
package api4
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2023-06-11 01:24:35 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
|
|
|
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
2020-12-03 05:38:00 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (api *API) InitImport() {
|
2024-07-15 10:52:03 -04:00
|
|
|
api.BaseRoutes.Imports.Handle("", api.APISessionRequired(listImports)).Methods(http.MethodGet)
|
2025-06-10 06:06:38 -04:00
|
|
|
api.BaseRoutes.Import.Handle("", api.APISessionRequired(deleteImport)).Methods(http.MethodDelete)
|
2020-12-03 05:38:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func listImports(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
if !c.IsSystemAdmin() {
|
2021-07-12 14:05:36 -04:00
|
|
|
c.SetPermissionError(model.PermissionManageSystem)
|
2020-12-03 05:38:00 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imports, appErr := c.App.ListImports()
|
|
|
|
|
if appErr != nil {
|
|
|
|
|
c.Err = appErr
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 10:28:52 -04:00
|
|
|
if err := json.NewEncoder(w).Encode(imports); err != nil {
|
|
|
|
|
c.Logger.Warn("Error writing imports", mlog.Err(err))
|
2020-12-03 05:38:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-10 06:06:38 -04:00
|
|
|
|
|
|
|
|
func deleteImport(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
importName := c.Params.ImportName
|
2025-07-16 00:47:03 -04:00
|
|
|
auditRec := c.MakeAuditRecord(model.AuditEventDeleteImport, model.AuditStatusFail)
|
2025-06-10 06:06:38 -04:00
|
|
|
defer c.LogAuditRec(auditRec)
|
|
|
|
|
auditRec.AddMeta("import_name", importName)
|
|
|
|
|
|
|
|
|
|
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageSystem) {
|
|
|
|
|
c.SetPermissionError(model.PermissionManageSystem)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := c.App.DeleteImport(importName); err != nil {
|
|
|
|
|
c.Err = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auditRec.Success()
|
|
|
|
|
ReturnStatusOK(w)
|
|
|
|
|
}
|