From 5e4f0f9fe8bd33a585be54030462abfa716eda72 Mon Sep 17 00:00:00 2001 From: bsag Date: Mon, 10 Oct 2005 21:14:34 +0000 Subject: [PATCH] Improved the security of the new drag and drop features of the projects and contexts lists by checking that the logged in user owns those items. Also changed references to Form.focus_first which were defined in the removed file prototype-ex.js to Form.focusFirstElement, which is defined in prototype.js. Fixes #133. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@149 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/context_controller.rb | 18 +++++++++++++++--- tracks/app/controllers/project_controller.rb | 17 +++++++++++++++-- .../app/views/context/_context_listing.rhtml | 4 +--- tracks/app/views/context/list.rhtml | 4 ++-- .../app/views/project/_project_listing.rhtml | 4 +--- tracks/app/views/project/list.rhtml | 4 ++-- tracks/public/stylesheets/standard.css | 11 ++--------- 7 files changed, 38 insertions(+), 24 deletions(-) diff --git a/tracks/app/controllers/context_controller.rb b/tracks/app/controllers/context_controller.rb index 8956919e..9d85ce69 100644 --- a/tracks/app/controllers/context_controller.rb +++ b/tracks/app/controllers/context_controller.rb @@ -76,9 +76,10 @@ class ContextController < ApplicationController # def order @params["list-contexts"].each_with_index do |id, position| - Context.update(id, :position => position + 1) + if check_user_matches_context_user(id) + Context.update(id, :position => position + 1) + end end - render_text "" end protected @@ -101,7 +102,18 @@ class ContextController < ApplicationController end end - + def check_user_matches_context_user(id) + @user = @session['user'] + @context = Context.find_by_id_and_user_id(id, @user.id) + if @user == @context.user + return @context + else + @context = nil + flash["warning"] = "Project and session user mis-match: #{@context.user_id} and #{@session['user'].id}!" + render_text "" + end + end + def init @user = @session['user'] @projects = @user.projects.collect { |x| x.done? ? nil:x }.compact diff --git a/tracks/app/controllers/project_controller.rb b/tracks/app/controllers/project_controller.rb index 8e5f9174..8294f193 100644 --- a/tracks/app/controllers/project_controller.rb +++ b/tracks/app/controllers/project_controller.rb @@ -73,9 +73,10 @@ class ProjectController < ApplicationController # def order @params["list-projects"].each_with_index do |id, position| - Project.update(id, :position => position + 1) + if check_user_matches_project_user(id) + Project.update(id, :position => position + 1) + end end - render_text "" end protected @@ -98,6 +99,18 @@ class ProjectController < ApplicationController end end + def check_user_matches_project_user(id) + @user = @session['user'] + @project = Project.find_by_id_and_user_id(id, @user.id) + if @user == @project.user + return @project + else + @project = nil + flash["warning"] = "Project and session user mis-match: #{@project.user_id} and #{@session['user'].id}!" + render_text "" + end + end + def init @user = @session['user'] @projects = @user.projects diff --git a/tracks/app/views/context/_context_listing.rhtml b/tracks/app/views/context/_context_listing.rhtml index 2ddcbeab..af17241b 100644 --- a/tracks/app/views/context/_context_listing.rhtml +++ b/tracks/app/views/context/_context_listing.rhtml @@ -1,7 +1,6 @@ <% context = context_listing %> -
+
-
DRAG @@ -27,7 +26,6 @@
-