You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

operate_log.go 1.4 kB

2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package operate_log
  2. import (
  3. "code.gitea.io/gitea/models"
  4. )
  5. type LogBizType string
  6. const (
  7. BadgeCategoryOperate LogBizType = "BadgeCategoryOperate"
  8. BadgeOperate LogBizType = "BadgeOperate"
  9. )
  10. func Log(log models.AdminOperateLog) error {
  11. _, err := models.InsertAdminOperateLog(log)
  12. return err
  13. }
  14. func NewLogValues() *models.LogValues {
  15. return &models.LogValues{Params: make([]models.LogValue, 0)}
  16. }
  17. func Log4Add(bizType LogBizType, newValue interface{}, doerId int64, comment string) {
  18. Log(models.AdminOperateLog{
  19. BizType: string(bizType),
  20. OperateType: "add",
  21. NewValue: NewLogValues().Add("new", newValue).JsonString(),
  22. CreatedBy: doerId,
  23. Comment: comment,
  24. })
  25. }
  26. func Log4Edit(bizType LogBizType, oldValue interface{}, newValue interface{}, doerId int64, comment string) {
  27. Log(models.AdminOperateLog{
  28. BizType: string(bizType),
  29. OperateType: "edit",
  30. NewValue: NewLogValues().Add("new", newValue).JsonString(),
  31. OldValue: NewLogValues().Add("old", oldValue).JsonString(),
  32. CreatedBy: doerId,
  33. Comment: comment,
  34. })
  35. }
  36. func Log4Del(bizType LogBizType, oldValue interface{}, doerId int64, comment string) {
  37. Log(models.AdminOperateLog{
  38. BizType: string(bizType),
  39. OperateType: "del",
  40. OldValue: NewLogValues().Add("old", oldValue).JsonString(),
  41. CreatedBy: doerId,
  42. Comment: comment,
  43. })
  44. }