Commit cbed32d2946c7dfef2af0d748f0cf5075d4f94c1

Authored by Tallys Martins
1 parent 1308d7fa

Refactoring Work Assignment Plugin

- Changed article_extra_fields hotspot name to upload_files_extra_fields
- Fixed some code spacing.
- Fixed uploaded file filter on plugin class
- Fixed after_validation filter on UploadedFile plugin extension class

Signed-off-by: Tallys Martins <tallysmartins@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: André Bernardes <andrebsguedes@gmail.com>
Signed-off-by: Hebert Douglas <hebertdougl@gmail>
app/controllers/my_profile/cms_controller.rb
@@ -35,7 +35,7 @@ class CmsController &lt; MyProfileController @@ -35,7 +35,7 @@ class CmsController &lt; MyProfileController
35 end 35 end
36 36
37 protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files, :new] do |c, user, profile| 37 protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files, :new] do |c, user, profile|
38 - add_as_exception?(c.action_name) || user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) 38 + user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))
39 end 39 end
40 40
41 protect_if :only => :new do |c, user, profile| 41 protect_if :only => :new do |c, user, profile|
app/helpers/application_helper.rb
@@ -866,11 +866,13 @@ module ApplicationHelper @@ -866,11 +866,13 @@ module ApplicationHelper
866 end 866 end
867 867
868 def helper_for_article(article) 868 def helper_for_article(article)
  869 + puts "teste "*20
869 article_helper = ActionView::Base.new 870 article_helper = ActionView::Base.new
870 article_helper.controller = controller 871 article_helper.controller = controller
871 article_helper.extend ArticleHelper 872 article_helper.extend ArticleHelper
872 article_helper.extend Rails.application.routes.url_helpers 873 article_helper.extend Rails.application.routes.url_helpers
873 begin 874 begin
  875 + puts "erro "*20
874 class_name = article.class.name + 'Helper' 876 class_name = article.class.name + 'Helper'
875 klass = class_name.constantize 877 klass = class_name.constantize
876 article_helper.extend klass 878 article_helper.extend klass
app/views/cms/upload_files.html.erb
@@ -19,9 +19,9 @@ @@ -19,9 +19,9 @@
19 19
20 <h5><%= _('Uploading files to %s') % content_tag('code', @target) %></h5> 20 <h5><%= _('Uploading files to %s') % content_tag('code', @target) %></h5>
21 21
22 -<%= form_for('uploaded_file', :url => {:action => 'upload_files' }, :html => {:multipart => true}) do |f| %> 22 +<%= form_for('uploaded_file', :url => { :action => 'upload_files' }, :html => {:multipart => true}) do |f| %>
23 23
24 - <%= @plugins.dispatch(:article_extra_fields, params[:parent_id]).collect { |content| instance_exec(&content) }.join("") %> 24 + <%= @plugins.dispatch(:upload_files_extra_fields, params[:parent_id]).collect { |content| instance_exec(&content) }.join("") %>
25 25
26 <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> 26 <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %>
27 27
lib/noosfero/plugin.rb
@@ -419,7 +419,7 @@ class Noosfero::Plugin @@ -419,7 +419,7 @@ class Noosfero::Plugin
419 419
420 # -> Adds adicional fields to a view 420 # -> Adds adicional fields to a view
421 # returns = proc block that creates html code 421 # returns = proc block that creates html code
422 - def article_extra_fields(article) 422 + def upload_files_extra_fields(article)
423 nil 423 nil
424 end 424 end
425 425
plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb 0 → 100644
@@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
  1 +class WorkAssignmentPluginMyprofileController < MyProfileController
  2 +
  3 +include ArticleHelper
  4 +include CmsHelper
  5 +
  6 +before_filter :protect_if, :only => [:edit_visibility]
  7 +
  8 +
  9 +def protect_if
  10 + article = c.environment.articles.find_by_id(c.params[:article_id])
  11 + (user && !article.nil? && (user.is_member_of? article.profile) &&
  12 + article.parent.allow_privacy_edition && article.folder? &&
  13 + (article.author == user || user.has_permission?('view_private_content', profile)))
  14 +end
  15 +
  16 +def edit_privacy
  17 + unless params[:article_id].blank?
  18 + folder = profile.environment.articles.find_by_id(params[:article_id])
  19 + @back_to = url_for(folder.parent.url)
  20 + unless params[:article].blank?
  21 + folder.published = params[:article][:published]
  22 + unless params[:q].nil?
  23 + folder.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i}
  24 + end
  25 + folder.save!
  26 + redirect_to @back_to
  27 + end
  28 + end
  29 + end
  30 +end
