forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operation.go
37 lines (32 loc) · 1.1 KB
/
operation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package controller
import (
"encoding/json"
"github.com/kamruljpi/go-admin/context"
"github.com/kamruljpi/go-admin/modules/config"
"github.com/kamruljpi/go-admin/plugins/admin/models"
"github.com/kamruljpi/go-admin/plugins/admin/modules/constant"
"github.com/kamruljpi/go-admin/plugins/admin/modules/response"
)
func (h *Handler) Operation(ctx *context.Context) {
id := ctx.Query("__goadmin_op_id")
if !h.OperationHandler(config.Url("/operation/"+id), ctx) {
errMsg := "not found"
if ctx.Headers(constant.PjaxHeader) == "" && ctx.Method() != "GET" {
response.BadRequest(ctx, errMsg)
} else {
response.Alert(ctx, errMsg, errMsg, errMsg, h.conn, h.navButtons)
}
return
}
}
// RecordOperationLog record all operation logs, store into database.
func (h *Handler) RecordOperationLog(ctx *context.Context) {
if user, ok := ctx.UserValue["user"].(models.UserModel); ok {
var input []byte
form := ctx.Request.MultipartForm
if form != nil {
input, _ = json.Marshal((*form).Value)
}
models.OperationLog().SetConn(h.conn).New(user.Id, ctx.Path(), ctx.Method(), ctx.LocalIP(), string(input))
}
}