mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 08:00:53 +00:00
feat: record user in operation logs (#12596)
This commit is contained in:
committed by
zhengkunwang223
parent
12f2d95265
commit
db4f699b85
@@ -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"`
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -39,6 +39,7 @@ func Init() {
|
||||
migrations.AddDocSourceSetting,
|
||||
migrations.AddAppStoreInstallAllowPortSetting,
|
||||
migrations.AddUserManagementMenu,
|
||||
migrations.AddOperationLogUser,
|
||||
})
|
||||
if err := m.Migrate(); err != nil {
|
||||
global.LOG.Error(err)
|
||||
|
||||
@@ -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{})
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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+"]") {
|
||||
|
||||
@@ -5,6 +5,7 @@ export namespace Log {
|
||||
export interface OperationLog {
|
||||
id: number;
|
||||
source: string;
|
||||
user: string;
|
||||
action: string;
|
||||
ip: string;
|
||||
path: string;
|
||||
|
||||
@@ -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'">
|
||||
|
||||
Reference in New Issue
Block a user