diff --git a/app/controllers/admin/images_controller.rb b/app/controllers/admin/images_controller.rb new file mode 100644 index 000000000..db5ce0ec6 --- /dev/null +++ b/app/controllers/admin/images_controller.rb @@ -0,0 +1,7 @@ +# encoding: UTF-8 +class Admin::ImagesController < AdminController + + def index + @images = Image.blocked(100) + end +end diff --git a/app/controllers/moderation/images_controller.rb b/app/controllers/moderation/images_controller.rb index 195e5ded7..c2e79f9cb 100644 --- a/app/controllers/moderation/images_controller.rb +++ b/app/controllers/moderation/images_controller.rb @@ -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 diff --git a/app/models/image.rb b/app/models/image.rb index 626218e67..0da45e59c 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -4,14 +4,20 @@ # 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) @@ -19,7 +25,10 @@ def self.decoded_link(encoded_link) 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) diff --git a/app/views/admin/images/index.html.haml b/app/views/admin/images/index.html.haml new file mode 100644 index 000000000..4264dfb49 --- /dev/null +++ b/app/views/admin/images/index.html.haml @@ -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}" diff --git a/app/views/admin/index.html.haml b/app/views/admin/index.html.haml index 420d907d0..82ebab473 100644 --- a/app/views/admin/index.html.haml +++ b/app/views/admin/index.html.haml @@ -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" diff --git a/app/views/moderation/images/index.html.haml b/app/views/moderation/images/index.html.haml index 4be6ecb3a..f80e48ea2 100644 --- a/app/views/moderation/images/index.html.haml +++ b/app/views/moderation/images/index.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 0f1dc60b4..16fa9591e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -209,6 +209,7 @@ end resources :pages, except: [:show] resources :applications, except: [:new, :create] + resources :images, except: [:show] end # Search diff --git a/db/redis.txt b/db/redis.txt index 0154f9923..8ad48477d 100644 --- a/db/redis.txt +++ b/db/redis.txt @@ -11,6 +11,7 @@ Key | Type | Value `convert/` | string | `` | no | Conversions from diary to news `dashboard/` | set | `` | 1 week | Notifications from answers `img/` | 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/` | 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/` | string | modtime | 1h | Cached images, created by `img` daemon, value like "Thu, 12 Dec 2013 12:28:47 GMT"