diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb
index 3e805c1..600bf66 100644
--- a/app/views/documents/_form.html.erb
+++ b/app/views/documents/_form.html.erb
@@ -1,15 +1,15 @@
-<%= error_messages_for 'document' %>
-
-
-
-<%= select('document', 'category_id', DocumentCategory.active.collect {|c| [c.name, c.id]}) %>
+<%= f.error_messages %>
-
-<%= text_field 'document', 'title', :size => 60 %>
-
-
-<%= text_area 'document', 'description', :cols => 60, :rows => 15, :class => 'wiki-edit' %>
-
+
+
<%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %>
+
<%= f.text_field :title, :required => true, :size => 60 %>
+
<%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %>
<%= wikitoolbar_for 'document_description' %>
+
+<% if @document.new_record? %>
+
+
<%= render :partial => 'attachments/form' %>
+
+<% end %>
diff --git a/app/views/documents/edit.html.erb b/app/views/documents/edit.html.erb
index 0b9f31f..04e9b72 100644
--- a/app/views/documents/edit.html.erb
+++ b/app/views/documents/edit.html.erb
@@ -1,8 +1,8 @@
<%=l(:label_document)%>
-<% form_tag({:action => 'edit', :id => @document}, :class => "tabular") do %>
- <%= render :partial => 'form' %>
- <%= submit_tag l(:button_save) %>
+<% labelled_form_for @document do |f| %>
+ <%= render :partial => 'form', :locals => {:f => f} %>
+
<%= submit_tag l(:button_save) %>
<% end %>
diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb
index 7449b67..31f5d2e 100644
--- a/app/views/documents/index.html.erb
+++ b/app/views/documents/index.html.erb
@@ -1,19 +1,16 @@
-<%= link_to_if_authorized l(:label_document_new),
- {:controller => 'documents', :action => 'new', :project_id => @project},
- :class => 'icon icon-add',
- :onclick => 'Element.show("add-document"); Form.Element.focus("document_title"); return false;' %>
+<%= link_to l(:label_document_new), new_project_document_path(@project), :class => 'icon icon-add',
+ :onclick => 'Element.show("add-document"); Form.Element.focus("document_title"); return false;' if User.current.allowed_to?(:manage_documents, @project) %>
<%=l(:label_document_new)%>
-<% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %>
-<%= render :partial => 'documents/form' %>
-
-
<%= render :partial => 'attachments/form' %>
-
-<%= submit_tag l(:button_create) %>
-<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-document")' %>
+<% labelled_form_for @document, :url => project_documents_path(@project), :html => {:multipart => true} do |f| %>
+<%= render :partial => 'form', :locals => {:f => f} %>
+
+ <%= submit_tag l(:button_create) %>
+ <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-document")' %>
+
<% end %>
diff --git a/app/views/documents/new.html.erb b/app/views/documents/new.html.erb
index 639b4f2..772093e 100644
--- a/app/views/documents/new.html.erb
+++ b/app/views/documents/new.html.erb
@@ -1,13 +1,6 @@
<%=l(:label_document_new)%>
-<% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %>
-<%= render :partial => 'documents/form' %>
-
-
-
<%= render :partial => 'attachments/form' %>
-
-
-<%= submit_tag l(:button_create) %>
+<% labelled_form_for @document, :url => project_documents_path(@project), :html => {:multipart => true} do |f| %>
+ <%= render :partial => 'form', :locals => {:f => f} %>
+
<%= submit_tag l(:button_create) %>
<% end %>
-
-
diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb
index 7585435..fded300 100644
--- a/app/views/documents/show.html.erb
+++ b/app/views/documents/show.html.erb
@@ -1,6 +1,8 @@
-<%= link_to_if_authorized l(:button_edit), {:controller => 'documents', :action => 'edit', :id => @document}, :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
-<%= link_to_if_authorized l(:button_delete), {:controller => 'documents', :action => 'destroy', :id => @document}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
+<% if User.current.allowed_to?(:manage_documents, @project) %>
+<%= link_to l(:button_edit), edit_document_path(@document), :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
+<%= link_to l(:button_delete), document_path(@document), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %>
+<% end %>
<%=h @document.title %>
diff --git a/config/routes.rb b/config/routes.rb
index 833f238..3ce5efd 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -63,19 +63,6 @@ ActionController::Routing::Routes.draw do |map|
end
end
- map.with_options :controller => 'documents' do |document_routes|
- document_routes.with_options :conditions => {:method => :get} do |document_views|
- document_views.connect 'projects/:project_id/documents', :action => 'index'
- document_views.connect 'projects/:project_id/documents/new', :action => 'new'
- document_views.connect 'documents/:id', :action => 'show'
- document_views.connect 'documents/:id/edit', :action => 'edit'
- end
- document_routes.with_options :conditions => {:method => :post} do |document_actions|
- document_actions.connect 'projects/:project_id/documents', :action => 'new'
- document_actions.connect 'documents/:id/:action', :action => /destroy|edit/
- end
- end
-
map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
map.resources :queries, :except => [:show]
@@ -158,6 +145,7 @@ ActionController::Routing::Routes.draw do |map|
project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id'
project.resources :queries, :only => [:new, :create]
project.resources :issue_categories, :shallow => true
+ project.resources :documents, :shallow => true, :member => {:add_attachment => :post}
project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get}
project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get}
@@ -230,7 +218,6 @@ ActionController::Routing::Routes.draw do |map|
#left old routes at the bottom for backwards compat
map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
- map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki'
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 252c1ca..6028599 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -102,7 +102,7 @@ Redmine::AccessControl.map do |map|
end
map.project_module :documents do |map|
- map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin
+ map.permission :manage_documents, {:documents => [:new, :create, :edit, :update, :destroy, :add_attachment]}, :require => :loggedin
map.permission :view_documents, :documents => [:index, :show, :download]
end
diff --git a/test/functional/documents_controller_test.rb b/test/functional/documents_controller_test.rb
index ad7260c..3b4424e 100644
--- a/test/functional/documents_controller_test.rb
+++ b/test/functional/documents_controller_test.rb
@@ -86,13 +86,20 @@ LOREM
assert_template 'show'
end
- def test_new_with_one_attachment
+ def test_new
+ @request.session[:user_id] = 2
+ get :new, :project_id => 1
+ assert_response :success
+ assert_template 'new'
+ end
+
+ def test_create_with_one_attachment
ActionMailer::Base.deliveries.clear
Setting.notified_events << 'document_added'
@request.session[:user_id] = 2
set_tmp_attachments_directory
- post :new, :project_id => 'ecookbook',
+ post :create, :project_id => 'ecookbook',
:document => { :title => 'DocumentsControllerTest#test_post_new',
:description => 'This is a new document',
:category_id => 2},
@@ -117,7 +124,7 @@ LOREM
def test_update
@request.session[:user_id] = 2
- post :edit, :id => 1, :document => {:title => 'test_update'}
+ put :update, :id => 1, :document => {:title => 'test_update'}
assert_redirected_to '/documents/1'
document = Document.find(1)
assert_equal 'test_update', document.title
@@ -126,7 +133,7 @@ LOREM
def test_destroy
@request.session[:user_id] = 2
assert_difference 'Document.count', -1 do
- post :destroy, :id => 1
+ delete :destroy, :id => 1
end
assert_redirected_to '/projects/ecookbook/documents'
assert_nil Document.find_by_id(1)