Commit ae0165251d3f3502c679819521bfef60c9ad4a46

Authored by Dylan Guedes
Committed by Tallys Martins
1 parent 7aab108a

Writting and fixing Work Assignment Plugin tests

- Written tests of work_assignment cms controller.
- Fixed failures on unit tests
- Removed empy lines, spaces and useless code.
- Fixing bugs on edit_visibility filters

Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Signed-off-by: Dylan Guedes <djmgguedes@gmail.com>
Signed-off-by: Filipe Ribeiro <firibeiro77@live.com>
Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
Signed-off-by: Álvaro Fernando <alvarofernandoms@gmail.com>
Signed-off-by: Eduardo Vital <vitaldu@gmail.com>
Signed-off-by: André Bernardes <andrebsguedes@gmail.com>
Signed-off-by: Hebert Douglas <hebertdougl@gmail>
app/controllers/my_profile/cms_controller.rb
@@ -52,8 +52,6 @@ class CmsController &lt; MyProfileController @@ -52,8 +52,6 @@ class CmsController &lt; MyProfileController
52 profile.articles.find(c.params[:id]).allow_edit?(user) 52 profile.articles.find(c.params[:id]).allow_edit?(user)
53 end 53 end
54 54
55 -  
56 -  
57 def boxes_holder 55 def boxes_holder
58 profile 56 profile
59 end 57 end
lib/noosfero/plugin.rb
@@ -224,12 +224,6 @@ class Noosfero::Plugin @@ -224,12 +224,6 @@ class Noosfero::Plugin
224 false 224 false
225 end 225 end
226 226
227 - # -> Add action names to a list of filtered actions on cms controller  
228 - # returns = []  
229 - def add_action_to_list  
230 - []  
231 - end  
232 -  
233 # -> Adds buttons to the control panel 227 # -> Adds buttons to the control panel
234 # returns = { :title => title, :icon => icon, :url => url } 228 # returns = { :title => title, :icon => icon, :url => url }
235 # title = name that will be displayed. 229 # title = name that will be displayed.
plugins/work_assignment/lib/ext/cms_controller.rb
@@ -2,33 +2,29 @@ require_dependency &#39;cms_controller&#39; @@ -2,33 +2,29 @@ require_dependency &#39;cms_controller&#39;
2 2
3 class CmsController 3 class CmsController
4 4
5 -  
6 -protect_if :only => :edit_visibility do |c,user,profile|  
7 - profile.articles.find(c.params[:article_id]).author == user || user.has_permission?('view_private_content', profile) 5 +protect_if :only => :edit_visibility do |c, user, profile|
  6 + article = c.environment.articles.find_by_id(c.params[:article_id])
  7 + (user && !article.nil? && article.folder? && article.parent.allow_privacy_edition &&
  8 + (article.author == user || user.has_permission?('view_private_content', profile)))
8 end 9 end
9 10
10 def edit_visibility 11 def edit_visibility
11 unless params[:article_id].blank? 12 unless params[:article_id].blank?
12 - @folder = profile.articles.find(params[:article_id])  
13 - @back_to = url_for(@folder.parent.url) 13 + folder = profile.environment.articles.find_by_id(params[:article_id])
  14 + @back_to = url_for(folder.parent.url)
14 unless params[:article].blank? 15 unless params[:article].blank?
15 - @folder.published = params[:article][:published] 16 + folder.published = params[:article][:published]
16 unless params[:q].nil? 17 unless params[:q].nil?
17 - @folder.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i}  
18 - @folder.children.each do |c|  
19 - c.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i}  
20 - c.save!  
21 - end 18 + folder.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i}
22 end 19 end
23 - @folder.save! 20 + folder.save!
24 redirect_to @back_to 21 redirect_to @back_to
25 - end 22 + end
26 end 23 end
27 end 24 end
28 25
29 def self.add_as_exception?(action) 26 def self.add_as_exception?(action)
30 actions = "edit_visibility, search_article_privacy_exceptions" 27 actions = "edit_visibility, search_article_privacy_exceptions"
31 -  
32 if actions.include? action 28 if actions.include? action
33 true 29 true
34 else 30 else
@@ -36,4 +32,4 @@ def self.add_as_exception?(action) @@ -36,4 +32,4 @@ def self.add_as_exception?(action)
36 end 32 end
37 end 33 end
38 34
39 -end  
40 \ No newline at end of file 35 \ No newline at end of file
  36 +end
