noosfero | 21 new commits pushed to repository

Antonio Terceiro gitlab at gitlab.com
Thu Jan 22 17:51:36 BRST 2015


Antonio Terceiro pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/938cbff344dd0978039ffde4d0fa99da8e997044">938cbff3</a> by Andre Bernardes
Migrating Work Assignment Plugin to rails3

Added upload_files_extra_content hotspot, fixed work_assignment_form file extension,
fixed redirections on file deletion, changed deprecated build_notification to build_contact method.

Signed-off-by: Andre Bernardes <andrebsguedes at gmail.com>
Signed-off-by: Eduardo Vital <vitaldu at gmail.com>
Signed-off-by: Hebert Douglas <hebertdougl at gmail.com>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

(AI2967)

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/46a4526be26a1b5b0c66c56e3681b26da28b8445">46a4526b</a> by Andre Bernardes
rails3: Fixing mass assignment on publish_submissions attribute.

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/6ef3eef0052f55a39ebe5f3197bc84d383946889">6ef3eef0</a> by Andre Bernardes
Creating new EmailContact model for sending work assignment notifications.

(work_assignment_rails3)

Signed-off-by: Tallys Martins <tallysmartins at gmail.com>
Signed-off-by: Andre Bernardes <andrebsguedes at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/05d537e3590b3ce92baec5d0a6a977f4198bebe5">05d537e3</a> by tallys
Inserted message body into Work Assignment email notification
TODO Refactor send_email method on Work Assignment Cms controller

Signed-off-by: Hebert Douglas <hebertdougl at gmail.com>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/17c8b3be7160c27bcda5b339529c42098f421a58">17c8b3be</a> by Hebert Douglas
Fixed bug on plugin views

Changed html forms to rails3 pattern.

Signed-off-by: Andre Bernardes <andrebsguedes at gmail.com>
Signed-off-by: Hebert Douglas <hebertdougl at gmail>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/e42003f520c18c8fa0e46a834ceb106ffb942e0c">e42003f5</a> by Andre Bernardes
Updated cms upload method on work_assignmet plugin.

Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/94d6333bcc9f9b0547b63a02b6defdfb53c5b392">94d6333b</a> by Andre Bernardes
Refactored send_email to a new method.

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/27831399b97b54c91d9375f01b8b62c794c7b4a1">27831399</a> by Tallys Martins
Fixing bugs on Work Assignment plugin

- Removed useless view.
- Fixed problem on page render when file error(e.g. over max size) is detected.
- Fixed bug when no file selected.
- Refactored dispatch on upload_files.html.erb  to have less impact on core.
- Added java script to modify the form action to use the plugin controller on upload_files form.
- Fixed Work Assignment not sending e-mails
- Removing duplicated code
- Added new dispatch on cms_controller

Signed-off-by: Andre Bernardes <andrebsguedes at gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/e6c0328a50fb1f89b69460c93dca29c80052b43a">e6c0328a</a> by Tallys Martins
Refactoring Work Assignment

Added filters to cms controller to send email
Removed unecessary dispatch on cms controller

Signed-off-by: Andre Bernardes <andrebsguedes at gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/99c763b5bcab185a3ecda4a8938cf1eac8f7a798">99c763b5</a> by Tallys Martins
Added new attribute to Work_assignment article type

Added default email message attribute to be sent when user choose to notify somebody.
Refactored build_email_message method that attaches the URL of the uploaded files to the email message.
Added Java Script to fill in the email field with  an example.
Removed destroy action method on plugin cms controller, now using the existent in the core cms controller.

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/4fe9e656de8f1516d6efdb53b1bf3cd24cfdf39d">4fe9e656</a> by Tallys Martins
Refactoring Work Assignment Plugin

- Removed class Person on Work Assignment Plugin.
- Fixed rails3 file extension on functional Tests.
- changed the email_contact 'from' to be the environment email.
- Changed notification text field to show the user email by default

Signed-off-by: Andre Bernardes <andrebsguedes at gmail.com>
Signed-off-by: Dylan Guedes <djmgguedes at gmail.com>
Signed-off-by: Filipe Ribeiro <firibeiro77 at live.com>
Signed-off-by: Dylan Guedes <djmgguedes at gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/03744acd4ab84d8e2779be43d056d3777e57cb4e">03744acd</a> by Tallys Martins
Work Assignment Privacy Options

- Added privacy button to work_Assignment uploaded files
- Added style for privacy options
- Applying privacy permitions on Uploaded Files

Signed-off-by: Andre Bernardes <andrebsguedes at gmail.com>
Signed-off-by: Filipe Ribeiro <firibeiro77 at live.com>
Signed-off-by: Dylan Guedes <djmgguedes at gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/1db348b82e1aa60abc6679bb75225604e2e696c0">1db348b8</a> by Marcos
WorkAssignment submissions visibility edition is now working for admins user

- Refactored the name of the action to edit_visibility
- Refactored edit_visibility behavior to apply privacy to also the Folder's children
- Fixed bug on plugin content_viewer filter not passing the right path of article

