Commit cbed32d2946c7dfef2af0d748f0cf5075d4f94c1
1 parent
1308d7fa
Exists in
master
and in
29 other branches
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>
Showing
13 changed files
with
87 additions
and
40 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -35,7 +35,7 @@ class CmsController < MyProfileController |
35 | 35 | end |
36 | 36 | |
37 | 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 | 39 | end |
40 | 40 | |
41 | 41 | protect_if :only => :new do |c, user, profile| | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -866,11 +866,13 @@ module ApplicationHelper |
866 | 866 | end |
867 | 867 | |
868 | 868 | def helper_for_article(article) |
869 | + puts "teste "*20 | |
869 | 870 | article_helper = ActionView::Base.new |
870 | 871 | article_helper.controller = controller |
871 | 872 | article_helper.extend ArticleHelper |
872 | 873 | article_helper.extend Rails.application.routes.url_helpers |
873 | 874 | begin |
875 | + puts "erro "*20 | |
874 | 876 | class_name = article.class.name + 'Helper' |
875 | 877 | klass = class_name.constantize |
876 | 878 | article_helper.extend klass | ... | ... |
app/views/cms/upload_files.html.erb
... | ... | @@ -19,9 +19,9 @@ |
19 | 19 | |
20 | 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 | 26 | <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> |
27 | 27 | ... | ... |
lib/noosfero/plugin.rb
plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
0 → 100644
... | ... | @@ -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 | 31 | \ No newline at end of file | ... | ... |
plugins/work_assignment/lib/ext/email_contact.rb
... | ... | @@ -52,6 +52,7 @@ class EmailContact |
52 | 52 | def build_mail_message!(environment, uploaded_files, parent_id) |
53 | 53 | article = environment.articles.find_by_id(parent_id) |
54 | 54 | message = "" |
55 | + #kind_of? | |
55 | 56 | if !article.nil? && article.type == "WorkAssignmentPlugin::WorkAssignment" |
56 | 57 | message = article.default_email + "<br>" |
57 | 58 | end | ... | ... |
plugins/work_assignment/lib/ext/uploaded_file.rb
... | ... | @@ -11,14 +11,8 @@ class UploadedFile < Article |
11 | 11 | end |
12 | 12 | |
13 | 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 | 15 | uploaded_file.published = uploaded_file.parent.published |
16 | 16 | end |
17 | 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 | 18 | end | ... | ... |
plugins/work_assignment/lib/work_assignment_plugin.rb
... | ... | @@ -73,7 +73,7 @@ class WorkAssignmentPlugin < Noosfero::Plugin |
73 | 73 | :block => block } |
74 | 74 | end |
75 | 75 | |
76 | - def article_extra_fields(article) | |
76 | + def upload_files_extra_fields(article) | |
77 | 77 | proc do |
78 | 78 | @article = Article.find_by_id(article) |
79 | 79 | if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment" | ... | ... |
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
1 | 1 | module WorkAssignmentPlugin::Helper |
2 | 2 | include CmsHelper |
3 | + include ArticleHelper | |
3 | 4 | def display_submissions(work_assignment, user) |
4 | 5 | return if work_assignment.submissions.empty? |
5 | 6 | content_tag('table', |
... | ... | @@ -72,22 +73,41 @@ module WorkAssignmentPlugin::Helper |
72 | 73 | end |
73 | 74 | |
74 | 75 | def display_privacy_button(author_folder, user) |
76 | + #ver if | |
75 | 77 | if author_folder |
76 | 78 | folder = environment.articles.find_by_id(author_folder.id) |
77 | 79 | work_assignment = folder.parent |
78 | 80 | @back_to = url_for(folder.parent.url) |
79 | 81 | if(user && work_assignment.allow_privacy_edition && |
80 | 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 | 85 | @tokenized_children = prepare_to_token_input( |
84 | 86 | profile.members.includes(:articles_with_access).find_all{ |m| |
85 | 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 | 91 | :tokenized_children => @tokenized_children, :back_to => @back_to}, :method => :post |
90 | 92 | end |
91 | 93 | end |
92 | 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 | 113 | end | ... | ... |
plugins/work_assignment/test/functional/cms_controller_test.rb
plugins/work_assignment/test/unit/work_assingment_plugin_test.rb
... | ... | @@ -15,7 +15,6 @@ class WorkAssignmentPluginTest < ActiveSupport::TestCase |
15 | 15 | }, |
16 | 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 | 18 | assert !WorkAssignmentPlugin.is_submission?(content) |
20 | 19 | |
21 | 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 | -<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 @@ |
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" %> | ... | ... |