plugins/work_assignment/lib/ext/email_contact.rb
@@ -31,17 +31,17 @@ class EmailContact @@ -31,17 +31,17 @@ class EmailContact
31 class EmailSender < ActionMailer::Base 31 class EmailSender < ActionMailer::Base
32 32
33 def notification(email_contact) 33 def notification(email_contact)
34 - @name = email_contact.sender.name  
35 - @email = email_contact.sender.email  
36 - @message = email_contact.message  
37 - @target = email_contact.receiver 34 + name = email_contact.sender.name
  35 + email = email_contact.sender.email
  36 + message = email_contact.message
  37 + target = email_contact.receiver
38 38
39 options = { 39 options = {
40 content_type: 'text/html', 40 content_type: 'text/html',
41 - to: @target,  
42 - reply_to: @email, 41 + to: target,
  42 + reply_to: email,
43 subject: email_contact.subject, 43 subject: email_contact.subject,
44 - body: @message, 44 + body: message,
45 from: "#{email_contact.sender.environment.name} <#{email_contact.sender.environment.contact_email}>", 45 from: "#{email_contact.sender.environment.name} <#{email_contact.sender.environment.contact_email}>",
46 } 46 }
47 47
@@ -50,16 +50,16 @@ class EmailContact @@ -50,16 +50,16 @@ class EmailContact
50 end 50 end
51 51
52 def build_mail_message!(environment, uploaded_files, parent_id) 52 def build_mail_message!(environment, uploaded_files, parent_id)
53 - @article = environment.articles.find_by_id(parent_id)  
54 - @message = ""  
55 - if !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment"  
56 - @message = @article.default_email + "<br>" 53 + article = environment.articles.find_by_id(parent_id)
  54 + message = ""
  55 + if !article.nil? && article.type == "WorkAssignmentPlugin::WorkAssignment"
  56 + message = article.default_email + "<br>"
57 end 57 end
58 uploaded_files.each do |file| 58 uploaded_files.each do |file|
59 - @real_file_url = "http://#{file.url[:host]}:#{file.url[:port]}/#{file.url[:profile]}/#{file.path}"  
60 - @message += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" 59 + file_url = "http://#{file.url[:host]}:#{file.url[:port]}/#{file.url[:profile]}/#{file.path}"
  60 + message += "<br><a href='#{file_url}'>#{file_url}</a>"
61 end 61 end
62 - self.message = @message 62 + self.message = message
63 end 63 end
64 64
65 end 65 end
plugins/work_assignment/lib/ext/folder.rb 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +require_dependency 'article'
  2 +require_dependency 'folder'
  3 +
  4 +class Folder < Article
  5 + after_save do |folder|
  6 + if folder.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment)
  7 + folder.children.each do |c|
  8 + c.published = folder.published
  9 + c.article_privacy_exceptions = folder.article_privacy_exceptions
  10 + end
  11 + end
  12 + end
  13 +end
0 \ No newline at end of file 14 \ No newline at end of file
plugins/work_assignment/lib/ext/uploaded_file.rb
@@ -9,4 +9,16 @@ class UploadedFile &lt; Article @@ -9,4 +9,16 @@ class UploadedFile &lt; Article
9 uploaded_file.parent = author_folder 9 uploaded_file.parent = author_folder
10 end 10 end
11 end 11 end
  12 +
  13 + after_validation do |uploaded_file|
  14 + if uploaded_file.parent.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment)
  15 + uploaded_file.published = uploaded_file.parent.published
  16 + end
  17 + end
  18 +
  19 + # after_create do |uploaded_file|
  20 + # if uploaded_file.parent.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment)
  21 + # uploaded_file.published = uploaded_file.parent.published
  22 + # end
  23 + # end