Signed-off-by: Andre Bernardes <andrebsguedes at gmail.com>
Signed-off-by: Filipe Ribeiro <firibeiro77 at live.com>
Signed-off-by: Dylan Guedes <djmgguedes at gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/dfed60056c9e3f6162e9e7f28a9da4a9de605f02">dfed6005</a> by Tallys Martins
WorkAssignment privacy edition now works for all users

Refactored Cms Controller inheritance on Work Assignment Plugin.
Added a new method on Cms controller that is extended on Work Assignment Plugin and can allow a plugin action to by pass
the static before filter generated on Cms that denies any other actions outside it's list.
Added a before filter on plugin cms controller  that allows the visibility edition only for the article author and admins.

Signed-off-by Tallys Martins <tallysmartins at gmail.com>
Signed-off-by: Arhur Del Esposte <arthurmde at gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/7aab108a3f977b17a595fb8eb91316a4efa353c6">7aab108a</a> by Tallys Martins
Refactoring work assignment plugin

Changed privacy edition box to open on a new page.
Fixed cancel buttom to redirect to back page.

    Signed-off-by: Tallys Martins <tallysmartins at gmail.com>
    Signed-off-by: Álvaro Fernando <alvarofernandoms at gmail.com>
    Signed-off-by: Eduardo Vital <vitaldu at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/ae0165251d3f3502c679819521bfef60c9ad4a46">ae016525</a> by DylanGuedes
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 at gmail.com>
Signed-off-by: Dylan Guedes <djmgguedes at gmail.com>
Signed-off-by: Filipe Ribeiro <firibeiro77 at live.com>
Signed-off-by: Pedro de Lyra <pedrodelyra at gmail.com>
Signed-off-by: Álvaro Fernando <alvarofernandoms at gmail.com>
Signed-off-by: Eduardo Vital <vitaldu at gmail.com>
Signed-off-by: André Bernardes <andrebsguedes at gmail.com>
Signed-off-by: Hebert Douglas <hebertdougl at gmail>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/1308d7fa36b937aab0caf9930345df04c362b614">1308d7fa</a> by Tallys Martins
Writing functional tests to Work Assignment Plugin

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/cbed32d2946c7dfef2af0d748f0cf5075d4f94c1">cbed32d2</a> by Tallys Martins
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 at gmail.com>
Signed-off-by: Filipe Ribeiro <firibeiro77 at live.com>
Signed-off-by: Pedro de Lyra <pedrodelyra at gmail.com>
Signed-off-by: Álvaro Fernando <alvarofernandoms at gmail.com>
Signed-off-by: André Bernardes <andrebsguedes at gmail.com>
Signed-off-by: Hebert Douglas <hebertdougl at gmail>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/c9b33c17f779d4f94212875f40ff3ab0eef530e2">c9b33c17</a> by Tallys Martins
Refactoring Work Assignment Plugin

- Changed methods and variable names.
- Created work_assignment_plugin_myprofile_controller and undone the cms_controller extension
- Fixed the tests to fit the new structure

Signed-off-by: Gabriela Navarro <navarro1703 at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/c13119fbe652161a543c379529453bc9435e4ea5">c13119fb</a> by Tallys Martins
Recatoring Work Assignment Plugin to fit the merge

 - Moved EmailContact class from ext directory to plugin scope
 - Refactored Work Assignment Plugin to accept general articles instead of only uploaded files
 - Protecting methods that are not supposed to be actions

Signed-off-by: Tallys Martins <tallysmartins at gmail.com>
Signed-off-by: André Bernardes <andrebsguedes at gmail.com>
Signed-off-by: Hebert Douglas <hebertdougl at gmail>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/5e1957f3b4cfb65788b99a126a940ca7dfe6dca5">5e1957f3</a> by Antonio Terceiro
Merge branch 'work_assignment_master_rebase' into 'master'

Work assignment master rebase

The last version of the Work Assignment plugin, increased by Universidade de Brasília team.

The plugin purpose is to keep versioned files, result of a work and to notify people by email about new uploaded files. Users can also change the visibility of their files, if the feature is set on Work Assignment settings.

See merge request !420

- - - - -


Changes:

=====================================
app/controllers/my_profile/cms_controller.rb
=====================================
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -214,6 +214,7 @@ class CmsController < MyProfileController
       if @errors.any?
         render :action => 'upload_files', :parent_id => @parent_id
       else
+        session[:notice] = _('File(s) successfully uploaded') 
         if @back_to
           redirect_to @back_to
         elsif @parent

=====================================
app/views/cms/upload_files.html.erb
=====================================
--- a/app/views/cms/upload_files.html.erb
+++ b/app/views/cms/upload_files.html.erb
@@ -20,5 +20,10 @@
 <h5><%= _('Uploading files to %s') % content_tag('code', @target) %></h5>
 
 <%= form_for('uploaded_file', :url => { :action => 'upload_files' }, :html => {:multipart => true}) do |f| %>
