From 113449eacba67625004b14081f4cc0cc3b984553 Mon Sep 17 00:00:00 2001 From: hukl Date: Mon, 2 Mar 2009 17:22:48 +0100 Subject: added unlock functionality. not yet hooked up with permissions though. anybody can unlock. put a confirmation in front of it. destroy has to be confirmed as well --- app/controllers/nodes_controller.rb | 17 ++++++++++++++++- app/views/nodes/index.html.erb | 3 ++- config/routes.rb | 2 +- public/stylesheets/admin.css | 10 +++++++--- test/fixtures/nodes.yml | 13 +++++++++++-- test/fixtures/pages.yml | 7 ++++++- test/functional/nodes_controller_test.rb | 22 ++++++++++++++++++++++ 7 files changed, 65 insertions(+), 9 deletions(-) diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index a403b95..81ead62 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb @@ -7,7 +7,8 @@ class NodesController < ApplicationController :edit, :update, :destroy, - :publish + :publish, + :unlock ] def index @@ -67,6 +68,20 @@ class NodesController < ApplicationController redirect_to node_path end + def unlock + # TODO that actually has to be implemented in the model, once we have + # permissions + if draft = @node.draft + draft.user = nil + draft.save + flash[:notice] = "Node unlocked" + else + flash[:notice] = "Cannot unlock" + end + + redirect_to nodes_path + end + def move_to parent = Node.find params[:parent_id] @node.move_to_child_of parent diff --git a/app/views/nodes/index.html.erb b/app/views/nodes/index.html.erb index 1429d1a..833ffed 100644 --- a/app/views/nodes/index.html.erb +++ b/app/views/nodes/index.html.erb @@ -23,7 +23,8 @@ <%= link_to 'Show', node_path(node) %> <%= link_to 'Edit', edit_node_path(node) %> - <%= link_to 'Destroy', node, :method => :delete %> + <%= link_to 'Destroy', node, :method => :delete, :confirm => "Are you sure you want to delete this node?" %> + <%= link_to 'Unlock', unlock_node_path(node), :method => :put, :confirm => "Are you sure you want to unlock?" %> <%= "#{node.draft.user.login}" if node.draft && node.draft.user %> diff --git a/config/routes.rb b/config/routes.rb index 5f2a9dc..4305a21 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,7 @@ ActionController::Routing::Routes.draw do |map| map.filter :locale map.resources :pages - map.resources :nodes, :member => {:publish => :put} + map.resources :nodes, :member => {:publish => :put, :unlock => :put} map.logout '/logout', :controller => 'sessions', :action => 'destroy' map.login '/login', :controller => 'sessions', :action => 'new' diff --git a/public/stylesheets/admin.css b/public/stylesheets/admin.css index 0b7e630..5fe88f1 100644 --- a/public/stylesheets/admin.css +++ b/public/stylesheets/admin.css @@ -10,7 +10,7 @@ a { table {} table#node_table { - width: 800px; + width: 1000px; } tr.odd { @@ -22,7 +22,7 @@ th { } th.title { - width: 450px; + width: 400px; } th.path { @@ -30,7 +30,11 @@ th.path { } th.actions { - width: 150px; + width: 180px; +} + +th.editor { + width: 120px; } td { diff --git a/test/fixtures/nodes.yml b/test/fixtures/nodes.yml index 8574c1b..a0e185b 100644 --- a/test/fixtures/nodes.yml +++ b/test/fixtures/nodes.yml @@ -3,7 +3,7 @@ root: id: 1 lft: 1 - rgt: 8 + rgt: 10 parent_id: slug: unique_name: @@ -34,4 +34,13 @@ third_child: parent_id: 1 draft_id: 102 slug: third_child - unique_name: third_child \ No newline at end of file + unique_name: third_child + +fourth_child: + id: 5 + lft: 8 + rgt: 9 + parent_id: 1 + draft_id: 103 + slug: fourth_child + unique_name: fourth_child \ No newline at end of file diff --git a/test/fixtures/pages.yml b/test/fixtures/pages.yml index 8171b38..271c494 100644 --- a/test/fixtures/pages.yml +++ b/test/fixtures/pages.yml @@ -23,4 +23,9 @@ draft2: draft3: id: 102 revision: 1 - node_id: 4 \ No newline at end of file + node_id: 4 + +draft4: + id: 103 + revision: 1 + node_id: 5 \ No newline at end of file diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb index ed8afd8..afe7576 100644 --- a/test/functional/nodes_controller_test.rb +++ b/test/functional/nodes_controller_test.rb @@ -22,6 +22,28 @@ class NodesControllerTest < ActionController::TestCase assert_redirected_to node_path(Node.last) end + def test_editing_a_node + login_as :quentin + + node = Node.find_by_unique_name("fourth_child") + + assert_equal 1, node.pages.length + + draft = node.find_or_create_draft( User.first ) + draft.title = "Hello" + draft.body = "World" + draft.save + node.publish_draft! + + get :edit, :id => node.id + assert_response :success + + node.reload + assert_equal 2, node.pages.length + assert_equal "Hello", node.find_or_create_draft( User.first ).title + assert_equal "World", node.find_or_create_draft( User.first ).body + end + def test_update_a_draft test_node = Node.create! :slug => "test_node" test_node.move_to_child_of Node.root -- cgit v1.3