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