diff --git a/core/app/dto/logs.go b/core/app/dto/logs.go
index 16a71ef84444..189ce6ab15ee 100644
--- a/core/app/dto/logs.go
+++ b/core/app/dto/logs.go
@@ -7,6 +7,7 @@ import (
type OperationLog struct {
ID uint `json:"id"`
Source string `json:"source"`
+ User string `json:"user"`
Node string `json:"node"`
IP string `json:"ip"`
Path string `json:"path"`
diff --git a/core/app/model/logs.go b/core/app/model/logs.go
index 99e26c43f3bd..511ebad44011 100644
--- a/core/app/model/logs.go
+++ b/core/app/model/logs.go
@@ -7,6 +7,7 @@ import (
type OperationLog struct {
BaseModel
Source string `json:"source"`
+ User string `json:"user"`
IP string `json:"ip"`
Node string `json:"node"`
Path string `json:"path"`
diff --git a/core/init/migration/migrate.go b/core/init/migration/migrate.go
index 86cb75c0aeff..53f2bb5eba54 100644
--- a/core/init/migration/migrate.go
+++ b/core/init/migration/migrate.go
@@ -39,6 +39,7 @@ func Init() {
migrations.AddDocSourceSetting,
migrations.AddAppStoreInstallAllowPortSetting,
migrations.AddUserManagementMenu,
+ migrations.AddOperationLogUser,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
diff --git a/core/init/migration/migrations/init.go b/core/init/migration/migrations/init.go
index 47511fa81a60..fa4a95e7dceb 100644
--- a/core/init/migration/migrations/init.go
+++ b/core/init/migration/migrations/init.go
@@ -1041,3 +1041,10 @@ var AddUserManagementMenu = &gormigrate.Migration{
return tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Update("value", string(updatedJSON)).Error
},
}
+
+var AddOperationLogUser = &gormigrate.Migration{
+ ID: "20260424-add-operation-log-user",
+ Migrate: func(tx *gorm.DB) error {
+ return tx.AutoMigrate(&model.OperationLog{})
+ },
+}
diff --git a/core/middleware/operation.go b/core/middleware/operation.go
index f7b36d58279e..a4b889631983 100644
--- a/core/middleware/operation.go
+++ b/core/middleware/operation.go
@@ -21,6 +21,7 @@ import (
"github.com/1Panel-dev/1Panel/core/cmd/server/docs"
"github.com/1Panel-dev/1Panel/core/constant"
"github.com/1Panel-dev/1Panel/core/global"
+ psessionUtils "github.com/1Panel-dev/1Panel/core/init/session/psession"
"github.com/gin-gonic/gin"
"github.com/glebarez/sqlite"
"gorm.io/gorm"
@@ -107,6 +108,8 @@ func OperationLog() gin.HandlerFunc {
c.Next()
+ record.User = loadOperationUser(c)
+
if len(operationDic.BeforeFunctions) != 0 {
if needAgentResolve {
mergeResolvedData(writer.resolvedHeader, formatMap)
@@ -173,6 +176,18 @@ func OperationLog() gin.HandlerFunc {
}
}
+func loadOperationUser(c *gin.Context) string {
+ sessionUser, ok := c.Get(psessionUtils.GinContextSessionUserKey)
+ if !ok {
+ return ""
+ }
+ psession, ok := sessionUser.(psessionUtils.SessionUser)
+ if !ok {
+ return ""
+ }
+ return psession.Name
+}
+
func fillOperationDetail(operationDic *operationJson, formatMap map[string]interface{}) {
for key, value := range formatMap {
if !strings.Contains(operationDic.FormatEN, "["+key+"]") {
diff --git a/frontend/src/api/interface/log.ts b/frontend/src/api/interface/log.ts
index 146649b2e95a..81c6afde4c71 100644
--- a/frontend/src/api/interface/log.ts
+++ b/frontend/src/api/interface/log.ts
@@ -5,6 +5,7 @@ export namespace Log {
export interface OperationLog {
id: number;
source: string;
+ user: string;
action: string;
ip: string;
path: string;
diff --git a/frontend/src/views/log/operation/index.vue b/frontend/src/views/log/operation/index.vue
index caf77b41ed89..fa0f49110a9d 100644
--- a/frontend/src/views/log/operation/index.vue
+++ b/frontend/src/views/log/operation/index.vue
@@ -60,6 +60,7 @@
+