1 # frozen_string_literal: true
4 # Bulk change of traces that still use a legacy visibility
5 class LegacyVisibilitiesController < ApplicationController
6 include PaginationMethods
10 before_action :authorize_web
11 before_action :set_locale
12 before_action :check_database_readable
14 authorize_resource :class => Trace
16 before_action :check_database_writable, :only => :update
17 before_action :offline_warning, :only => :edit
18 before_action :offline_redirect, :only => :update
22 @params = params.permit(:visibility, :from, :to, :before, :after)
24 traces = legacy_traces
26 @traces = get_page_items(traces, :includes => [:user, :tags])
30 visibility = params[:new_visibility]
32 if Trace::VISIBILITIES.include?(visibility)
33 # the traces are legacy and the new visibility is a current one, so no validation can fail
34 # rubocop:disable-next Rails/SkipsModelValidations
35 count = legacy_traces.update_all(:visibility => visibility)
36 flash[:notice] = t ".updated", :count => count
38 flash[:error] = t ".invalid_visibility"
41 redirect_to edit_traces_legacy_visibility_path(:visibility => params[:visibility],
42 :from => params[:from],
49 # the current user's legacy traces, with the optional filters applied
51 traces = current_user.traces.visible.where(:visibility => Trace::LEGACY_VISIBILITIES)
52 traces = traces.where(:visibility => params[:visibility]) if Trace::LEGACY_VISIBILITIES.include?(params[:visibility])
54 from = filter_date(params[:from])
55 to = filter_date(params[:to])
56 traces = traces.where(:timestamp => from..) if from
57 # timestamp is a datetime, so the upper bound is the start of the next day
58 traces = traces.where(:timestamp => ...(to + 1)) if to
63 def filter_date(value)
64 Date.parse(value) if value.present?
70 flash.now[:warning] = t "traces.offline_warning.message" if Settings.status == "gpx_offline"
74 render :template => "traces/offline" if Settings.status == "gpx_offline"