+
+  <%= @plugins.dispatch(:upload_files_extra_fields, params[:parent_id]).collect { |content| instance_exec(&content) }.join("") %>
+
   <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %>
-<% end %>
+
+<% end %> 
+

=====================================
lib/noosfero/plugin.rb
=====================================
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -417,6 +417,12 @@ class Noosfero::Plugin
     nil
   end
 
+  # -> Adds adicional fields to a view
+  # returns = proc block that creates html code
+  def upload_files_extra_fields(article)
+    nil
+  end
+  
   # -> Adds fields to the signup form
   # returns = proc that creates html code
   def signup_extra_contents

=====================================
plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
=====================================
--- /dev/null
+++ b/plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
@@ -0,0 +1,38 @@
+class WorkAssignmentPluginMyprofileController < MyProfileController
+
+helper ArticleHelper
+helper CmsHelper
+
+before_filter :protect_if, :only => [:edit_visibility]
+
+def edit_visibility
+  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
+
+  def search_article_privacy_exceptions
+    arg = params[:q].downcase
+    result = profile.members.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"])
+    render :text => prepare_to_token_input(result).to_json
+  end
+
+  protected
+
+  def protect_if
+    article = environment.articles.find_by_id(params[:article_id])
+    render_access_denied unless (user && !article.nil? && (user.is_member_of? article.profile) &&
+    article.parent.allow_visibility_edition && article.folder? &&
+    (article.author == user || user.has_permission?('view_private_content', profile)))
+  end
+
+end

=====================================
plugins/work_assignment/lib/ext/article.rb
=====================================
--- /dev/null
+++ b/plugins/work_assignment/lib/ext/article.rb
@@ -0,0 +1,20 @@
+require_dependency 'article'
+
+class Article
+  before_validation :work_assignment_save_into_author_folder
+  after_validation :work_assignment_change_visibility
+
+  def work_assignment_save_into_author_folder
+    if not self.is_a? Folder and self.parent.kind_of? WorkAssignmentPlugin::WorkAssignment
+      author_folder = self.parent.find_or_create_author_folder(self.author)
+      self.name = WorkAssignmentPlugin::WorkAssignment.versioned_name(self, author_folder)
+      self.parent = author_folder
+    end
+  end
+
+  def work_assignment_change_visibility
+    if self.parent && self.parent.parent && self.parent.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment)
+      self.published = self.parent.published
+    end
+  end
+end
\ No newline at end of file

=====================================
plugins/work_assignment/lib/ext/folder.rb
=====================================
--- /dev/null
+++ b/plugins/work_assignment/lib/ext/folder.rb
@@ -0,0 +1,13 @@
+require_dependency 'article'
+require_dependency 'folder'
+
+class Folder < Article
+  after_save do |folder|
+    if folder.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment)
+      folder.children.each do |c|
+        c.published = folder.published
+        c.article_privacy_exceptions = folder.article_privacy_exceptions
+      end
+    end
+  end
+end

=====================================
plugins/work_assignment/lib/ext/uploaded_file.rb
=====================================
--- a/plugins/work_assignment/lib/ext/uploaded_file.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require_dependency 'article'
-require_dependency 'uploaded_file'
-
-class UploadedFile < Article
-  before_validation do |uploaded_file|
-    if uploaded_file.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment)
-      author_folder = uploaded_file.parent.find_or_create_author_folder(uploaded_file.author)
-      uploaded_file.name = WorkAssignmentPlugin::WorkAssignment.versioned_name(uploaded_file, author_folder)
-      uploaded_file.parent = author_folder
-    end
-  end
-end

=====================================
plugins/work_assignment/lib/work_assignment_plugin.rb
=====================================
--- a/plugins/work_assignment/lib/work_assignment_plugin.rb
+++ b/plugins/work_assignment/lib/work_assignment_plugin.rb
@@ -9,8 +9,8 @@ class WorkAssignmentPlugin < Noosfero::Plugin
   end
 
   def self.can_download_submission?(user, submission)
-    work_assignment = submission.parent.parent
-    work_assignment.publish_submissions || (user && (submission.author == user || user.has_permission?('view_private_content', work_assignment.profile)))
+      submission.published? || (user && (submission.author == user || user.has_permission?('view_private_content', submission.profile) ||
+      submission.display_unpublished_article_to?(user)))
   end
 
   def self.is_submission?(content)
@@ -37,7 +37,7 @@ class WorkAssignmentPlugin < Noosfero::Plugin
 
   def content_viewer_controller_filters
     block = proc do
-      path = params[:page]
+      path = get_path(params[:page], params[:format])
       content = profile.articles.find_by_path(path)
 
       if WorkAssignmentPlugin.is_submission?(content) && !WorkAssignmentPlugin.can_download_submission?(user, content)
@@ -51,4 +51,34 @@ class WorkAssignmentPlugin < Noosfero::Plugin
       :block => block }
   end
 
