]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/traces_controller.rb
Split out updating a trace into an update action
[rails.git] / app / controllers / traces_controller.rb
index ab4c8f3b80849408be5259afa1555d20784b8193..31ce88ec394268600720648dfe56fae4c73392a3 100644 (file)
@@ -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 => "view", :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