12 end 24 end
plugins/work_assignment/lib/work_assignment_plugin.rb
@@ -54,11 +54,11 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -54,11 +54,11 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
54 def cms_controller_filters 54 def cms_controller_filters
55 block = proc do 55 block = proc do
56 if request.post? && params[:uploaded_files] 56 if request.post? && params[:uploaded_files]
57 - @email_notification = params[:article_email_notification]  
58 - unless !@email_notification || @email_notification.empty?  
59 - @email_contact = EmailContact.new(:subject => @parent.name, :receiver => @email_notification, :sender => user)  
60 - @email_contact.build_mail_message!(environment, @uploaded_files, @parent.id)  
61 - if @email_contact.deliver 57 + email_notification = params[:article_email_notification]
  58 + unless !email_notification || email_notification.empty?
  59 + email_contact = EmailContact.new(:subject => @parent.name, :receiver => email_notification, :sender => user)
  60 + email_contact.build_mail_message!(environment, @uploaded_files, @parent.id)
  61 + if email_contact.deliver
62 session[:notice] = _('Notification successfully sent') 62 session[:notice] = _('Notification successfully sent')
63 else 63 else
64 session[:notice] = _('Notification not sent') 64 session[:notice] = _('Notification not sent')
@@ -81,11 +81,4 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -81,11 +81,4 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
81 end 81 end
82 end 82 end
83 end 83 end
84 -  
85 - def add_action_to_list  
86 - proc do  
87 - action_list.append(", edits, search_article_privacy_exceptions")  
88 - end  
89 - end  
90 -  
91 end 84 end
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
@@ -16,7 +16,6 @@ module WorkAssignmentPlugin::Helper @@ -16,7 +16,6 @@ module WorkAssignmentPlugin::Helper
16 16
17 def display_author_folder(author_folder, user) 17 def display_author_folder(author_folder, user)
18 return if author_folder.children.empty? 18 return if author_folder.children.empty?
19 - action = 'toggle_friends_permission'  
20 content_tag('tr', 19 content_tag('tr',
21 content_tag('td', link_to_last_submission(author_folder, user)) + 20 content_tag('td', link_to_last_submission(author_folder, user)) +
22 content_tag('td', time_format(author_folder.children.last.created_at)) + 21 content_tag('td', time_format(author_folder.children.last.created_at)) +
@@ -74,21 +73,21 @@ module WorkAssignmentPlugin::Helper @@ -74,21 +73,21 @@ module WorkAssignmentPlugin::Helper
74 73
75 def display_privacy_button(author_folder, user) 74 def display_privacy_button(author_folder, user)
76 if author_folder 75 if author_folder
77 - @folder = environment.articles.find_by_id(author_folder.id)  
78 - work_assignment = @folder.parent  
79 - @back_to = url_for(@folder.parent.url) 76 + folder = environment.articles.find_by_id(author_folder.id)
  77 + work_assignment = folder.parent
  78 + @back_to = url_for(folder.parent.url)
80 if(user && work_assignment.allow_privacy_edition && 79 if(user && work_assignment.allow_privacy_edition &&
81 - (author_folder.author_id == user.id || user.has_permission?('view_private_content', work_assignment.profile))) 80 + ((author_folder.author_id == user.id && (user.is_member_of? work_assignment.profile)) ||
  81 + user.has_permission?('view_private_content', work_assignment.profile)))
82 82
83 @tokenized_children = prepare_to_token_input( 83 @tokenized_children = prepare_to_token_input(
84 profile.members.includes(:articles_with_access).find_all{ |m| 84 profile.members.includes(:articles_with_access).find_all{ |m|
85 - m.articles_with_access.include?(@folder) 85 + m.articles_with_access.include?(folder)
86 }) 86 })
87 button :edit, _('Edit'), { :controller => 'cms', 87 button :edit, _('Edit'), { :controller => 'cms',
88 - :action => 'edit_visibility', :article_id => @folder.id, 88 + :action => 'edit_visibility', :article_id => folder.id,
89 :tokenized_children => @tokenized_children, :back_to => @back_to}, :method => :post 89 :tokenized_children => @tokenized_children, :back_to => @back_to}, :method => :post
90 end 90 end
91 end 91 end
92 end 92 end
93 -  
94 end 93 end
plugins/work_assignment/public/content_resize.js
@@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
1 -  
2 -  
3 - alert( 'oi');  
plugins/work_assignment/public/style.css
1 .icon-newwork-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) } 1 .icon-newwork-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) }
2 .icon-work-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) } 2 .icon-work-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) }
3 -.select-privacy-options {  
4 - padding: 5px 20px;  
5 - width: 400px;  
6 - height: 300px;  
7 -}  
8 \ No newline at end of file 3 \ No newline at end of file
plugins/work_assignment/test/functional/cms_controller_test.rb
@@ -6,39 +6,196 @@ class CmsController; def rescue_action(e) raise e end; end @@ -6,39 +6,196 @@ class CmsController; def rescue_action(e) raise e end; end
6 6
7 class CmsControllerTest < ActionController::TestCase 7 class CmsControllerTest < ActionController::TestCase
8 8
  9 + include NoosferoTestHelper
  10 +
  11 + fixtures :environments
  12 +
  13 +
  14 + attr_reader :profile
  15 + attr_accessor :person
  16 +