+  def cms_controller_filters
+    block = proc do
+      if request.post? && params[:uploaded_files]
+        email_notification = params[:article_email_notification]
+        unless !email_notification || email_notification.empty?
+          email_contact = WorkAssignmentPlugin::EmailContact.new(:subject => @parent.name, :receiver => email_notification, :sender => user)
+          WorkAssignmentPlugin::EmailContact::EmailSender.build_mail_message(email_contact, @uploaded_files)
+          if email_contact.deliver
+            session[:notice] = _('Notification successfully sent')
+          else
+            session[:notice] = _('Notification not sent')
+          end
+        end
+      end
+    end
+
+    { :type => 'after_filter',
+      :method_name => 'send_email_after_upload_file',
+      :options => {:only => 'upload_files'},
+      :block => block }
+  end
+
+  def upload_files_extra_fields(article)
+    proc do
+      @article = Article.find_by_id(article)
+      if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment"
+        render :partial => 'notify_text_field',  :locals => { :size => '45'}
+      end
+    end
+  end
 end

=====================================
plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb
=====================================
--- /dev/null
+++ b/plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb
@@ -0,0 +1,64 @@
+class WorkAssignmentPlugin::EmailContact
+
+  include ActiveModel::Validations
+
+  def initialize(attributes = nil)
+    if attributes
+      attributes.each do |attr,value|
+        self.send("#{attr}=", value)
+      end
+    end
+  end
+
+  attr_accessor :name
+  attr_accessor :subject
+  attr_accessor :message
+  attr_accessor :email
+  attr_accessor :receive_a_copy
+  attr_accessor :sender
+  attr_accessor :receiver
+
+  N_('Subject'); N_('Message'); N_('e-Mail'); N_('Name')
+
+  validates_presence_of :receiver, :subject, :message, :sender
+  validates_format_of :receiver, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|o| !o.email.blank?})
+
+  def deliver
+    return false unless self.valid?
+    WorkAssignmentPlugin::EmailContact::EmailSender.notification(self).deliver
+  end
+
+  class EmailSender < ActionMailer::Base
+
+    def notification(email_contact)
+      name = email_contact.sender.name
+      email = email_contact.sender.email
+      message = email_contact.message
+      target = email_contact.receiver
+
+      options = {
+        content_type: 'text/html',
+        to: target,
+        reply_to: email,
+        subject: email_contact.subject,
+        body: message,
+        from: "#{email_contact.sender.environment.name} <#{email_contact.sender.environment.contact_email}>",
+      }
+
+      mail(options)
+    end
+
+    def build_mail_message(email_contact, uploaded_files)
+      message = ""
+      if uploaded_files && uploaded_files.first && uploaded_files.first.parent && uploaded_files.first.parent.parent
+        article = uploaded_files.first.parent.parent
+        message = article.default_email + "<br>"
+        uploaded_files.each do |file|
+          url = url_for(file.url)
+          message += "<br><a href='#{url}'>#{url}</a>"
+        end
+      end
+      email_contact.message = message
+    end
+  end
+end

=====================================
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
=====================================
--- a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb
+++ b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb
@@ -1,4 +1,6 @@
 module WorkAssignmentPlugin::Helper
+  include CmsHelper
+  
   def display_submissions(work_assignment, user)
     return if work_assignment.submissions.empty?
     content_tag('table',
@@ -6,6 +8,7 @@ module WorkAssignmentPlugin::Helper
         content_tag('th', c_('Author'), :style => 'width: 50%') +
         content_tag('th', _('Submission date')) +
         content_tag('th', _('Versions'), :style => 'text-align: center') +
+        content_tag('th', '') +
         content_tag('th', '')
       ).html_safe +
       work_assignment.children.map {|author_folder| display_author_folder(author_folder, user)}.join("\n").html_safe
@@ -18,7 +21,8 @@ module WorkAssignmentPlugin::Helper
       content_tag('td', link_to_last_submission(author_folder, user)) +
       content_tag('td', time_format(author_folder.children.last.created_at)) +
       content_tag('td', author_folder.children.count, :style => 'text-align: center') +
-      content_tag('td', content_tag('button', _('View all versions'), :class => 'view-author-versions', 'data-folder-id' => author_folder.id))
+      content_tag('td', content_tag('button', _('View all versions'), :class => 'view-author-versions', 'data-folder-id' => author_folder.id)) +
+      content_tag('td', display_privacy_button(author_folder, user))
     ).html_safe +
     author_folder.children.map {|submission| display_submission(submission, user)}.join("\n").html_safe
   end
@@ -26,7 +30,13 @@ module WorkAssignmentPlugin::Helper
   def display_submission(submission, user)
     content_tag('tr',
       content_tag('td', link_to_submission(submission, user)) +
-      content_tag('td', time_format(submission.created_at), :colspan => 3),
+      content_tag('td', time_format(submission.created_at))+
+      content_tag('td', '') +
+      content_tag('td', 
+        if submission.parent.parent.allow_post_content?(user)
+          display_delete_button(submission)
+        end
+      ),
       :class => "submission-from-#{submission.parent.id}",
       :style => 'display: none'
     )
@@ -40,7 +50,6 @@ module WorkAssignmentPlugin::Helper
     end
   end
 
