Fix for hideUser
Cette révision appartient à :
Parent
7092e4fc36
révision
c10c1e86ae
6 fichiers modifiés avec 34 ajouts et 4 suppressions
|
@ -239,7 +239,7 @@ func CommentsListPanel(c *gin.Context) {
|
|||
// TorrentEditModPanel : Controller for editing a torrent after GET request
|
||||
func TorrentEditModPanel(c *gin.Context) {
|
||||
id, _ := strconv.ParseInt(c.Query("id"), 10, 32)
|
||||
torrent, _ := torrents.FindByID(uint(id))
|
||||
torrent, _ := torrents.FindUnscopeByID(uint(id))
|
||||
|
||||
torrentJSON := torrent.ToJSON()
|
||||
uploadForm := upload.NewTorrentRequest()
|
||||
|
@ -259,7 +259,7 @@ func TorrentPostEditModPanel(c *gin.Context) {
|
|||
var uploadForm torrentValidator.TorrentRequest
|
||||
id, _ := strconv.ParseInt(c.Query("id"), 10, 32)
|
||||
messages := msg.GetMessages(c)
|
||||
torrent, _ := torrents.FindByID(uint(id))
|
||||
torrent, _ := torrents.FindUnscopeByID(uint(id))
|
||||
if torrent.ID > 0 {
|
||||
errUp := upload.ExtractEditInfo(c, &uploadForm)
|
||||
if errUp != nil {
|
||||
|
@ -278,6 +278,9 @@ func TorrentPostEditModPanel(c *gin.Context) {
|
|||
_, err := torrent.UpdateUnscope()
|
||||
messages.AddInfoT("infos", "torrent_updated")
|
||||
if err == nil { // We only log edit torrent for admins
|
||||
if torrent.Uploader == nil {
|
||||
torrent.Uploader = &models.User{}
|
||||
}
|
||||
_, username := torrents.HideUser(torrent.UploaderID, torrent.Uploader.Username, torrent.Hidden)
|
||||
activities.Log(&models.User{}, torrent.Identifier(), "edit", "torrent_edited_by", strconv.Itoa(int(torrent.ID)), username, getUser(c).Username)
|
||||
}
|
||||
|
@ -327,6 +330,9 @@ func TorrentDeleteModPanel(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
if err == nil {
|
||||
if torrent.Uploader == nil {
|
||||
torrent.Uploader = &models.User{}
|
||||
}
|
||||
_, username := torrents.HideUser(torrent.UploaderID, torrent.Uploader.Username, torrent.Hidden)
|
||||
activities.Log(&models.User{}, torrent.Identifier(), "delete", "torrent_deleted_by", strconv.Itoa(int(torrent.ID)), username, getUser(c).Username)
|
||||
}
|
||||
|
@ -472,6 +478,9 @@ func TorrentBlockModPanel(c *gin.Context) {
|
|||
action = "unblocked"
|
||||
}
|
||||
if err == nil {
|
||||
if torrent.Uploader == nil {
|
||||
torrent.Uploader = &models.User{}
|
||||
}
|
||||
_, username := torrents.HideUser(torrent.UploaderID, torrent.Uploader.Username, torrent.Hidden)
|
||||
activities.Log(&models.User{}, torrent.Identifier(), action, "torrent_"+action+"_by", strconv.Itoa(int(torrent.ID)), username, getUser(c).Username)
|
||||
}
|
||||
|
@ -577,6 +586,9 @@ func torrentManyAction(c *gin.Context) {
|
|||
/* Changes are done, we save */
|
||||
_, err := torrent.UpdateUnscope()
|
||||
if err == nil {
|
||||
if torrent.Uploader == nil {
|
||||
torrent.Uploader = &models.User{}
|
||||
}
|
||||
_, username := torrents.HideUser(torrent.UploaderID, torrent.Uploader.Username, torrent.Hidden)
|
||||
activities.Log(&models.User{}, torrent.Identifier(), "edited", "torrent_edited_by", strconv.Itoa(int(torrent.ID)), username, getUser(c).Username)
|
||||
}
|
||||
|
@ -591,6 +603,9 @@ func torrentManyAction(c *gin.Context) {
|
|||
messages.ImportFromError("errors", err)
|
||||
} else {
|
||||
messages.AddInfoTf("infos", "torrent_deleted", torrent.Name)
|
||||
if torrent.Uploader == nil {
|
||||
torrent.Uploader = &models.User{}
|
||||
}
|
||||
_, username := torrents.HideUser(torrent.UploaderID, torrent.Uploader.Username, torrent.Hidden)
|
||||
activities.Log(&models.User{}, torrent.Identifier(), "deleted", "torrent_deleted_by", strconv.Itoa(int(torrent.ID)), username, getUser(c).Username)
|
||||
}
|
||||
|
|
|
@ -223,6 +223,9 @@ func TorrentDeleteUserPanel(c *gin.Context) {
|
|||
if currentUser.CurrentOrAdmin(torrent.UploaderID) {
|
||||
_, _, err := torrent.Delete(false)
|
||||
if err == nil {
|
||||
if torrent.Uploader == nil {
|
||||
torrent.Uploader = &models.User{}
|
||||
}
|
||||
_, username := torrents.HideUser(torrent.UploaderID, torrent.Uploader.Username, torrent.Hidden)
|
||||
if currentUser.HasAdmin() { // We hide username on log activity if user is not admin and torrent is hidden
|
||||
activities.Log(&models.User{}, torrent.Identifier(), "delete", "torrent_deleted_by", strconv.Itoa(int(torrent.ID)), username, currentUser.Username)
|
||||
|
|
|
@ -74,6 +74,16 @@ func FindRawByID(id uint) (torrent models.Torrent, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// FindUnscopeByID : Get torrent with ID deleted or not
|
||||
func FindUnscopeByID(id uint) (torrent models.Torrent, err error) {
|
||||
err = nil
|
||||
if models.ORM.Unscoped().Where("torrent_id = ?", id).Preload("Uploader").Find(&torrent).RecordNotFound() {
|
||||
err = errors.New("Torrent is not found")
|
||||
}
|
||||
torrent.ParseLanguages()
|
||||
return
|
||||
}
|
||||
|
||||
// FindRawByHash : Get torrent with id without user or comments
|
||||
// won't fetch user or comments
|
||||
func FindRawByHash(hash string) (torrent models.Torrent, err error) {
|
||||
|
|
|
@ -52,7 +52,7 @@ func NewTorrentEvent(user *models.User, torrent *models.Torrent) error {
|
|||
|
||||
// HideUser : hides a torrent user for hidden torrents
|
||||
func HideUser(uploaderID uint, uploaderName string, torrentHidden bool) (uint, string) {
|
||||
if torrentHidden {
|
||||
if uploaderName == "" || torrentHidden {
|
||||
return 0, "れんちょん"
|
||||
}
|
||||
if uploaderID == 0 {
|
||||
|
|
|
@ -107,6 +107,7 @@ func byQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool,
|
|||
search.FromRequest(c)
|
||||
search.Offset = uint32(pagenum)
|
||||
search.Hidden = hidden
|
||||
search.Deleted = deleted
|
||||
search.Full = withUser
|
||||
|
||||
orderBy := search.Sort.ToDBField()
|
||||
|
|
|
@ -37,6 +37,7 @@ type TorrentParam struct {
|
|||
Full bool // True means load all members
|
||||
Order bool // True means ascending
|
||||
Hidden bool // True means filter hidden torrents
|
||||
Deleted bool // False means filter deleted torrents
|
||||
Status Status
|
||||
Sort SortMode
|
||||
Category Categories
|
||||
|
@ -63,7 +64,7 @@ func (p *TorrentParam) Identifier() string {
|
|||
for _, v := range p.Languages {
|
||||
languages += fmt.Sprintf("%s%s", v.Code, v.Name)
|
||||
}
|
||||
return fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%d%d%s%t%t%t", p.NameLike, p.NotNull, languages, p.Max, p.Offset, p.FromID, p.MinSize, p.MaxSize, p.Status, p.Sort, p.FromDate, p.ToDate, p.UserID, p.TorrentID, cats, p.Full, p.Order, p.Hidden)
|
||||
return fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%d%d%s%t%t%t%t", p.NameLike, p.NotNull, languages, p.Max, p.Offset, p.FromID, p.MinSize, p.MaxSize, p.Status, p.Sort, p.FromDate, p.ToDate, p.UserID, p.TorrentID, cats, p.Full, p.Order, p.Hidden, p.Deleted)
|
||||
}
|
||||
|
||||
func (st *Status) ToString() string {
|
||||
|
|
Référencer dans un nouveau ticket