diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index f428e4b..47d4600 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -35,7 +35,7 @@ class CmsController < MyProfileController end protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files, :new] do |c, user, profile| - add_as_exception?(c.action_name) || user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) + user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) end protect_if :only => :new do |c, user, profile| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e928f9f..daf844b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -866,11 +866,13 @@ module ApplicationHelper end def helper_for_article(article) + puts "teste "*20 article_helper = ActionView::Base.new article_helper.controller = controller article_helper.extend ArticleHelper article_helper.extend Rails.application.routes.url_helpers begin + puts "erro "*20 class_name = article.class.name + 'Helper' klass = class_name.constantize article_helper.extend klass diff --git a/app/views/cms/upload_files.html.erb b/app/views/cms/upload_files.html.erb index d47a73e..c90acfc 100644 --- a/app/views/cms/upload_files.html.erb +++ b/app/views/cms/upload_files.html.erb @@ -19,9 +19,9 @@
<%= _('Uploading files to %s') % content_tag('code', @target) %>
-<%= form_for('uploaded_file', :url => {:action => 'upload_files' }, :html => {:multipart => true}) do |f| %> +<%= form_for('uploaded_file', :url => { :action => 'upload_files' }, :html => {:multipart => true}) do |f| %> - <%= @plugins.dispatch(:article_extra_fields, params[:parent_id]).collect { |content| instance_exec(&content) }.join("") %> + <%= @plugins.dispatch(:upload_files_extra_fields, params[:parent_id]).collect { |content| instance_exec(&content) }.join("") %> <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index 575f3df..0bee597 100644 --- a/lib/noosfero/plugin.rb +++ b/lib/noosfero/plugin.rb @@ -419,7 +419,7 @@ class Noosfero::Plugin # -> Adds adicional fields to a view # returns = proc block that creates html code - def article_extra_fields(article) + def upload_files_extra_fields(article) nil end diff --git a/plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb b/plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb new file mode 100644 index 0000000..8f0de69 --- /dev/null +++ b/plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb @@ -0,0 +1,30 @@ +class WorkAssignmentPluginMyprofileController < MyProfileController + +include ArticleHelper +include CmsHelper + +before_filter :protect_if, :only => [:edit_visibility] + + +def protect_if + article = c.environment.articles.find_by_id(c.params[:article_id]) + (user && !article.nil? && (user.is_member_of? article.profile) && + article.parent.allow_privacy_edition && article.folder? && + (article.author == user || user.has_permission?('view_private_content', profile))) +end + +def edit_privacy + unless params[:article_id].blank? + folder = profile.environment.articles.find_by_id(params[:article_id]) + @back_to = url_for(folder.parent.url) + unless params[:article].blank? + folder.published = params[:article][:published] + unless params[:q].nil? + folder.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i} + end + folder.save! + redirect_to @back_to + end + end + end +end \ No newline at end of file diff --git a/plugins/work_assignment/lib/ext/email_contact.rb b/plugins/work_assignment/lib/ext/email_contact.rb index e4d60fb..7ae5023 100644 --- a/plugins/work_assignment/lib/ext/email_contact.rb +++ b/plugins/work_assignment/lib/ext/email_contact.rb @@ -52,6 +52,7 @@ class EmailContact def build_mail_message!(environment, uploaded_files, parent_id) article = environment.articles.find_by_id(parent_id) message = "" + #kind_of? if !article.nil? && article.type == "WorkAssignmentPlugin::WorkAssignment" message = article.default_email + "
" end diff --git a/plugins/work_assignment/lib/ext/uploaded_file.rb b/plugins/work_assignment/lib/ext/uploaded_file.rb index 28110e8..a4876e9 100644 --- a/plugins/work_assignment/lib/ext/uploaded_file.rb +++ b/plugins/work_assignment/lib/ext/uploaded_file.rb @@ -11,14 +11,8 @@ class UploadedFile < Article end after_validation do |uploaded_file| - if uploaded_file.parent.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment) + if uploaded_file.parent && uploaded_file.parent.parent && uploaded_file.parent.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment) uploaded_file.published = uploaded_file.parent.published end end - - # after_create do |uploaded_file| - # if uploaded_file.parent.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment) - # uploaded_file.published = uploaded_file.parent.published - # end - # end end diff --git a/plugins/work_assignment/lib/work_assignment_plugin.rb b/plugins/work_assignment/lib/work_assignment_plugin.rb index 0c2dcd7..1fb0903 100644 --- a/plugins/work_assignment/lib/work_assignment_plugin.rb +++ b/plugins/work_assignment/lib/work_assignment_plugin.rb @@ -73,7 +73,7 @@ class WorkAssignmentPlugin < Noosfero::Plugin :block => block } end - def article_extra_fields(article) + def upload_files_extra_fields(article) proc do @article = Article.find_by_id(article) if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment" diff --git a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb index b25e759..907b19d 100644 --- a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb +++ b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb @@ -1,5 +1,6 @@ module WorkAssignmentPlugin::Helper include CmsHelper + include ArticleHelper def display_submissions(work_assignment, user) return if work_assignment.submissions.empty? content_tag('table', @@ -72,22 +73,41 @@ module WorkAssignmentPlugin::Helper end def display_privacy_button(author_folder, user) + #ver if if author_folder folder = environment.articles.find_by_id(author_folder.id) work_assignment = folder.parent @back_to = url_for(folder.parent.url) if(user && work_assignment.allow_privacy_edition && ((author_folder.author_id == user.id && (user.is_member_of? work_assignment.profile)) || - user.has_permission?('view_private_content', work_assignment.profile))) + user.has_permission?('view_private_content', work_assignment.profile)))#@profile? @tokenized_children = prepare_to_token_input( profile.members.includes(:articles_with_access).find_all{ |m| m.articles_with_access.include?(folder) }) - button :edit, _('Edit'), { :controller => 'cms', - :action => 'edit_visibility', :article_id => folder.id, + button :edit, _('Edit'), { :controller => 'work_assignment_plugin_myprofile', + :action => 'edit_privacy', :article_id => folder.id, :tokenized_children => @tokenized_children, :back_to => @back_to}, :method => :post end end end + + def visibility_options(article, tokenized_children) + content_tag('h4', _('Visibility')) + + content_tag('div', + content_tag('div', + radio_button(:article, :published, true) + + content_tag('label', _('Public (visible to other people)'), :for => 'article_published_true') + ) + + content_tag('div', + radio_button(:article, :published, false) + + content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private") + ) + + (article.profile.community? ? content_tag('div', + content_tag('label', _('Fill in the search field to add the exception users to see this content'), :id => "text-input-search-exception-users") + + token_input_field_tag(:q, 'search-article-privacy-exceptions', {:action => 'search_article_privacy_exceptions'}, + {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_children})) : + '')) + end end diff --git a/plugins/work_assignment/test/functional/cms_controller_test.rb b/plugins/work_assignment/test/functional/cms_controller_test.rb index aadd703..94b25a7 100644 --- a/plugins/work_assignment/test/functional/cms_controller_test.rb +++ b/plugins/work_assignment/test/functional/cms_controller_test.rb @@ -7,7 +7,7 @@ class CmsController; def rescue_action(e) raise e end; end class CmsControllerTest < ActionController::TestCase include NoosferoTestHelper - + #necessario? fixtures :environments diff --git a/plugins/work_assignment/test/unit/work_assingment_plugin_test.rb b/plugins/work_assignment/test/unit/work_assingment_plugin_test.rb index 3ba2024..85094de 100644 --- a/plugins/work_assignment/test/unit/work_assingment_plugin_test.rb +++ b/plugins/work_assignment/test/unit/work_assingment_plugin_test.rb @@ -15,7 +15,6 @@ class WorkAssignmentPluginTest < ActiveSupport::TestCase }, :without_protection => true ) - #content = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :author => fast_create(Person)) assert !WorkAssignmentPlugin.is_submission?(content) work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization) diff --git a/plugins/work_assignment/views/cms/edit_visibility.html.erb b/plugins/work_assignment/views/cms/edit_visibility.html.erb deleted file mode 100644 index 067dafe..0000000 --- a/plugins/work_assignment/views/cms/edit_visibility.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -
-<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> - - <% @article = environment.articles.find_by_id((params[:article_id]))%> - - <% @tokenized_children = params[:tokenized_children]%> - - <%= hidden_field_tag('article_id', @article.id) %> - -
- <%= options_for_article(@article, @tokenized_children) %> -
- - <% button_bar do %> - <%= submit_button :save, _('Save') %> - <%= button :cancel, _('Cancel'), @back_to %> - <% end %> -<% end %> -
- -
- -<%= javascript_include_tag "article.js" %> diff --git a/plugins/work_assignment/views/work_assignment_plugin_myprofile/edit_privacy.html.erb b/plugins/work_assignment/views/work_assignment_plugin_myprofile/edit_privacy.html.erb new file mode 100644 index 0000000..e6cc462 --- /dev/null +++ b/plugins/work_assignment/views/work_assignment_plugin_myprofile/edit_privacy.html.erb @@ -0,0 +1,24 @@ +
+ +<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> + + <% @article = environment.articles.find_by_id((params[:article_id]))%> + + <% @tokenized_children = params[:tokenized_children]%> + + <%= hidden_field_tag('article_id', @article.id) %> + +
+ <%= visibility_options(@article, @tokenized_children) %> +
+ + <% button_bar do %> + <%= submit_button :save, _('Save') %> + <%= button :cancel, _('Cancel'), @back_to %> + <% end %> +<% end %> +
+ +
+ +<%= javascript_include_tag "article.js" %> -- libgit2 0.21.2