-
   def link_to_last_submission(author_folder, user)
     if WorkAssignmentPlugin.can_download_submission?(user, author_folder.children.last)
       link_to(author_folder.name, author_folder.children.last.url)
@@ -48,6 +57,7 @@ module WorkAssignmentPlugin::Helper
       author_folder.name
     end
   end
+
   # FIXME Copied from custom-froms. Consider passing it to core...
   def time_format(time)
     minutes = (time.min == 0) ? '' : ':%M'
@@ -56,4 +66,28 @@ module WorkAssignmentPlugin::Helper
     time.strftime("%Y-%m-%d#{hour+minutes+h}")
   end
 
+  def display_delete_button(article)
+    expirable_button article, :delete, _('Delete'), 
+    {:controller =>'cms', :action => 'destroy', :id => article.id },
+    :method => :post, :confirm => delete_article_message(article)
+  end
+
+  def display_privacy_button(author_folder, user)
+    folder = environment.articles.find_by_id(author_folder.id)
+    work_assignment = folder.parent
+    @back_to = url_for(work_assignment.url)
+
+    if(user && work_assignment.allow_visibility_edition &&
+      ((author_folder.author_id == user.id && (user.is_member_of? profile)) ||
+      user.has_permission?('view_private_content', 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 => 'work_assignment_plugin_myprofile',
+      :action => 'edit_visibility', :article_id => folder.id,
+      :tokenized_children => @tokenized_children, :back_to => @back_to}, :method => :post
+    end
+  end
 end

=====================================
plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
=====================================
--- a/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
+++ b/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
@@ -1,9 +1,13 @@
 class WorkAssignmentPlugin::WorkAssignment < Folder
 
   settings_items :publish_submissions, :type => :boolean, :default => false
+  settings_items :default_email, :type => :string, :default => ""
+  settings_items :allow_visibility_edition, :type => :boolean, :default => false
 
   attr_accessible :publish_submissions
-
+  attr_accessible :default_email
+  attr_accessible :allow_visibility_edition
+  
   def self.icon_name(article = nil)
     'work-assignment'
   end
@@ -29,13 +33,22 @@ class WorkAssignmentPlugin::WorkAssignment < Folder
   end
 
   def to_html(options = {})
-    proc do
+    lambda do
       render :file => 'content_viewer/work_assignment.html.erb'
     end
   end
 
   def find_or_create_author_folder(author)
-    children.find_by_slug(author.name.to_slug) || Folder.create!(:name => author.name, :parent => self, :profile => profile)
+    children.find_by_slug(author.name.to_slug) || Folder.create!(
+                                                                {
+                                                                  :name => author.name,
+                                                                  :parent => self,
+                                                                  :profile => profile,
+                                                                  :author => author,
+                                                                  :published => publish_submissions,
+                                                                }, 
+                                                                :without_protection => true
+                                                  )
   end
 
   def submissions
@@ -45,6 +58,5 @@ class WorkAssignmentPlugin::WorkAssignment < Folder
   def cache_key_with_person(params = {}, user = nil, language = 'en')
     cache_key_without_person + (user && profile.members.include?(user) ? "-#{user.identifier}" : '')
   end
-  alias_method_chain :cache_key, :person
-
+  alias_method_chain :cache_key, :person  
 end

=====================================
plugins/work_assignment/test/functional/cms_controller_test.rb
=====================================
--- a/plugins/work_assignment/test/functional/cms_controller_test.rb
+++ b/plugins/work_assignment/test/functional/cms_controller_test.rb
@@ -1,4 +1,4 @@
-require 'test_helper'
+require File.expand_path(File.dirname(__FILE__) + "/../../../../test/test_helper")
 require 'cms_controller'
 
 # Re-raise errors caught by the controller.
@@ -12,33 +12,67 @@ class CmsControllerTest < ActionController::TestCase
     @response   = ActionController::TestResponse.new
     @person = create_user('test_user').person
     login_as :test_user
+    e = Environment.default
+    e.enabled_plugins = ['WorkAssignmentPlugin']
+    e.save!
+    @organization = fast_create(Organization) #
   end
 
-  attr_accessor :person
-
   should 'not allow non-members to upload submissions on work_assignment' do
-    organization = fast_create(Organization)
-    work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)
-
-    get :upload_files, :profile => organization.identifier, :parent_id => work_assignment.id
+    work_assignment = create_work_assignment('Work Assignment', @organization, nil, nil)
+    get :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id
     assert_response :forbidden
     assert_template 'access_denied'
+  end
 
-    organization.add_member(person)
-
-    get :upload_files, :profile => organization.identifier, :parent_id => work_assignment.id
+  should 'allow members to upload submissions on work_assignment' do
+    @organization.add_member(@person)
+    # then he trys to upload new stuff
+    work_assignment = create_work_assignment('Work Assignment', @organization, nil, nil)
+    get :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id
     assert_response :success
   end
 
+  should 'redirect to Work Assignment view page after upload submission' do
+    @organization.add_member(@person)
+    work_assignment = create_work_assignment('Work Assignment', @organization, nil, nil)
+    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
+    assert_redirected_to work_assignment.url
+  end
+
   should 'upload submission and automatically move it to the author folder' do
-    organization = fast_create(Organization)
-    work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)
-    organization.add_member(person)
-    post :upload_files, :profile => organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
+    work_assignment = create_work_assignment('Work Assignment', @organization, nil, nil)
+    @organization.add_member(@person)
+    post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
+    submission = UploadedFile.last
+    assert_equal work_assignment.find_or_create_author_folder(@person), submission.parent
+  end
+
+  should 'work_assignment attribute allow_visibility_edition is true when set a new work_assignment' do
+    work_assignment = create_work_assignment('Work Assignment', @organization, nil, true)
+    @organization.add_member(@person)
+    assert_equal true, work_assignment.allow_visibility_edition
+  end
 
