Added per-user counter of approved/rejected screenshots

This commit is contained in:
Christoph Haas 2021-03-21 23:06:51 +01:00
parent c97a711e6b
commit 9635b3968c
5 changed files with 55 additions and 27 deletions

View file

@ -220,6 +220,14 @@ class PackagesController < ApplicationController
auditlog "Screenshot #{@screenshot.id} deleted",
package: @screenshot.package
@screenshot.destroy
# Increase the rejection counter for the user (social scoring)
# if the screenshot is new and pending approval
if !@screenshot.approved
@screenshot.user.rejected_screenshots += 1
@screenshot.user.save!
end
flash['notice'] = "Screenshot deleted."
redirect_back(fallback_location: package_path(name: @screenshot.package.name))
else
@ -234,6 +242,11 @@ class PackagesController < ApplicationController
@screenshot.approve!
auditlog "Screenshot approved",
package: @screenshot.package, screenshot: @screenshot
# Increase the approval counter for the user (social scoring)
@screenshot.user.approved_screenshots += 1
@screenshot.user.save!
flash['notice'] = "Screenshot approved."
redirect_back(fallback_location: package_path(name: @screenshot.package.name))
else

View file

@ -79,10 +79,6 @@ class User < ApplicationRecord
end
end
def approved_screenshots
self.screenshots.where(approved: true)
end
# Seamlessly create a user account for the current visitor.
# It helps track uploads because uploaded screenshots get assigned
# to this user record.

View file

@ -54,28 +54,39 @@ h1 Your data
hr
.card-section
h3 Your permissions
ul
- if can? :approve, Screenshot.new
li
=> fa_icon 'thumbs-up'
'approve uploaded screenshots
- if can? :destroy, Screenshot.new
li
=> fa_icon 'trash'
'delete screenshots
- if can? :hide, Screenshot.new
li
=> fa_icon 'eye-slash'
'hide screenshots from the public
- if can? :unhide, Screenshot.new
li
=> fa_icon 'eye'
'restore (unhide) screenshots for the public
- if can? :view, Log
li
=> fa_icon 'book'
'view logs
h3 Statistics
p
= pluralize(current_user.approved_screenshots, 'approved screenshot')
p
= pluralize(current_user.rejected_screenshots, 'rejected screenshot')
- unless current_user.pseudo
.cell
hr
.card-section
h3 Your permissions
ul
- if can? :approve, Screenshot.new
li
=> fa_icon 'thumbs-up'
'approve uploaded screenshots
- if can? :destroy, Screenshot.new
li
=> fa_icon 'trash'
'delete screenshots
- if can? :hide, Screenshot.new
li
=> fa_icon 'eye-slash'
'hide screenshots from the public
- if can? :unhide, Screenshot.new
li
=> fa_icon 'eye'
'restore (unhide) screenshots for the public
- if can? :view, Log
li
=> fa_icon 'book'
'view logs
.cell.auto