##// END OF EJS Templates
Resourcified documents....
Jean-Philippe Lang -
r7890:c3c2a4afe008
parent child
Show More
@@ -18,9 +18,9
18 18 class DocumentsController < ApplicationController
19 19 default_search_scope :documents
20 20 model_object Document
21 before_filter :find_project_by_project_id, :only => [:index, :new]
22 before_filter :find_model_object, :except => [:index, :new]
23 before_filter :find_project_from_association, :except => [:index, :new]
21 before_filter :find_project_by_project_id, :only => [:index, :new, :create]
22 before_filter :find_model_object, :except => [:index, :new, :create]
23 before_filter :find_project_from_association, :except => [:index, :new, :create]
24 24 before_filter :authorize
25 25
26 26 helper :attachments
@@ -48,24 +48,34 class DocumentsController < ApplicationController
48 48
49 49 def new
50 50 @document = @project.documents.build(params[:document])
51 end
52
53 def create
54 @document = @project.documents.build(params[:document])
51 55 if request.post? and @document.save
52 56 attachments = Attachment.attach_files(@document, params[:attachments])
53 57 render_attachment_warning_if_needed(@document)
54 58 flash[:notice] = l(:notice_successful_create)
55 59 redirect_to :action => 'index', :project_id => @project
60 else
61 render :action => 'new'
56 62 end
57 63 end
58 64
59 65 def edit
60 @categories = DocumentCategory.active #TODO: use it in the views
61 if request.post? and @document.update_attributes(params[:document])
66 end
67
68 def update
69 if request.put? and @document.update_attributes(params[:document])
62 70 flash[:notice] = l(:notice_successful_update)
63 71 redirect_to :action => 'show', :id => @document
72 else
73 render :action => 'edit'
64 74 end
65 75 end
66 76
67 77 def destroy
68 @document.destroy
78 @document.destroy if request.delete?
69 79 redirect_to :controller => 'documents', :action => 'index', :project_id => @project
70 80 end
71 81
@@ -1,4 +1,4
1 <h4><%= link_to h(document.title), :controller => 'documents', :action => 'show', :id => document %></h4>
1 <h4><%= link_to h(document.title), document_path(document) %></h4>
2 2 <p><em><%= format_time(document.updated_on) %></em></p>
3 3
4 4 <div class="wiki">
@@ -1,15 +1,15
1 <%= error_messages_for 'document' %>
2 <div class="box">
3 <!--[form:document]-->
4 <p><label for="document_category_id"><%=l(:field_category)%></label>
5 <%= select('document', 'category_id', DocumentCategory.active.collect {|c| [c.name, c.id]}) %></p>
1 <%= f.error_messages %>
6 2
7 <p><label for="document_title"><%=l(:field_title)%> <span class="required">*</span></label>
8 <%= text_field 'document', 'title', :size => 60 %></p>
9
10 <p><label for="document_description"><%=l(:field_description)%></label>
11 <%= text_area 'document', 'description', :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
12 <!--[eoform:document]-->
3 <div class="box tabular">
4 <p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %></p>
5 <p><%= f.text_field :title, :required => true, :size => 60 %></p>
6 <p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
13 7 </div>
14 8
15 9 <%= wikitoolbar_for 'document_description' %>
10
11 <% if @document.new_record? %>
12 <div class="box tabular">
13 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
14 </div>
15 <% end %>
@@ -1,8 +1,8
1 1 <h2><%=l(:label_document)%></h2>
2 2
3 <% form_tag({:action => 'edit', :id => @document}, :class => "tabular") do %>
4 <%= render :partial => 'form' %>
5 <%= submit_tag l(:button_save) %>
3 <% labelled_form_for @document do |f| %>
4 <%= render :partial => 'form', :locals => {:f => f} %>
5 <p><%= submit_tag l(:button_save) %></p>
6 6 <% end %>
7 7
8 8
@@ -1,19 +1,16
1 1 <div class="contextual">
2 <%= link_to_if_authorized l(:label_document_new),
3 {:controller => 'documents', :action => 'new', :project_id => @project},
4 :class => 'icon icon-add',
5 :onclick => 'Element.show("add-document"); Form.Element.focus("document_title"); return false;' %>
2 <%= link_to l(:label_document_new), new_project_document_path(@project), :class => 'icon icon-add',
3 :onclick => 'Element.show("add-document"); Form.Element.focus("document_title"); return false;' if User.current.allowed_to?(:manage_documents, @project) %>
6 4 </div>
7 5
8 6 <div id="add-document" style="display:none;">
9 7 <h2><%=l(:label_document_new)%></h2>
10 <% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %>
11 <%= render :partial => 'documents/form' %>
12 <div class="box">
13 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
14 </div>
8 <% labelled_form_for @document, :url => project_documents_path(@project), :html => {:multipart => true} do |f| %>
9 <%= render :partial => 'form', :locals => {:f => f} %>
10 <p>
15 11 <%= submit_tag l(:button_create) %>
16 12 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-document")' %>
13 </p>
17 14 <% end %>
18 15 </div>
19 16
@@ -1,13 +1,6
1 1 <h2><%=l(:label_document_new)%></h2>
2 2
3 <% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %>
4 <%= render :partial => 'documents/form' %>
5
6 <div class="box">
7 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
8 </div>
9
10 <%= submit_tag l(:button_create) %>
3 <% labelled_form_for @document, :url => project_documents_path(@project), :html => {:multipart => true} do |f| %>
4 <%= render :partial => 'form', :locals => {:f => f} %>
5 <p><%= submit_tag l(:button_create) %></p>
11 6 <% end %>
12
13
@@ -1,6 +1,8
1 1 <div class="contextual">
2 <%= link_to_if_authorized l(:button_edit), {:controller => 'documents', :action => 'edit', :id => @document}, :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
3 <%= 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' %>
2 <% if User.current.allowed_to?(:manage_documents, @project) %>
3 <%= link_to l(:button_edit), edit_document_path(@document), :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
4 <%= link_to l(:button_delete), document_path(@document), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %>
5 <% end %>
4 6 </div>
5 7
6 8 <h2><%=h @document.title %></h2>
@@ -63,19 +63,6 ActionController::Routing::Routes.draw do |map|
63 63 end
64 64 end
65 65
66 map.with_options :controller => 'documents' do |document_routes|
67 document_routes.with_options :conditions => {:method => :get} do |document_views|
68 document_views.connect 'projects/:project_id/documents', :action => 'index'
69 document_views.connect 'projects/:project_id/documents/new', :action => 'new'
70 document_views.connect 'documents/:id', :action => 'show'
71 document_views.connect 'documents/:id/edit', :action => 'edit'
72 end
73 document_routes.with_options :conditions => {:method => :post} do |document_actions|
74 document_actions.connect 'projects/:project_id/documents', :action => 'new'
75 document_actions.connect 'documents/:id/:action', :action => /destroy|edit/
76 end
77 end
78
79 66 map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
80 67 map.resources :queries, :except => [:show]
81 68
@@ -158,6 +145,7 ActionController::Routing::Routes.draw do |map|
158 145 project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id'
159 146 project.resources :queries, :only => [:new, :create]
160 147 project.resources :issue_categories, :shallow => true
148 project.resources :documents, :shallow => true, :member => {:add_attachment => :post}
161 149
162 150 project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get}
163 151 project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get}
@@ -230,7 +218,6 ActionController::Routing::Routes.draw do |map|
230 218
231 219 #left old routes at the bottom for backwards compat
232 220 map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
233 map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
234 221 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
235 222 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
236 223 map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki'
@@ -102,7 +102,7 Redmine::AccessControl.map do |map|
102 102 end
103 103
104 104 map.project_module :documents do |map|
105 map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin
105 map.permission :manage_documents, {:documents => [:new, :create, :edit, :update, :destroy, :add_attachment]}, :require => :loggedin
106 106 map.permission :view_documents, :documents => [:index, :show, :download]
107 107 end
108 108
@@ -86,13 +86,20 LOREM
86 86 assert_template 'show'
87 87 end
88 88
89 def test_new_with_one_attachment
89 def test_new
90 @request.session[:user_id] = 2
91 get :new, :project_id => 1
92 assert_response :success
93 assert_template 'new'
94 end
95
96 def test_create_with_one_attachment
90 97 ActionMailer::Base.deliveries.clear
91 98 Setting.notified_events << 'document_added'
92 99 @request.session[:user_id] = 2
93 100 set_tmp_attachments_directory
94 101
95 post :new, :project_id => 'ecookbook',
102 post :create, :project_id => 'ecookbook',
96 103 :document => { :title => 'DocumentsControllerTest#test_post_new',
97 104 :description => 'This is a new document',
98 105 :category_id => 2},
@@ -117,7 +124,7 LOREM
117 124
118 125 def test_update
119 126 @request.session[:user_id] = 2
120 post :edit, :id => 1, :document => {:title => 'test_update'}
127 put :update, :id => 1, :document => {:title => 'test_update'}
121 128 assert_redirected_to '/documents/1'
122 129 document = Document.find(1)
123 130 assert_equal 'test_update', document.title
@@ -126,7 +133,7 LOREM
126 133 def test_destroy
127 134 @request.session[:user_id] = 2
128 135 assert_difference 'Document.count', -1 do
129 post :destroy, :id => 1
136 delete :destroy, :id => 1
130 137 end
131 138 assert_redirected_to '/projects/ecookbook/documents'
132 139 assert_nil Document.find_by_id(1)
General Comments 0
You need to be logged in to leave comments. Login now