Skip to content

Commit

Permalink
Merge pull request #384 from linuxfrorg/3186_admin_blocked_images
Browse files Browse the repository at this point in the history
List blocked images
  • Loading branch information
Oumph authored Mar 20, 2024
2 parents 8a582a0 + ac07ad5 commit 82d265e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 16 deletions.
7 changes: 7 additions & 0 deletions app/controllers/admin/images_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# encoding: UTF-8
class Admin::ImagesController < AdminController

def index
@images = Image.blocked(100)
end
end
6 changes: 4 additions & 2 deletions app/controllers/moderation/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ def index
end

def destroy
Board.amr_notification("Une image #{moderation_images_url} a été bloquée par #{current_user.name} #{user_url(current_user)}")
Image.destroy params[:id] unless params[:id].blank?
unless params[:id].blank?
Board.amr_notification("Une image récente de #{moderation_images_url} a été bloquée par #{current_user.name} #{user_url(current_user)}")
Image.destroy params[:id]
end
redirect_to moderation_images_url
end
end
15 changes: 12 additions & 3 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@
# When a user use an image from an external domain on LinuxFr.org, we keep some
# infos about this image in redis, so it can served by our proxy/cache daemon, img.
#
class Image < Struct.new(:link, :title, :alt_text)
class Image < Struct.new(:link, :title, :alt_text, :blocked)
LATEST_KEY = "img/latest"
NB_IMG_IN_LATEST = 100
BLOCKED_KEY = "img/blocked"
E403 = "/images/403.png"

def self.latest(nb=NB_IMG_IN_LATEST)
links = $redis.lrange LATEST_KEY, 0, nb
links.map {|l| Image.new(l, l, l) }
links.map {|l| Image.new(l, l, l, ($redis.hget "img/#{l}", "status") == "Blocked") }
end

def self.blocked(nb)
links = $redis.lrange BLOCKED_KEY, 0, nb
links.map {|l| Image.new(l, l, l, ($redis.hget "img/#{l}", "status") == "Blocked") }
end

def self.decoded_link(encoded_link)
[encoded_link].pack('H*')
end

def self.destroy(encoded_link)
$redis.hset "img/#{decoded_link encoded_link}", "status", "Blocked"
link = decoded_link(encoded_link)
if $redis.hset "img/#{link}", "status", "Blocked"
$redis.lpush BLOCKED_KEY, link
end
end

def self.original_link(link)
Expand Down
13 changes: 13 additions & 0 deletions app/views/admin/images/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# encoding: utf-8
%h1 Images externes bloquées

- if @images.any?
%p Liste des images externes bloquées :
- else
%p Aucune image externe bloquée actuellement

%ul
- @images.each do |image|
%li
%pre
= "#{image.link.html_safe} #{'⚠ image non bloquée' unless image.blocked}"
15 changes: 8 additions & 7 deletions app/views/admin/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
=h1 "Administration"
%ul
%li= link_to "Applications de l’API", admin_applications_path
%li= link_to "Bannières", admin_banners_path
%li= link_to "Débogage", "/admin/debug"
%li= link_to "Derniers comptes", admin_accounts_path
%li= link_to "Réponses de refus (pour les dépêches)", admin_responses_path
%li= link_to "Sections (pour les dépêches)", admin_sections_path
%li= link_to "Forums", admin_forums_path
%li= link_to "Catégories (pour le suivi)", admin_categories_path
%li= link_to "Bannières", admin_banners_path
%li= link_to "Logo", admin_logo_path
%li= link_to "Feuilles de style", admin_stylesheet_path
%li= link_to "Forums", admin_forums_path
%li= link_to "Images", admin_images_path
%li= link_to "Logo", admin_logo_path
%li= link_to "Réponses de refus (pour les dépêches)", admin_responses_path
%li= link_to "Sections (pour les dépêches)", admin_sections_path
%li= link_to "Sites amis", admin_friend_sites_path
%li= link_to "Pages statiques", admin_pages_path
%li= link_to "Applications de l’API", admin_applications_path
%li= link_to "Débogage", "/admin/debug"
17 changes: 13 additions & 4 deletions app/views/moderation/images/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
%h1 Images externes les plus récentes

- @images.each do |image|
.image
= image.to_html.html_safe
= button_to "Bloquer", moderation_image_path(image.encoded_link), method: :delete, data: { confirm: "Confirmez‑vous vouloir bloquer cette image ?" }
- if @images.any?
%p Images externes les plus récentes
%ul
- @images.each do |image|
%li.image
- if image.blocked
%pre #{image.link.html_safe}
= "⛔ Bloquée"
- else
= image.to_html.html_safe
= button_to "Bloquer", moderation_image_path(image.encoded_link), method: :delete, data: { confirm: "Confirmez‑vous vouloir bloquer cette image ?" }
- else
%p Aucune image externe actuellement
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
end
resources :pages, except: [:show]
resources :applications, except: [:new, :create]
resources :images, except: [:show]
end

# Search
Expand Down
1 change: 1 addition & 0 deletions db/redis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Key | Type | Value
`convert/<news_id>` | string | `<diary_id>` | no | Conversions from diary to news
`dashboard/<account_id>` | set | `<node_id>` | 1 week | Notifications from answers
`img/<uri>` | hash | | no | Images, with fields 'created_at': seconds since Epoch, 'status': 'Blocked' if administratively blocked (by moderation), 'type': content-type like 'image/jpeg' (set by `img` daemon), 'checksum': SHA1 (set by `img` daemon), and 'etag': etag (set by `img` daemon)
`img/blocked` | list | URIs | no | Images blocked by moderation team
`img/err/<uri>` | string | error | no | Images in error, like "Invalid content-type", created by `img` daemon but removed by `dlfp`
`img/latest` | list | URIs | no, limited| Last images, limited to NB_IMG_IN_LATEST = 100
`img/updated/<uri>` | string | modtime | 1h | Cached images, created by `img` daemon, value like "Thu, 12 Dec 2013 12:28:47 GMT"
Expand Down

0 comments on commit 82d265e

Please sign in to comment.