+  should 'a submission and parent attribute "published" be equal to Work Assignment attribute publish submissions' do
+    @organization.add_member(@person)
+    work_assignment = create_work_assignment('Work Assignment', @organization, true, nil)
+    assert_equal true, work_assignment.publish_submissions
+    post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
     submission = UploadedFile.last
-    assert_equal work_assignment.find_or_create_author_folder(person), submission.parent
+    assert_equal work_assignment.publish_submissions, submission.published
+    assert_equal work_assignment.publish_submissions, submission.parent.published
+
+    other_work_assignment = create_work_assignment('Other Work Assigment', @organization, false, nil)
+    assert_equal false, other_work_assignment.publish_submissions
+    post :upload_files, :profile => @organization.identifier, :parent_id => other_work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
+    submission = UploadedFile.last
+    assert_equal other_work_assignment.publish_submissions, submission.published
+    assert_equal other_work_assignment.publish_submissions, submission.parent.published
   end
 
+  private
+    def create_work_assignment(name = nil, profile = nil, publish_submissions = nil, allow_visibility_edition = nil)
+      @work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => name, :profile => profile, :publish_submissions => publish_submissions, :allow_visibility_edition => allow_visibility_edition)
+    end
 end
-

=====================================
plugins/work_assignment/test/functional/content_viewer_controller_test.rb
=====================================
--- a/plugins/work_assignment/test/functional/content_viewer_controller_test.rb
+++ b/plugins/work_assignment/test/functional/content_viewer_controller_test.rb
@@ -1,4 +1,4 @@
-require 'test_helper'
+require File.expand_path(File.dirname(__FILE__) + "/../../../../test/test_helper")
 require 'content_viewer_controller'
 
 # Re-raise errors caught by the controller.
@@ -15,6 +15,7 @@ class ContentViewerControllerTest < ActionController::TestCase
     @organization = fast_create(Organization)
     @work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => @organization)
     @person = create_user('test_user').person
+    @organization.add_member(@person)
     @environment = @organization.environment
     @environment.enable_plugin(WorkAssignmentPlugin)
     @environment.save!
@@ -23,19 +24,17 @@ class ContentViewerControllerTest < ActionController::TestCase
   attr_reader :organization, :person, :profile, :work_assignment
 
   should 'can download work_assignment' do
-    random_member = fast_create(Person)
-    organization.add_member(random_member)
-    folder = work_assignment.find_or_create_author_folder(random_member)
+    folder = work_assignment.find_or_create_author_folder(@person)
     submission = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => folder)
     WorkAssignmentPlugin.stubs(:can_download_submission?).returns(false)
 
-    get :view_page, :profile => organization.identifier, :page => submission.path
+    get :view_page, :profile => @organization.identifier, :page => submission.path
     assert_response :forbidden
     assert_template 'access_denied'
 
     WorkAssignmentPlugin.stubs(:can_download_submission?).returns(true)
 
-    get :view_page, :profile => organization.identifier, :page => submission.path
+    get :view_page, :profile => @organization.identifier, :page => submission.path
     assert_response :success
   end
 

