Use imported scope to simplify trace controller methods
This commit is contained in:
parent
50df5eefcc
commit
91143a5959
3 changed files with 15 additions and 22 deletions
|
@ -6,9 +6,8 @@ module Traces
|
||||||
authorize_resource :trace
|
authorize_resource :trace
|
||||||
|
|
||||||
def show
|
def show
|
||||||
trace = Trace.visible.find(params[:trace_id])
|
trace = Trace.visible.imported.find(params[:trace_id])
|
||||||
|
|
||||||
if trace.inserted?
|
|
||||||
if trace.public? || (current_user && current_user == trace.user)
|
if trace.public? || (current_user && current_user == trace.user)
|
||||||
if trace.icon.attached?
|
if trace.icon.attached?
|
||||||
redirect_to rails_blob_path(trace.icon, :disposition => "inline")
|
redirect_to rails_blob_path(trace.icon, :disposition => "inline")
|
||||||
|
@ -19,9 +18,6 @@ module Traces
|
||||||
else
|
else
|
||||||
head :forbidden
|
head :forbidden
|
||||||
end
|
end
|
||||||
else
|
|
||||||
head :not_found
|
|
||||||
end
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
head :not_found
|
head :not_found
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,9 +6,8 @@ module Traces
|
||||||
authorize_resource :trace
|
authorize_resource :trace
|
||||||
|
|
||||||
def show
|
def show
|
||||||
trace = Trace.visible.find(params[:trace_id])
|
trace = Trace.visible.imported.find(params[:trace_id])
|
||||||
|
|
||||||
if trace.inserted?
|
|
||||||
if trace.public? || (current_user && current_user == trace.user)
|
if trace.public? || (current_user && current_user == trace.user)
|
||||||
if trace.icon.attached?
|
if trace.icon.attached?
|
||||||
redirect_to rails_blob_path(trace.image, :disposition => "inline")
|
redirect_to rails_blob_path(trace.image, :disposition => "inline")
|
||||||
|
@ -19,9 +18,6 @@ module Traces
|
||||||
else
|
else
|
||||||
head :forbidden
|
head :forbidden
|
||||||
end
|
end
|
||||||
else
|
|
||||||
head :not_found
|
|
||||||
end
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
head :not_found
|
head :not_found
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,7 @@ class Trace < ApplicationRecord
|
||||||
scope :visible_to, ->(u) { visible.where(:visibility => %w[public identifiable]).or(visible.where(:user => u)) }
|
scope :visible_to, ->(u) { visible.where(:visibility => %w[public identifiable]).or(visible.where(:user => u)) }
|
||||||
scope :visible_to_all, -> { where(:visibility => %w[public identifiable]) }
|
scope :visible_to_all, -> { where(:visibility => %w[public identifiable]) }
|
||||||
scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) }
|
scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) }
|
||||||
|
scope :imported, -> { where(:inserted => true) }
|
||||||
|
|
||||||
has_one_attached :file, :service => Settings.trace_file_storage
|
has_one_attached :file, :service => Settings.trace_file_storage
|
||||||
has_one_attached :image, :service => Settings.trace_image_storage
|
has_one_attached :image, :service => Settings.trace_image_storage
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue