-
Notifications
You must be signed in to change notification settings - Fork 2
/
auditlog.go
73 lines (60 loc) · 1.64 KB
/
auditlog.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package auditlog
import (
"github.com/kubeservice-stack/basa/src/backend/controllers/base"
"github.com/kubeservice-stack/basa/src/backend/models"
"github.com/kubeservice-stack/basa/src/backend/util/logs"
)
type AuditLogController struct {
base.APIController
}
func (c *AuditLogController) URLMapping() {
c.Mapping("List", c.List)
}
func (c *AuditLogController) Prepare() {
// Check administration
c.APIController.Prepare()
}
// @Title GetAll
// @Description get audit log
// @Param pageNo query int false "the page current no"
// @Param pageSize query int false "the page size"
// @Success 200 {object} []models.AuditLog success
// @router / [get]
func (c *AuditLogController) List() {
param := c.BuildQueryParam()
user := c.Input().Get("user")
if user != "" {
param.Query["User__contains"] = user
}
userIp := c.Input().Get("userIp")
if userIp != "" {
param.Query["UserIp__contains"] = userIp
}
logType := c.Input().Get("logType")
if logType != "" {
param.Query["LogType__contains"] = logType
}
logLevel := c.Input().Get("logLevel")
if logLevel != "" {
param.Query["LogLevel__contains"] = logLevel
}
action := c.Input().Get("action")
if action != "" {
param.Query["Action__contains"] = action
}
auditLogs := []models.AuditLog{}
total, err := models.GetTotal(new(models.AuditLog), param)
if err != nil {
logs.Error("get total count by param (%v) error. %v", param, err)
c.HandleError(err)
return
}
err = models.GetAll(new(models.AuditLog), &auditLogs, param)
if err != nil {
logs.Error("list by param (%v) error. %v", param, err)
c.HandleError(err)
return
}
c.Success(param.NewPage(total, auditLogs))
return
}