algunas recomendaciones de brakeman

This commit is contained in:
f 2020-08-05 12:29:11 -03:00
parent 96c2b8189a
commit b9215fee6d
5 changed files with 17 additions and 36 deletions

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
require 'filemagic'
# Define un campo de archivo
class MetadataFile < MetadataTemplate
# Una ruta vacía a la imagen con una descripción vacía
@ -68,10 +70,22 @@ class MetadataFile < MetadataTemplate
private
def filemagic
@filemagic ||= FileMagic.new(FileMagic::MAGIC_MIME)
end
def path
@path ||= Pathname.new value['path']
end
def file
if value['path'].is_a? ActionDispatch::Http::UploadedFile
value['path'].tempfile.path
else
value['path']
end
end
def key_from_path
path.dirname.basename.to_s
end
@ -84,10 +98,6 @@ class MetadataFile < MetadataTemplate
FileUtils.ln uploaded_path, destination_path
end
def extension
@extension ||= static_file.filename.to_s.split('.').last
end
# Obtener la ruta al archivo
# https://stackoverflow.com/a/53908358
def uploaded_relative_path

View file

@ -11,16 +11,8 @@ class MetadataImage < MetadataFile
errors.empty?
end
# Determina si es una imagen antes de subirla
# Determina si es una imagen
def image?
if value['path'].is_a? ActionDispatch::Http::UploadedFile
`file --mime-type "#{value['path'].tempfile.path}"`
.split(' ')
.last
.chomp
.starts_with? 'image/'
else
true
end
FileMagic.new(FileMagic::MAGIC_MIME).file(file).starts_with? 'image/'
end
end

View file

@ -13,9 +13,6 @@ class Usuarie < ApplicationRecord
has_many :roles
has_many :sites, through: :roles
before_create :register_in_lounge!,
if: proc { Rails.env.production? }
def name
email.split('@', 2).first
end
@ -40,15 +37,4 @@ class Usuarie < ApplicationRecord
increment_failed_attempts
lock_access! if attempts_exceeded? && !access_locked?
end
private
# XXX: Tenemos que hacer esto en línea porque necesitamos la
# contraseña y no la queremos dejar registrada por error en ningún
# lado
def register_in_lounge!
Thread.new do
open("https://chat.#{Site.domain}/#{ENV['LOUNGE']}/#{email}/#{password}")
end
end
end

View file

@ -17,11 +17,8 @@
%tr
%th.text-center{ colspan: 2 }= t('.front_matter')
%tbody
-#
TODO: Cambiar por un método que nos deje interactuar
directamente con los metadatos
- @post.attributes.each do |attr|
- metadata = @post.send(attr)
- metadata = @post[attr]
- next unless metadata.front_matter?
= render("posts/attribute_ro/#{metadata.type}",

View file

@ -6,10 +6,6 @@ Rails.application.routes.draw do
root 'application#index'
direct :mutual_aid do |channel|
"https://chat.#{Site.domain}/?channels=#{channel}"
end
get 'markdown', to: 'application#markdown'
constraints subdomain: 'api' do