9 def setup 17 def setup
10 @controller = CmsController.new 18 @controller = CmsController.new
11 @request = ActionController::TestRequest.new 19 @request = ActionController::TestRequest.new
12 @response = ActionController::TestResponse.new 20 @response = ActionController::TestResponse.new
13 @person = create_user('test_user').person 21 @person = create_user('test_user').person
14 login_as :test_user 22 login_as :test_user
  23 + e = Environment.default
  24 + e.enabled_plugins = ['WorkAssignmentPlugin']
  25 + e.save!
  26 + @organization = fast_create(Organization) #
15 end 27 end
16 28
17 - attr_accessor :person  
18 -  
19 should 'not allow non-members to upload submissions on work_assignment' do 29 should 'not allow non-members to upload submissions on work_assignment' do
20 - organization = fast_create(Organization)  
21 - work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)  
22 -  
23 - get :upload_files, :profile => organization.identifier, :parent_id => work_assignment.id 30 + work_assignment = create_work_assignment('Another Work Assignment', @organization, nil, nil)
  31 + get :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id
24 assert_response :forbidden 32 assert_response :forbidden
25 assert_template 'access_denied' 33 assert_template 'access_denied'
  34 + end
26 35
27 - organization.add_member(person)  
28 -  
29 - get :upload_files, :profile => organization.identifier, :parent_id => work_assignment.id 36 + should 'allow members to upload submissions on work_assignment' do
  37 + @organization.add_member(person)
  38 + # then he trys to upload new stuff
  39 + work_assignment = create_work_assignment('Another Work Assignment', @organization, nil, nil)
  40 + get :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id
30 assert_response :success 41 assert_response :success
31 end 42 end
32 43
33 - should 'upload submission and automatically move it to the author folder' do  
34 - organization = fast_create(Organization)  
35 - work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)  
36 - organization.add_member(person)  
37 - post :upload_files, :profile => organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')] 44 + should 'redirect to Work Assignment view page after upload submission' do
  45 + @organization.add_member(person)
  46 + work_assignment = create_work_assignment('Another Work Assignment', @organization, nil, nil)
  47 + post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')] , :back_to => @work_assignment.url
  48 + assert_redirected_to work_assignment.url
  49 + end
38 50
  51 + should 'upload submission and automatically move it to the author folder' do
  52 + work_assignment = create_work_assignment('Another Work Assignment', @organization, nil, nil)
  53 + @organization.add_member(person)
  54 + post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