=====================================
plugins/work_assignment/test/functional/work_assignment_plugin_myprofile_controller_test.rb
=====================================
--- /dev/null
+++ b/plugins/work_assignment/test/functional/work_assignment_plugin_myprofile_controller_test.rb
@@ -0,0 +1,191 @@
+require File.expand_path(File.dirname(__FILE__) + "/../../../../test/test_helper")
+require 'work_assignment_plugin_myprofile_controller'
+
+# Re-raise errors caught by the controller.
+class WorkAssignmentPluginMyprofileController; def rescue_action(e) raise e end; end
+
+class WorkAssignmentPluginMyprofileControllerTest < ActionController::TestCase
+
+  def setup
+    @controller = WorkAssignmentPluginMyprofileController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+    @person = create_user('test_user').person
+    login_as :test_user
+    e = Environment.default
+    e.enabled_plugins = ['WorkAssignmentPlugin']
+    e.save!
+    @organization = fast_create(Organization) #
+  end
+
+  should 'submission edit visibility deny access to users and admin when Work Assignment allow_visibility_edition is false' do
+    @organization.add_member(@person)
+    ##### Testing with normal user
+    work_assignment = create_work_assignment('Work Assignment', @organization, nil, false)
+    work_assignment.save!
+    assert_equal false, work_assignment.allow_visibility_edition
+    parent = work_assignment.find_or_create_author_folder(@person)
+    UploadedFile.create(
+            {
+              :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'),
+              :profile => @organization,
+              :parent => parent,
+              :last_changed_by => @person,
+              :author => @person,
+            },
+            :without_protection => true
+          )
+    submission = UploadedFile.find_by_filename("test.txt")
+    assert_equal false, submission.published
+    assert_equal false, submission.parent.published
+
+    post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id
+    assert_template 'access_denied'
+    post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id, :article => { :published => true }
+    assert_template 'access_denied'
+
+    submission.reload
+    assert_equal false, submission.published
+    assert_equal false, submission.parent.published
+
+    #### Even with admin user
+    e = Environment.default
+    assert_equal false, @person.is_admin?
+    e.add_admin(@person)
+    e.save!
+    assert_equal true, @person.is_admin?
+
+    post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id
+    assert_template 'access_denied'
+    post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id, :article => { :published => true }
+    assert_template 'access_denied'
+
+    submission.reload
+    assert_equal false, submission.published
+  end
+
+  should 'redirect an unlogged user to the login page if he tryes to access the edit visibility page and work_assignment allow_visibility_edition is true' do
+    @organization.add_member(@person)
+    work_assignment = create_work_assignment('Work Assignment', @organization, nil, true)
+    assert_equal true, work_assignment.allow_visibility_edition
+    work_assignment.save!
+    parent = work_assignment.find_or_create_author_folder(@person)
+    UploadedFile.create(
+            {
+              :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'),
+              :profile => @organization,
+              :parent => parent,
+              :last_changed_by => @person,
+              :author => @person,
+            },
+            :without_protection => true
+          )
+    logout
+    submission = UploadedFile.find_by_filename("test.txt")
+    assert_equal false, submission.parent.published
+    assert_equal false, submission.published
+
+    post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id
+    assert_redirected_to '/account/login'
+    post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id, :article => { :published => true }
+    assert_redirected_to '/account/login'
+    submission.reload
+    assert_equal false, submission.parent.published
+    assert_equal false, submission.published
+  end
+
+  should 'submission edit_visibility deny access to not owner when WorkAssignment edit_visibility is true' do
+    @organization.add_member(@person) # current_user is a member
+    work_assignment = create_work_assignment('Another Work Assignment', @organization, nil, true)
+    parent = work_assignment.find_or_create_author_folder(@person)
+    UploadedFile.create(
+            {
+              :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'),
+              :profile => @organization,
+              :parent => parent,
+              :last_changed_by => @person,
+              :author => @person,
+            },
+            :without_protection => true
+          )
+    logout
+
+
+    other_person = create_user('other_user').person
+    @organization.add_member(other_person)
+    login_as :other_user
+
+    @organization.add_member(other_person)
+    submission = UploadedFile.find_by_filename("test.txt")
+    assert_equal(submission.author, @person)
+
+    post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id
+    assert_template 'access_denied'
+
+    post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id, :article => { :published => true }
+    assert_template 'access_denied'
+
+    submission.reload
+    assert_equal false, submission.parent.published
+    assert_equal false, submission.published
+  end
+
+  should 'submission white list give permission to an user that has been added' do
+    other_person = create_user('other_user').person
+    @organization.add_member(@person)
+    @organization.add_member(other_person)
+    work_assignment = create_work_assignment('Another Work Assignment', @organization, false,  true)
+    parent = work_assignment.find_or_create_author_folder(@person)
+    UploadedFile.create(
+            {
+              :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'),
+              :profile => @organization,
+              :parent => parent,
+              :last_changed_by => @person,
+              :author => @person,
+            },
+            :without_protection => true
+          )
+    submission = UploadedFile.find_by_filename("test.txt")
+    assert_equal false, submission.article_privacy_exceptions.include?(other_person)
+    post :edit_visibility, :profile => @organization.identifier, :article_id  => parent.id, :article => { :published => false }, :q => other_person.id
+    submission.reload
+    assert_equal true, submission.parent.article_privacy_exceptions.include?(other_person)
+    assert_equal true, submission.article_privacy_exceptions.include?(other_person)
+  end
+
+  should 'submission edit_visibility deny access to owner if not organization member' do
+    @organization.add_member(@person) # current_user is a member
+    work_assignment = create_work_assignment('Work Assignment', @organization, nil, true)
+    parent = work_assignment.find_or_create_author_folder(@person)
+    UploadedFile.create(
+            {
+              :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'),
+              :profile => @organization,
+              :parent => parent,
+              :last_changed_by => @person,
+              :author => @person,
+            },
+            :without_protection => true
+          )
+    @organization.remove_member(@person)
+    submission = UploadedFile.find_by_filename("test.txt")
+
+    assert_equal false, (@person.is_member_of? submission.profile)
+
+    post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id
+    assert_template 'access_denied'
+
+    post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id, :article => { :published => true }
+    assert_template 'access_denied'
+
+    submission.reload
+    assert_equal false, submission.parent.published
+    assert_equal false, submission.published
+  end
+
+  private
+    def create_work_assignment(name = nil, profile = nil, publish_submissions = nil, allow_visibility_edition = nil)
+      @work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => name, :profile => profile, :publish_submissions => publish_submissions, :allow_visibility_edition => allow_visibility_edition)
+    end
+end

