93364dac77
List Torrent delete log Torrent edit log Comment delete log And every other logged activities Can be filtered out by a filter tag ("edit" or "delete" supported) Pages navigation Can be accessed by /activities Added some translation string Fixed hidden username on api request Fixed comments username on modpanel New Activity model New Activity handler New Activity Service Fixed some updating issue for ES when moderating torrents Be aware deleting torrents and comments return the model now!
41 lignes
1,3 Kio
Go
41 lignes
1,3 Kio
Go
package activity
|
|
|
|
import (
|
|
"html/template"
|
|
"strings"
|
|
|
|
"github.com/NyaaPantsu/nyaa/db"
|
|
"github.com/NyaaPantsu/nyaa/model"
|
|
"github.com/NyaaPantsu/nyaa/util/publicSettings"
|
|
)
|
|
|
|
// Log : log an activity from a user to his own id (System user id is 0)
|
|
func Log(user *model.User, name string, filter string, msg ...string) {
|
|
activity := model.NewActivity(name, filter, msg...)
|
|
activity.UserID = user.ID
|
|
db.ORM.Create(&activity)
|
|
}
|
|
|
|
// DeleteAll : Erase aticities from a user (System user id is 0)
|
|
func DeleteAll(id uint) {
|
|
db.ORM.Where("user_id = ?", id).Delete(&model.Activity{})
|
|
}
|
|
|
|
// ToLocale : Convert list of parameters to message in local language
|
|
func ToLocale(a *model.Activity, T publicSettings.TemplateTfunc) template.HTML {
|
|
c := strings.Split(a.Content, ",")
|
|
d := make([]interface{}, len(c)-1)
|
|
for i, s := range c[1:] {
|
|
d[i] = s
|
|
}
|
|
return T(c[0], d...)
|
|
}
|
|
|
|
// GetAllActivities : Get All activities
|
|
func GetAllActivities(limit int, offset int, conditions string, values ...interface{}) ([]model.Activity, int) {
|
|
var activities []model.Activity
|
|
var nbActivities int
|
|
db.ORM.Model(&activities).Where(conditions, values...).Count(&nbActivities)
|
|
db.ORM.Preload("User").Limit(limit).Offset(offset).Order("id DESC").Where(conditions, values...).Find(&activities)
|
|
return activities, nbActivities
|
|
}
|