39 submission = UploadedFile.last 55 submission = UploadedFile.last
40 assert_equal work_assignment.find_or_create_author_folder(person), submission.parent 56 assert_equal work_assignment.find_or_create_author_folder(person), submission.parent
41 end 57 end
42 58
43 -end 59 + should 'work_assignment attribute allow_privacy_edition is true when set a new work_assignment' do
  60 + work_assignment = create_work_assignment('Another Work Assignment', @organization, nil, true)
  61 + @organization.add_member(person)
  62 + assert_equal true, work_assignment.allow_privacy_edition
  63 + end
  64 +
  65 + should 'a submission and parent attribute "published" be equal to Work Assignment attribute publish submissions' do
  66 + @organization.add_member(person)
  67 + work_assignment = create_work_assignment('Another Work Assignment', @organization, true, nil)
  68 + assert_equal true, work_assignment.publish_submissions
  69 + post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
  70 + submission = UploadedFile.last
  71 + assert_equal work_assignment.publish_submissions, submission.published
  72 + assert_equal work_assignment.publish_submissions, submission.parent.published
  73 +
  74 + other_work_assignment = create_work_assignment('Another Other Work Assigment', @organization, false, nil)
  75 + assert_equal false, other_work_assignment.publish_submissions
  76 + post :upload_files, :profile => @organization.identifier, :parent_id => other_work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
  77 + submission = UploadedFile.last
  78 + assert_equal other_work_assignment.publish_submissions, submission.published
  79 + assert_equal other_work_assignment.publish_submissions, submission.parent.published
  80 + end
  81 +
  82 + should 'submission edit visibility deny access to users and admin when Work Assignment allow_privacy_edition is false' do
  83 + @organization.add_member(person)
  84 + ##### Testing with normal user
  85 + work_assignment = create_work_assignment('Another Work Assignment', @organization, nil, nil)
  86 + post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
  87 + submission = UploadedFile.last
  88 + assert_equal false, submission.published
  89 + assert_equal false, submission.parent.published
  90 +
  91 + post :edit_visibility, :profile => @organization.identifier, :article_id => submission.parent.id
  92 + assert_template 'access_denied'
  93 + post :edit_visibility, :profile => @organization.identifier, :article_id => submission.parent.id, :article => { :published => true }
  94 + assert_template 'access_denied'
  95 +
  96 + submission.reload
  97 + assert_equal false, submission.published
  98 + assert_equal false, submission.parent.published