0 \ No newline at end of file 31 \ No newline at end of file
plugins/work_assignment/lib/ext/email_contact.rb
@@ -52,6 +52,7 @@ class EmailContact @@ -52,6 +52,7 @@ class EmailContact
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) 53 article = environment.articles.find_by_id(parent_id)
54 message = "" 54 message = ""
  55 + #kind_of?
55 if !article.nil? && article.type == "WorkAssignmentPlugin::WorkAssignment" 56 if !article.nil? && article.type == "WorkAssignmentPlugin::WorkAssignment"
56 message = article.default_email + "<br>" 57 message = article.default_email + "<br>"
57 end 58 end
plugins/work_assignment/lib/ext/uploaded_file.rb
@@ -11,14 +11,8 @@ class UploadedFile &lt; Article @@ -11,14 +11,8 @@ class UploadedFile &lt; Article
11 end 11 end
12 12
13 after_validation do |uploaded_file| 13 after_validation do |uploaded_file|
14 - if uploaded_file.parent.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment) 14 + if uploaded_file.parent && uploaded_file.parent.parent && uploaded_file.parent.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment)
15 uploaded_file.published = uploaded_file.parent.published 15 uploaded_file.published = uploaded_file.parent.published
16 end 16 end
17 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  
24 end 18 end
plugins/work_assignment/lib/work_assignment_plugin.rb
@@ -73,7 +73,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -73,7 +73,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
73 :block => block } 73 :block => block }
74 end 74 end
75 75
76 - def article_extra_fields(article) 76 + def upload_files_extra_fields(article)
77 proc do 77 proc do
78 @article = Article.find_by_id(article) 78 @article = Article.find_by_id(article)
79 if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment" 79 if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment"
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
1 module WorkAssignmentPlugin::Helper 1 module WorkAssignmentPlugin::Helper
2 include CmsHelper 2 include CmsHelper
  3 + include ArticleHelper