=====================================
plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
=====================================
--- a/plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
+++ b/plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require File.expand_path(File.dirname(__FILE__) + "/../../../../../test/test_helper")
 
 class WorkAssignmentTest < ActiveSupport::TestCase
   should 'find or create sub-folder based on author identifier' do

=====================================
plugins/work_assignment/test/unit/work_assingment_plugin_test.rb
=====================================
--- a/plugins/work_assignment/test/unit/work_assingment_plugin_test.rb
+++ b/plugins/work_assignment/test/unit/work_assingment_plugin_test.rb
@@ -1,9 +1,20 @@
-require 'test_helper'
+require File.expand_path(File.dirname(__FILE__) + "/../../../../test/test_helper")
 
 class WorkAssignmentPluginTest < ActiveSupport::TestCase
   should 'verify if a content is a work_assignment submission' do
     organization = fast_create(Organization)
-    content = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :author => fast_create(Person))
+    folder = fast_create(Folder)
+    person = fast_create(Person)
+    content = UploadedFile.create(
+            {
+              :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'),
+              :profile => organization,
+              :parent => folder,
+              :last_changed_by => person,
+              :author => person,
+            },
+            :without_protection => true
+          )
     assert !WorkAssignmentPlugin.is_submission?(content)
 
     work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)
@@ -22,7 +33,9 @@ class WorkAssignmentPluginTest < ActiveSupport::TestCase
     work_assignment = submission.parent.parent
     work_assignment.publish_submissions = true
     work_assignment.save!
-    assert WorkAssignmentPlugin.can_download_submission?(nil, submission)
+
+    other_submission = create_submission(nil, work_assignment)
+    assert WorkAssignmentPlugin.can_download_submission?(nil, other_submission)
   end
 
   should 'be able to download submission if the user is author of it' do
@@ -45,12 +58,21 @@ class WorkAssignmentPluginTest < ActiveSupport::TestCase
 
   private
 
-  def create_submission(author=nil)
+  def create_submission(author=nil, work_assignment=nil)
     author ||= fast_create(Person)
     organization = fast_create(Organization)
-
-    work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)
+    organization.add_member(author)
+    work_assignment ||= WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)
     author_folder = work_assignment.find_or_create_author_folder(author)
-    create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => author_folder, :author => author, :last_changed_by => author)
+    content = UploadedFile.create(
+            {
+              :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'),
+              :profile => organization,
+              :parent => author_folder,
+              :last_changed_by => author,
+              :author => author,
+            },
+            :without_protection => true
+          )
   end
 end

=====================================
plugins/work_assignment/views/cms/_notify_text_field.html.erb
=====================================
--- /dev/null
+++ b/plugins/work_assignment/views/cms/_notify_text_field.html.erb
@@ -0,0 +1,3 @@
+<h5><%= _('If you want to notify someone about this action, fill the field below with the emails of the destinies, separated by comma.') %></h5>
+
+<%= labelled_text_field(_('Send notification to: '), 'article_email_notification', user.email, :style => 'width: 60%;') %>

=====================================
plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
=====================================
--- a/plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
+++ b/plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
@@ -1,3 +1,7 @@
 <%= render :partial => 'folder', :locals => {:f => f} %>
 
-<%= labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %>
+<%= labelled_form_field(_('Default email message:'), text_area(:article, :default_email, :rows => 3, :cols => 64)) %>
+
+<%=labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %>
+
+<%=labelled_check_box(_('Allow users change submissions privacy?'), 'article[allow_visibility_edition]', true, @article.allow_visibility_edition) %>

=====================================
plugins/work_assignment/views/work_assignment_plugin_myprofile/edit_visibility.html.erb
=====================================
--- /dev/null
+++ b/plugins/work_assignment/views/work_assignment_plugin_myprofile/edit_visibility.html.erb
@@ -0,0 +1,24 @@
+<div class="select-visibility-options">
+
+<%= 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) %>
+
+  <div id='edit-article-options'>
+    <%= visibility_options(@article, @tokenized_children) %>
+  </div>
+
+  <% button_bar do %>
+    <%= submit_button :save, _('Save') %>
+    <%= button :cancel, _('Cancel'), @back_to %>
+  <% end %>
+<% end %>
+</div>
+
+<br style='clear: both'/>
+
+<%= javascript_include_tag "article.js" %>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150122/61191b68/attachment-0001.html>


More information about the Noosfero-dev mailing list