44 99
  100 + #### Even with admin user
  101 + e = Environment.default
  102 + assert_equal false, person.is_admin?
  103 + e.add_admin(person)
  104 + e.save!
  105 + assert_equal true, person.is_admin?
  106 +
  107 + post :edit_visibility, :profile => @organization.identifier, :article_id => submission.parent.id
  108 + assert_template 'access_denied'
  109 + post :edit_visibility, :profile => @organization.identifier, :article_id => submission.parent.id, :article => { :published => true }
  110 + assert_template 'access_denied'
  111 +
  112 + submission.reload
  113 + assert_equal false, submission.published
  114 + end
  115 +
  116 + should 'redirect an unlogged user to the login page if he tryes to access the edit visibility page and work_assignment allow_privacy_edition is true' do
  117 + @organization.add_member(person)
  118 + work_assignment = create_work_assignment('Another Work Assignment', @organization, nil, nil)
  119 + work_assignment.allow_privacy_edition = true # the user can edit the privacy
  120 + assert_equal true, work_assignment.allow_privacy_edition
  121 + work_assignment.save!
  122 + parent = work_assignment.find_or_create_author_folder(person)
  123 + UploadedFile.create(
  124 + {
  125 + :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'),
  126 + :profile => @organization,
  127 + :parent => parent,
  128 + :last_changed_by => person,
  129 + :author => person,
  130 + },
  131 + :without_protection => true
  132 + )
  133 + logout
  134 + submission = UploadedFile.last
  135 + assert_equal false, submission.parent.published
  136 + assert_equal false, submission.published
  137 +
  138 + post :edit_visibility, :profile => @organization.identifier, :article_id => submission.parent.id
  139 + assert_redirected_to '/account/login'
  140 + post :edit_visibility, :profile => @organization.identifier, :article_id => submission.parent.id, :article => { :published => true }
  141 + assert_redirected_to '/account/login'
  142 + submission.reload
  143 + assert_equal false, submission.parent.published
  144 + assert_equal false, submission.published
  145 + end
  146 +
  147 + should 'submission edit_visibility deny access to not owner when WorkAssignment edit_visibility is true' do
  148 + @organization.add_member(person) # current_user is a member
  149 + work_assignment = create_work_assignment('Another Work Assignment', @organization, nil, true)
  150 + @parent = work_assignment.find_or_create_author_folder(person)
  151 + UploadedFile.create(
  152 + {
  153 + :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'),
  154 + :profile => @organization,
  155 + :parent => @parent,
  156 + :last_changed_by => person,
  157 + :author => person,
  158 + },
  159 + :without_protection => true
  160 + )
  161 + logout
  162 +
  163 +
  164 + other_person = create_user('other_user').person
  165 + @organization.add_member(other_person)
  166 + login_as :other_user
  167 +
  168 + @organization.add_member(other_person)
  169 + submission = UploadedFile.last
  170 + assert_equal(submission.author, person)
  171 +
  172 + post :edit_visibility, :profile => @organization.identifier, :article_id => submission.parent.id
  173 + assert_template 'access_denied'
  174 +
  175 + post :edit_visibility, :profile => @organization.identifier, :article_id => submission.parent.id, :article => { :published => true }
  176 + assert_template 'access_denied'
  177 +
  178 + submission.reload
  179 + assert_equal false, submission.parent.published
  180 + assert_equal false, submission.published
  181 + end
  182 +
  183 + should 'submission white list give permission to an user that has been added' do
  184 + other_person = create_user('other_user').person
  185 + @organization.add_member(person)
  186 + @organization.add_member(other_person)
  187 + work_assignment = create_work_assignment('Another Work Assignment', @organization, false, true)
  188 + post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
  189 + submission = UploadedFile.last
  190 + assert_equal false, submission.display_unpublished_article_to?(other_person)
  191 + post :edit_visibility, :profile => @organization.identifier, :article_id => submission.parent.id, :article => { :published => false }, :q => other_person.id
  192 + submission.reload
  193 + assert_equal true, submission.parent.display_unpublished_article_to?(other_person)
  194 + assert_equal true, submission.display_unpublished_article_to?(other_person)
  195 + end
  196 +
  197 + private
  198 + def create_work_assignment(name = nil, profile = nil, publish_submissions = nil, allow_privacy_edition = nil)
  199 + @work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => name, :profile => profile, :publish_submissions => publish_submissions, :allow_privacy_edition => allow_privacy_edition)
  200 + end
  201 +end
plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
1 -require "test_helper" 1 +require File.expand_path(File.dirname(__FILE__) + "/../../../../../test/test_helper")
2 2
3 class WorkAssignmentTest < ActiveSupport::TestCase 3 class WorkAssignmentTest < ActiveSupport::TestCase
4 should 'find or create sub-folder based on author identifier' do 4 should 'find or create sub-folder based on author identifier' do
@@ -38,7 +38,7 @@ class WorkAssignmentTest &lt; ActiveSupport::TestCase @@ -38,7 +38,7 @@ class WorkAssignmentTest &lt; ActiveSupport::TestCase
38 submission = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => work_assignment, :author => author) 38 submission = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => work_assignment, :author => author)
39 39
40 author_folder = work_assignment.find_or_create_author_folder(author) 40 author_folder = work_assignment.find_or_create_author_folder(author)
41 - assert author_folder, submission.parent 41 + assert_equal author_folder, submission.parent
42 end 42 end
43 43
44 should 'add logged user on cache_key if is a member' do 44 should 'add logged user on cache_key if is a member' do
plugins/work_assignment/test/unit/work_assingment_plugin_test.rb
1 -require 'test_helper' 1 +require File.expand_path(File.dirname(__FILE__) + "/../../../../test/test_helper")
2 2
3 class WorkAssignmentPluginTest < ActiveSupport::TestCase 3 class WorkAssignmentPluginTest < ActiveSupport::TestCase
4 should 'verify if a content is a work_assignment submission' do 4 should 'verify if a content is a work_assignment submission' do
5 organization = fast_create(Organization) 5 organization = fast_create(Organization)
6 - content = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :author => fast_create(Person)) 6 + folder = fast_create(Folder)
  7 + person = fast_create(Person)
  8 + content = UploadedFile.create(
  9 + {
  10 + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'),
  11 + :profile => organization,
  12 + :parent => folder,
  13 + :last_changed_by => person,
  14 + :author => person,
  15 + },
  16 + :without_protection => true
  17 + )
  18 + #content = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :author => fast_create(Person))
