feat: add audit log to resource handlers (#2369)
This commit is contained in:
parent
3ba68c2acf
commit
ab1aed2be1
@ -14,6 +14,7 @@ import (
|
||||
"github.com/shirou/gopsutil/v3/disk"
|
||||
"github.com/spf13/afero"
|
||||
|
||||
"github.com/filebrowser/filebrowser/v2/audit"
|
||||
"github.com/filebrowser/filebrowser/v2/errors"
|
||||
"github.com/filebrowser/filebrowser/v2/files"
|
||||
"github.com/filebrowser/filebrowser/v2/fileutils"
|
||||
@ -86,6 +87,12 @@ func resourceDeleteHandler(fileCache FileCache) handleFunc {
|
||||
return errToStatus(err), err
|
||||
}
|
||||
|
||||
audit.LogResourceActivity(audit.ResourceActivity{
|
||||
Event: "Deletion",
|
||||
ResourcePath: r.URL.Path,
|
||||
User: d.user,
|
||||
})
|
||||
|
||||
return http.StatusOK, nil
|
||||
})
|
||||
}
|
||||
@ -139,6 +146,12 @@ func resourcePostHandler(fileCache FileCache) handleFunc {
|
||||
|
||||
if err != nil {
|
||||
_ = d.user.Fs.RemoveAll(r.URL.Path)
|
||||
} else {
|
||||
audit.LogResourceActivity(audit.ResourceActivity{
|
||||
Event: "Creation",
|
||||
ResourcePath: r.URL.Path,
|
||||
User: d.user,
|
||||
})
|
||||
}
|
||||
|
||||
return errToStatus(err), err
|
||||
@ -174,6 +187,14 @@ var resourcePutHandler = withUser(func(w http.ResponseWriter, r *http.Request, d
|
||||
return nil
|
||||
}, "save", r.URL.Path, "", d.user)
|
||||
|
||||
if err == nil {
|
||||
audit.LogResourceActivity(audit.ResourceActivity{
|
||||
Event: "Update",
|
||||
ResourcePath: r.URL.Path,
|
||||
User: d.user,
|
||||
})
|
||||
}
|
||||
|
||||
return errToStatus(err), err
|
||||
})
|
||||
|
||||
@ -218,6 +239,14 @@ func resourcePatchHandler(fileCache FileCache) handleFunc {
|
||||
return patchAction(r.Context(), action, src, dst, d, fileCache)
|
||||
}, action, src, dst, d.user)
|
||||
|
||||
if err == nil {
|
||||
audit.LogResourceActivity(audit.ResourceActivity{
|
||||
Event: "Patch",
|
||||
ResourcePath: r.URL.Path,
|
||||
User: d.user,
|
||||
})
|
||||
}
|
||||
|
||||
return errToStatus(err), err
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user