Added moderation, report and approval buttons for admins, uploaders and anonymous people

This commit is contained in:
Christoph Haas 2016-04-07 18:44:12 +02:00
parent 014a840493
commit 9bb9cf1f5d
5 changed files with 43 additions and 10 deletions

View file

@ -1,5 +1,5 @@
class PackagesController < ApplicationController
before_action :authenticate_user!, only: [:moderate]
before_action :authenticate_user!, only: [:moderate, :moderate_screenshot]
def list
@packages = query_packages
@ -96,6 +96,28 @@ class PackagesController < ApplicationController
@screenshot = Screenshot.find(params[:id])
@screenshot.description = params[:description]
@screenshot.save!
flash['notice'] = "Description updated."
redirect_to package_path
end
# Receive an anonymous report from a user to have a screenshot removed.
def report_screenshot
@screenshot = Screenshot.find(params[:id])
@screenshot.delete_reason = params[:delete_reason]
@screenshot.markedfordelete = true
@screenshot.save!
flash['notice'] = "Screenshot reported. The moderators will deal with it."
redirect_to package_path
end
# Publish a screenshot from the moderation queue
def approve_screenshot
@screenshot = Screenshot.find(params[:id])
@screenshot.delete_reason = nil
@screenshot.markedfordelete = false
@screenshot.approved = true
@screenshot.save!
flash['notice'] = "Screenshot approved."
redirect_to package_path
end

View file

@ -1,14 +1,18 @@
// Button that reveals a dropdown/modal for admins
.text-center
.text-right
button.small.dropdown.warning.button type="button" data-toggle="admin-info-#{screenshot.id}"
'Admin
.dropdown-pane data-dropdown=true id="admin-info-#{screenshot.id}"
a.button.small.success[
href=approve_screenshot_path(@package.name, screenshot.id)
method='post'
] Approve screenshot
a.button.small.alert[
href=delete_screenshot_path(@package.name, screenshot.id)
onclick="return confirm('Really delete the screenshot?');"
] Delete screenshot
p Status: #{screenshot.status}
p Uploader IP=#{screenshot.uploaderip}
p Uploader Token=#{session[:token]}
p Uploaded #{screenshot.age_days} (#{screenshot.created_at})
p Status: #{screenshot.status}

View file

@ -1,5 +1,5 @@
// Button that reveals a dropdown/modal for users (for their own screenshots)
.text-center
.text-right
button.small.dropdown.warning.button type="button" data-toggle="admin-info-#{screenshot.id}"
'Manage your screenshot
.dropdown-pane data-dropdown=true id="admin-info-#{screenshot.id}"

View file

@ -13,12 +13,16 @@
= image_tag(screenshot.image.url(:large, timestamp: false), alt: screenshot.caption)
.imgcaption =screenshot.caption
// TODO: Show information only if admin
- if user_signed_in?
// Button that reveals a dropdown/modal for admins
= render(partial: 'admin_dropdown', locals: {screenshot: screenshot})
- elsif screenshot.uploaderhash == session[:token]
= render(partial: 'user_dropdown', locals: {screenshot: screenshot})
// Is the user an admin?
- if user_signed_in?
= render(partial: 'admin_dropdown', locals: {screenshot: screenshot})
// or does the screenshot belong to the user (determined by session cookie)
- elsif screenshot.uploaderhash == session[:token]
= render(partial: 'user_dropdown', locals: {screenshot: screenshot})
// or is the user not related to the screenshot and the screenshot is public?
- elsif screenshot.approved
= render(partial: 'report_dropdown', locals: {screenshot: screenshot})
// Anonymous users can see their own screenshots
/ - if not screenshot.approved

View file

@ -21,6 +21,9 @@ Debshots::Application.routes.draw do
# TODO: "get" is probably the wrong method to delete a screenshot
get 'delete_screenshot/:name/:id' => 'packages#delete_screenshot', as: :delete_screenshot
post 'update_screenshot_description/:name/:id' => 'packages#update_screenshot_description', as: :update_screenshot_description
post 'report_screenshot/:name/:id' => 'packages#report_screenshot', as: :report_screenshot
# TODO: "get" is probably the wrong method to delete a screenshot
get 'approve_screenshot/:name/:id' => 'packages#approve_screenshot', as: :approve_screenshot
get 'about' => 'welcome#about'
get 'thumbnail/:name' => 'packages#thumbnail', as: :thumbnail_image, name: /[^\/]+/