7 assert !WorkAssignmentPlugin.is_submission?(content) 19 assert !WorkAssignmentPlugin.is_submission?(content)
8 20
9 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization) 21 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)
@@ -22,7 +34,9 @@ class WorkAssignmentPluginTest &lt; ActiveSupport::TestCase @@ -22,7 +34,9 @@ class WorkAssignmentPluginTest &lt; ActiveSupport::TestCase
22 work_assignment = submission.parent.parent 34 work_assignment = submission.parent.parent
23 work_assignment.publish_submissions = true 35 work_assignment.publish_submissions = true
24 work_assignment.save! 36 work_assignment.save!
25 - assert WorkAssignmentPlugin.can_download_submission?(nil, submission) 37 +
  38 + other_submission = create_submission(nil, work_assignment)
  39 + assert WorkAssignmentPlugin.can_download_submission?(nil, other_submission)
26 end 40 end
27 41
28 should 'be able to download submission if the user is author of it' do 42 should 'be able to download submission if the user is author of it' do
@@ -45,12 +59,21 @@ class WorkAssignmentPluginTest &lt; ActiveSupport::TestCase @@ -45,12 +59,21 @@ class WorkAssignmentPluginTest &lt; ActiveSupport::TestCase
45 59
46 private 60 private
47 61
48 - def create_submission(author=nil) 62 + def create_submission(author=nil, work_assignment=nil)
49 author ||= fast_create(Person) 63 author ||= fast_create(Person)
50 organization = fast_create(Organization) 64 organization = fast_create(Organization)
51 -  
52 - work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization) 65 + organization.add_member(author)
  66 + work_assignment ||= WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)
53 author_folder = work_assignment.find_or_create_author_folder(author) 67 author_folder = work_assignment.find_or_create_author_folder(author)
54 - create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => author_folder, :author => author, :last_changed_by => author) 68 + content = UploadedFile.create(
  69 + {
  70 + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'),
  71 + :profile => organization,
  72 + :parent => author_folder,
  73 + :last_changed_by => author,
  74 + :author => author,
  75 + },
  76 + :without_protection => true
  77 + )
55 end 78 end
56 end 79 end
plugins/work_assignment/views/cms/_notify_text_field.html.erb
1 <h5><%= _('If you want to notify someone about this action, fill the field below with the emails of the destinies, separated by comma.') %></h5> 1 <h5><%= _('If you want to notify someone about this action, fill the field below with the emails of the destinies, separated by comma.') %></h5>
2 2
3 <%= labelled_text_field(_('Send notification to: '), 'article_email_notification', user.email, :style => 'width: 60%;') %> 3 <%= labelled_text_field(_('Send notification to: '), 'article_email_notification', user.email, :style => 'width: 60%;') %>
4 -  
plugins/work_assignment/views/cms/edit_visibility.html.erb
@@ -20,4 +20,4 @@ @@ -20,4 +20,4 @@
20 20
21 <br style='clear: both'/> 21 <br style='clear: both'/>
22 22
23 -<%= javascript_include_tag "article.js" %>  
24 \ No newline at end of file 23 \ No newline at end of file
  24 +<%= javascript_include_tag "article.js" %>
plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
@@ -5,4 +5,3 @@ @@ -5,4 +5,3 @@
5 <%=labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %> 5 <%=labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %>
6 6
7 <%=labelled_check_box(_('Allow users set privacy?'), 'article[allow_privacy_edition]', true, @article.allow_privacy_edition) %> 7 <%=labelled_check_box(_('Allow users set privacy?'), 'article[allow_privacy_edition]', true, @article.allow_privacy_edition) %>
8 -