[LSS#4190] Add watching to documents
This commit is contained in:
parent
61a21f4990
commit
3af5544dbc
@ -43,20 +43,33 @@ class DocumentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@document = @project.documents.build(params[:document])
|
@document = @project.documents.build(params[:document])
|
||||||
if request.post? and @document.save
|
if request.post?
|
||||||
attachments = Attachment.attach_files(@document, params[:attachments])
|
if User.current.allowed_to?(:add_document_watchers, @project) && params[:document]['watcher_user_ids'].present?
|
||||||
render_attachment_warning_if_needed(@document)
|
@document.watcher_user_ids = params[:document]['watcher_user_ids']
|
||||||
flash[:notice] = l(:notice_successful_create)
|
end
|
||||||
redirect_to :action => 'index', :project_id => @project
|
|
||||||
|
if @document.save
|
||||||
|
attachments = Attachment.attach_files(@document, params[:attachments])
|
||||||
|
render_attachment_warning_if_needed(@document)
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
redirect_to :action => 'index', :project_id => @project
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@categories = DocumentCategory.all
|
@categories = DocumentCategory.all
|
||||||
if request.post? and @document.update_attributes(params[:document])
|
|
||||||
flash[:notice] = l(:notice_successful_update)
|
if request.post?
|
||||||
redirect_to :action => 'show', :id => @document
|
if User.current.allowed_to?(:add_document_watchers, @project) && params[:document]['watcher_user_ids'].present?
|
||||||
|
@document.watcher_user_ids = params[:document]['watcher_user_ids']
|
||||||
|
end
|
||||||
|
|
||||||
|
if @document.update_attributes(params[:document])
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to :action => 'show', :id => @document
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ class Document < ActiveRecord::Base
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
||||||
|
acts_as_watchable
|
||||||
|
|
||||||
validates_presence_of :project, :title, :category
|
validates_presence_of :project, :title, :category
|
||||||
validates_length_of :title, :maximum => 60
|
validates_length_of :title, :maximum => 60
|
||||||
@ -48,4 +49,10 @@ class Document < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
@updated_on
|
@updated_on
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def recipients
|
||||||
|
mails = super # from acts_as_event
|
||||||
|
mails += watcher_recipients
|
||||||
|
mails.uniq
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,6 +9,15 @@
|
|||||||
|
|
||||||
<p><label for="document_description"><%=l(:field_description)%></label>
|
<p><label for="document_description"><%=l(:field_description)%></label>
|
||||||
<%= text_area 'document', 'description', :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
|
<%= text_area 'document', 'description', :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
|
||||||
|
|
||||||
|
<% if User.current.allowed_to?(:add_document_watchers, @project) -%>
|
||||||
|
<p id="watchers_form"><label><%= l(:label_document_watchers) %></label>
|
||||||
|
<% @document.project.users.sort.each do |user| -%>
|
||||||
|
<label class="floating"><%= check_box_tag 'document[watcher_user_ids][]', user.id, @document.watched_by?(user) %> <%=h user %></label>
|
||||||
|
<% end -%>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<!--[eoform:document]-->
|
<!--[eoform:document]-->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -27,6 +27,16 @@
|
|||||||
|
|
||||||
<% html_title h(@document.title) -%>
|
<% html_title h(@document.title) -%>
|
||||||
|
|
||||||
|
<% content_for :sidebar do %>
|
||||||
|
<% if User.current.allowed_to?(:add_document_watchers, @project) ||
|
||||||
|
(@document.watchers.present? && User.current.allowed_to?(:view_document_watchers, @project)) %>
|
||||||
|
<div id="watchers">
|
||||||
|
<%= render :partial => 'watchers/watchers', :locals => {:watched => @document} %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% content_for :header_tags do %>
|
<% content_for :header_tags do %>
|
||||||
<%= stylesheet_link_tag 'scm' %>
|
<%= stylesheet_link_tag 'scm' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -774,6 +774,7 @@ en:
|
|||||||
label_incoming_emails: Incoming emails
|
label_incoming_emails: Incoming emails
|
||||||
label_generate_key: Generate a key
|
label_generate_key: Generate a key
|
||||||
label_issue_watchers: Watchers
|
label_issue_watchers: Watchers
|
||||||
|
label_document_watchers: Watchers
|
||||||
label_example: Example
|
label_example: Example
|
||||||
label_display: Display
|
label_display: Display
|
||||||
label_sort: Sort
|
label_sort: Sort
|
||||||
|
@ -116,6 +116,9 @@ Redmine::AccessControl.map do |map|
|
|||||||
map.project_module :documents do |map|
|
map.project_module :documents do |map|
|
||||||
map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin
|
map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin
|
||||||
map.permission :view_documents, :documents => [:index, :show, :download]
|
map.permission :view_documents, :documents => [:index, :show, :download]
|
||||||
|
map.permission :view_document_watchers, {}
|
||||||
|
map.permission :add_document_watchers, {:watchers => :new}
|
||||||
|
map.permission :delete_document_watchers, {:watchers => :destroy}
|
||||||
end
|
end
|
||||||
|
|
||||||
map.project_module :files do |map|
|
map.project_module :files do |map|
|
||||||
|
3
test/fixtures/roles.yml
vendored
3
test/fixtures/roles.yml
vendored
@ -34,6 +34,9 @@ roles_001:
|
|||||||
- :comment_news
|
- :comment_news
|
||||||
- :view_documents
|
- :view_documents
|
||||||
- :manage_documents
|
- :manage_documents
|
||||||
|
- :view_document_watchers
|
||||||
|
- :add_document_watchers
|
||||||
|
- :delete_document_watchers
|
||||||
- :view_wiki_pages
|
- :view_wiki_pages
|
||||||
- :export_wiki_pages
|
- :export_wiki_pages
|
||||||
- :view_wiki_edits
|
- :view_wiki_edits
|
||||||
|
@ -83,6 +83,70 @@ LOREM
|
|||||||
assert_equal 2, ActionMailer::Base.deliveries.size
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#new" do
|
||||||
|
should "allow adding watchers" do
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
set_tmp_attachments_directory
|
||||||
|
|
||||||
|
post(:new,
|
||||||
|
:project_id => 'ecookbook',
|
||||||
|
:document => {
|
||||||
|
:title => 'DocumentsControllerTest#test_post_new',
|
||||||
|
:description => 'This is a new document',
|
||||||
|
:category_id => 2,
|
||||||
|
:watcher_user_ids => ['2','3']
|
||||||
|
},
|
||||||
|
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}})
|
||||||
|
|
||||||
|
assert_redirected_to '/projects/ecookbook/documents'
|
||||||
|
|
||||||
|
document = Document.find_by_title('DocumentsControllerTest#test_post_new')
|
||||||
|
assert_not_nil document
|
||||||
|
assert document.watched_by?(User.find(2))
|
||||||
|
assert document.watched_by?(User.find(3))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "POST #edit" do
|
||||||
|
setup do
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
set_tmp_attachments_directory
|
||||||
|
|
||||||
|
@document = Document.generate!(:project => Project.find('ecookbook'),
|
||||||
|
:title => 'Test')
|
||||||
|
end
|
||||||
|
|
||||||
|
should "update the document" do
|
||||||
|
post(:edit,
|
||||||
|
:id => @document.id,
|
||||||
|
:document => {
|
||||||
|
:title => 'Change'
|
||||||
|
})
|
||||||
|
|
||||||
|
assert_response :redirect
|
||||||
|
|
||||||
|
@document.reload
|
||||||
|
assert_not_nil @document
|
||||||
|
assert_equal 'Change', @document.title
|
||||||
|
end
|
||||||
|
|
||||||
|
should "allow adding watchers" do
|
||||||
|
post(:edit,
|
||||||
|
:id => @document.id,
|
||||||
|
:document => {
|
||||||
|
:title => 'Change',
|
||||||
|
:watcher_user_ids => ['2','3']
|
||||||
|
})
|
||||||
|
|
||||||
|
assert_response :redirect
|
||||||
|
|
||||||
|
@document.reload
|
||||||
|
assert_not_nil @document
|
||||||
|
assert @document.watched_by?(User.find(2))
|
||||||
|
assert @document.watched_by?(User.find(3))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_destroy
|
def test_destroy
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
post :destroy, :id => 1
|
post :destroy, :id => 1
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DocumentTest < ActiveSupport::TestCase
|
class DocumentTest < ActiveSupport::TestCase
|
||||||
fixtures :projects, :enumerations, :documents, :attachments
|
fixtures :all
|
||||||
|
|
||||||
def test_create
|
def test_create
|
||||||
doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
|
doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
|
||||||
@ -51,4 +51,22 @@ class DocumentTest < ActiveSupport::TestCase
|
|||||||
assert d.attachments.empty?
|
assert d.attachments.empty?
|
||||||
assert_equal d.created_on, d.updated_on
|
assert_equal d.created_on, d.updated_on
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "allow watchers" do
|
||||||
|
assert Document.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods)
|
||||||
|
assert Document.new.respond_to?(:add_watcher)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#recipients" do
|
||||||
|
should "include watchers" do
|
||||||
|
document = Document.generate!(:project => Project.find(1))
|
||||||
|
user = User.find(1)
|
||||||
|
assert document.add_watcher(user)
|
||||||
|
|
||||||
|
assert document.save
|
||||||
|
|
||||||
|
assert document.recipients.include?(user.mail), "Watcher not included in recipients"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user