File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77type OperationLog struct {
88 ID uint `json:"id"`
99 Source string `json:"source"`
10+ User string `json:"user"`
1011 Node string `json:"node"`
1112 IP string `json:"ip"`
1213 Path string `json:"path"`
Original file line number Diff line number Diff line change 77type OperationLog struct {
88 BaseModel
99 Source string `json:"source"`
10+ User string `json:"user"`
1011 IP string `json:"ip"`
1112 Node string `json:"node"`
1213 Path string `json:"path"`
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ func Init() {
3939 migrations .AddDocSourceSetting ,
4040 migrations .AddAppStoreInstallAllowPortSetting ,
4141 migrations .AddUserManagementMenu ,
42+ migrations .AddOperationLogUser ,
4243 })
4344 if err := m .Migrate (); err != nil {
4445 global .LOG .Error (err )
Original file line number Diff line number Diff line change @@ -1041,3 +1041,10 @@ var AddUserManagementMenu = &gormigrate.Migration{
10411041 return tx .Model (& model.Setting {}).Where ("key = ?" , "HideMenu" ).Update ("value" , string (updatedJSON )).Error
10421042 },
10431043}
1044+
1045+ var AddOperationLogUser = & gormigrate.Migration {
1046+ ID : "20260424-add-operation-log-user" ,
1047+ Migrate : func (tx * gorm.DB ) error {
1048+ return tx .AutoMigrate (& model.OperationLog {})
1049+ },
1050+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import (
2121 "github.com/1Panel-dev/1Panel/core/cmd/server/docs"
2222 "github.com/1Panel-dev/1Panel/core/constant"
2323 "github.com/1Panel-dev/1Panel/core/global"
24+ psessionUtils "github.com/1Panel-dev/1Panel/core/init/session/psession"
2425 "github.com/gin-gonic/gin"
2526 "github.com/glebarez/sqlite"
2627 "gorm.io/gorm"
@@ -107,6 +108,8 @@ func OperationLog() gin.HandlerFunc {
107108
108109 c .Next ()
109110
111+ record .User = loadOperationUser (c )
112+
110113 if len (operationDic .BeforeFunctions ) != 0 {
111114 if needAgentResolve {
112115 mergeResolvedData (writer .resolvedHeader , formatMap )
@@ -173,6 +176,18 @@ func OperationLog() gin.HandlerFunc {
173176 }
174177}
175178
179+ func loadOperationUser (c * gin.Context ) string {
180+ sessionUser , ok := c .Get (psessionUtils .GinContextSessionUserKey )
181+ if ! ok {
182+ return ""
183+ }
184+ psession , ok := sessionUser .(psessionUtils.SessionUser )
185+ if ! ok {
186+ return ""
187+ }
188+ return psession .Name
189+ }
190+
176191func fillOperationDetail (operationDic * operationJson , formatMap map [string ]interface {}) {
177192 for key , value := range formatMap {
178193 if ! strings .Contains (operationDic .FormatEN , "[" + key + "]" ) {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export namespace Log {
55 export interface OperationLog {
66 id : number ;
77 source : string ;
8+ user : string ;
89 action : string ;
910 ip : string ;
1011 path : string ;
Original file line number Diff line number Diff line change 6060 </span >
6161 </template >
6262 </el-table-column >
63+ <el-table-column :label =" $t('commons.table.user')" prop =" user" show-overflow-tooltip />
6364 <el-table-column :label =" $t('commons.table.operate')" min-width =" 150px" prop =" detailZH" >
6465 <template #default =" { row } " >
6566 <span v-if =" globalStore.language === 'zh' || globalStore.language === 'zh-Hant'" >
You can’t perform that action at this time.
0 commit comments