Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/app/dto/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions core/app/model/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions core/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func Init() {
migrations.AddDocSourceSetting,
migrations.AddAppStoreInstallAllowPortSetting,
migrations.AddUserManagementMenu,
migrations.AddOperationLogUser,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
Expand Down
7 changes: 7 additions & 0 deletions core/init/migration/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
},
}
15 changes: 15 additions & 0 deletions core/middleware/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -173,6 +176,18 @@ func OperationLog() gin.HandlerFunc {
}
}

func loadOperationUser(c *gin.Context) string {
sessionUser, ok := c.Get(psessionUtils.GinContextSessionUserKey)
if !ok {
return ""
Comment on lines +180 to +182
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fall back to session lookup when context user is missing

loadOperationUser only checks GinContextSessionUserKey and returns "" when that key is absent. In this middleware stack, some logged routes (notably /api/v2/core/auth/*) bypass the code path that sets this context value, so requests with valid session cookies still get stored with an empty user field; this makes the new operation-log user column unreliable for actions like MFA/API config changes. Add a fallback to read the current session directly when the context key is unavailable.

Useful? React with 👍 / 👎.

}
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+"]") {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/interface/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export namespace Log {
export interface OperationLog {
id: number;
source: string;
user: string;
action: string;
ip: string;
path: string;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/log/operation/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
</span>
</template>
</el-table-column>
<el-table-column :label="$t('commons.table.user')" prop="user" show-overflow-tooltip />
<el-table-column :label="$t('commons.table.operate')" min-width="150px" prop="detailZH">
<template #default="{ row }">
<span v-if="globalStore.language === 'zh' || globalStore.language === 'zh-Hant'">
Expand Down
Loading