X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/db39876dd6f0bccb36e4cdde0e1a0da81a05fcfe..16fef14b61f4cf5222484b7c315ed05c661cbcef:/app/controllers/traces_controller.rb diff --git a/app/controllers/traces_controller.rb b/app/controllers/traces_controller.rb index ab4c8f3b8..b6982894d 100644 --- a/app/controllers/traces_controller.rb +++ b/app/controllers/traces_controller.rb @@ -12,7 +12,7 @@ class TracesController < ApplicationController before_action :check_api_writable, :only => [:api_create, :api_update, :api_delete] before_action :require_allow_read_gpx, :only => [:api_read, :api_data] before_action :require_allow_write_gpx, :only => [:api_create, :api_update, :api_delete] - before_action :offline_warning, :only => [:mine, :view] + before_action :offline_warning, :only => [:mine, :show] before_action :offline_redirect, :only => [:new, :create, :edit, :delete, :data, :api_create, :api_delete, :api_data] around_action :api_call_handle_error, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data] @@ -89,7 +89,7 @@ class TracesController < ApplicationController redirect_to :action => :list, :display_name => current_user.display_name end - def view + def show @trace = Trace.find(params[:id]) if @trace && @trace.visible? && @@ -175,13 +175,24 @@ class TracesController < ApplicationController head :forbidden else @title = t ".title", :name => @trace.name + end + rescue ActiveRecord::RecordNotFound + head :not_found + end - if request.post? && params[:trace] - @trace.description = params[:trace][:description] - @trace.tagstring = params[:trace][:tagstring] - @trace.visibility = params[:trace][:visibility] - redirect_to :action => "view", :display_name => current_user.display_name if @trace.save - end + def update + @trace = Trace.find(params[:id]) + + if !@trace.visible? + head :not_found + elsif current_user.nil? || @trace.user != current_user + head :forbidden + elsif @trace.update(trace_params) + flash[:notice] = t ".updated" + redirect_to :action => "show", :display_name => current_user.display_name + else + @title = t ".title", :name => @trace.name + render :action => "edit" end rescue ActiveRecord::RecordNotFound head :not_found @@ -413,4 +424,8 @@ class TracesController < ApplicationController "public" end end + + def trace_params + params.require(:trace).permit(:description, :tagstring, :visibility) + end end