3 def display_submissions(work_assignment, user) 4 def display_submissions(work_assignment, user)
4 return if work_assignment.submissions.empty? 5 return if work_assignment.submissions.empty?
5 content_tag('table', 6 content_tag('table',
@@ -72,22 +73,41 @@ module WorkAssignmentPlugin::Helper @@ -72,22 +73,41 @@ module WorkAssignmentPlugin::Helper
72 end 73 end
73 74
74 def display_privacy_button(author_folder, user) 75 def display_privacy_button(author_folder, user)
  76 + #ver if
75 if author_folder 77 if author_folder
76 folder = environment.articles.find_by_id(author_folder.id) 78 folder = environment.articles.find_by_id(author_folder.id)
77 work_assignment = folder.parent 79 work_assignment = folder.parent
78 @back_to = url_for(folder.parent.url) 80 @back_to = url_for(folder.parent.url)
79 if(user && work_assignment.allow_privacy_edition && 81 if(user && work_assignment.allow_privacy_edition &&
80 ((author_folder.author_id == user.id && (user.is_member_of? work_assignment.profile)) || 82 ((author_folder.author_id == user.id && (user.is_member_of? work_assignment.profile)) ||
81 - user.has_permission?('view_private_content', work_assignment.profile))) 83 + user.has_permission?('view_private_content', work_assignment.profile)))#@profile?
82 84
83 @tokenized_children = prepare_to_token_input( 85 @tokenized_children = prepare_to_token_input(
84 profile.members.includes(:articles_with_access).find_all{ |m| 86 profile.members.includes(:articles_with_access).find_all{ |m|
85 m.articles_with_access.include?(folder) 87 m.articles_with_access.include?(folder)
86 }) 88 })
87 - button :edit, _('Edit'), { :controller => 'cms',  
88 - :action => 'edit_visibility', :article_id => folder.id, 89 + button :edit, _('Edit'), { :controller => 'work_assignment_plugin_myprofile',
  90 + :action => 'edit_privacy', :article_id => folder.id,
89 :tokenized_children => @tokenized_children, :back_to => @back_to}, :method => :post 91 :tokenized_children => @tokenized_children, :back_to => @back_to}, :method => :post
90 end 92 end
91 end 93 end
92 end 94 end
  95 +
  96 + def visibility_options(article, tokenized_children)
  97 + content_tag('h4', _('Visibility')) +
  98 + content_tag('div',
  99 + content_tag('div',
  100 + radio_button(:article, :published, true) +
  101 + content_tag('label', _('Public (visible to other people)'), :for => 'article_published_true')
  102 + ) +
  103 + content_tag('div',
  104 + radio_button(:article, :published, false) +
  105 + content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private")
  106 + ) +
  107 + (article.profile.community? ? content_tag('div',
  108 + content_tag('label', _('Fill in the search field to add the exception users to see this content'), :id => "text-input-search-exception-users") +
  109 + token_input_field_tag(:q, 'search-article-privacy-exceptions', {:action => 'search_article_privacy_exceptions'},
  110 + {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_children})) :
  111 + ''))
  112 + end
93 end 113 end
plugins/work_assignment/test/functional/cms_controller_test.rb
@@ -7,7 +7,7 @@ class CmsController; def rescue_action(e) raise e end; end @@ -7,7 +7,7 @@ class CmsController; def rescue_action(e) raise e end; end
7 class CmsControllerTest < ActionController::TestCase 7 class CmsControllerTest < ActionController::TestCase
8 8
9 include NoosferoTestHelper 9 include NoosferoTestHelper
10 - 10 + #necessario?
11 fixtures :environments 11 fixtures :environments
12 12
13 13
plugins/work_assignment/test/unit/work_assingment_plugin_test.rb
@@ -15,7 +15,6 @@ class WorkAssignmentPluginTest &lt; ActiveSupport::TestCase @@ -15,7 +15,6 @@ class WorkAssignmentPluginTest &lt; ActiveSupport::TestCase
15 }, 15 },
16 :without_protection => true 16 :without_protection => true
17 ) 17 )
18 - #content = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :author => fast_create(Person))  
19 assert !WorkAssignmentPlugin.is_submission?(content) 18 assert !WorkAssignmentPlugin.is_submission?(content)
20 19
21 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization) 20 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)
plugins/work_assignment/views/cms/edit_visibility.html.erb
@@ -1,23 +0,0 @@ @@ -1,23 +0,0 @@
1 -<div class="select-privacy-options">  
2 -<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %>  
3 -  
4 - <% @article = environment.articles.find_by_id((params[:article_id]))%>  
5 -  
6 - <% @tokenized_children = params[:tokenized_children]%>  
7 -  
8 - <%= hidden_field_tag('article_id', @article.id) %>  
9 -  
10 - <div id='edit-article-options'>  
11 - <%= options_for_article(@article, @tokenized_children) %>  
12 - </div>  
13 -  
14 - <% button_bar do %>  
15 - <%= submit_button :save, _('Save') %>  
16 - <%= button :cancel, _('Cancel'), @back_to %>  
17 - <% end %>  
18 -<% end %>  
19 -</div>  
20 -  
21 -<br style='clear: both'/>  
22 -  
23 -<%= javascript_include_tag "article.js" %>  
plugins/work_assignment/views/work_assignment_plugin_myprofile/edit_privacy.html.erb 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +<div class="select-privacy-options">
  2 +
  3 +<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %>
  4 +
  5 + <% @article = environment.articles.find_by_id((params[:article_id]))%>
  6 +
  7 + <% @tokenized_children = params[:tokenized_children]%>
  8 +
  9 + <%= hidden_field_tag('article_id', @article.id) %>
  10 +
  11 + <div id='edit-article-options'>
  12 + <%= visibility_options(@article, @tokenized_children) %>
  13 + </div>
  14 +
  15 + <% button_bar do %>
  16 + <%= submit_button :save, _('Save') %>
  17 + <%= button :cancel, _('Cancel'), @back_to %>
  18 + <% end %>
  19 +<% end %>
  20 +</div>
  21 +
  22 +<br style='clear: both'/>
  23 +
  24 +<%= javascript_include_tag "article.js" %>