Commit 938cbff344dd0978039ffde4d0fa99da8e997044
Committed by
Tallys Martins
1 parent
46080e93
Exists in
staging
and in
42 other branches
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@gmail.com> Signed-off-by: Eduardo Vital <vitaldu@gmail.com> Signed-off-by: Hebert Douglas <hebertdougl@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com> (AI2967)
Showing
15 changed files
with
207 additions
and
14 deletions
Show diff stats
app/views/cms/upload_files.html.erb
| @@ -19,6 +19,15 @@ | @@ -19,6 +19,15 @@ | ||
| 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| %> | ||
| 23 | - <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> | 22 | +<% if @plugins.dispatch(:upload_files_extra_contents).size == 0 %> |
| 23 | + <% form_for('uploaded_file', :url => { :action => 'upload_files' }, :html => {:multipart => true}) do |f| %> | ||
| 24 | + | ||
| 25 | + <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> | ||
| 26 | + | ||
| 27 | + <% end %> | ||
| 28 | +<% else %> | ||
| 29 | + | ||
| 30 | + <%= @plugins.dispatch(:upload_files_extra_contents).collect { |content| instance_eval(&content) }.join("") %> | ||
| 31 | + | ||
| 24 | <% end %> | 32 | <% end %> |
| 33 | + |
plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
0 → 100644
| @@ -0,0 +1,95 @@ | @@ -0,0 +1,95 @@ | ||
| 1 | +class WorkAssignmentPluginCmsController < CmsController | ||
| 2 | + | ||
| 3 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | ||
| 4 | + | ||
| 5 | + def upload_files | ||
| 6 | + @uploaded_files = [] | ||
| 7 | + @article = @parent = check_parent(params[:parent_id]) | ||
| 8 | + @email_notification = params[:article_email_notification] | ||
| 9 | + | ||
| 10 | + @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier | ||
| 11 | + if @article | ||
| 12 | + record_coming | ||
| 13 | + end | ||
| 14 | + if request.post? && params[:uploaded_files] | ||
| 15 | + params[:uploaded_files].each do |file| | ||
| 16 | + if file != '' | ||
| 17 | + u = UploadedFile.new(:uploaded_data => file, :profile => profile, :parent => @parent) | ||
| 18 | + u.last_changed_by = user | ||
| 19 | + u.save! | ||
| 20 | + @uploaded_files << u | ||
| 21 | + end | ||
| 22 | + end | ||
| 23 | + @errors = @uploaded_files.select { |f| f.errors.any? } | ||
| 24 | + if @errors.any? | ||
| 25 | + render :action => 'upload_files', :id => @parent_id | ||
| 26 | + else | ||
| 27 | + if @back_to | ||
| 28 | + if @email_notification == 'true' | ||
| 29 | + redirect_to :controller => 'work_assignment_plugin_cms', :action => 'send_email', :id => @parent.id, :files_id => @uploaded_files, :confirm => true | ||
| 30 | + else | ||
| 31 | + redirect_to @back_to | ||
| 32 | + end | ||
| 33 | + elsif @parent | ||
| 34 | + redirect_to :controller => 'cms', :action => 'view', :id => @parent.id | ||
| 35 | + else | ||
| 36 | + redirect_to :controller => 'cms', :action => 'index' | ||
| 37 | + end | ||
| 38 | + end | ||
| 39 | + end | ||
| 40 | + end | ||
| 41 | + | ||
| 42 | + def send_email | ||
| 43 | + @parent = check_parent(params[:id]) | ||
| 44 | + @files_id_list = params[:files_id] | ||
| 45 | + @target = ['',@parent.url[:profile], @parent.url[:page]].join('/') | ||
| 46 | + @contact | ||
| 47 | + if request.post? && params[:confirm] == 'true' | ||
| 48 | + @files_paths = [] | ||
| 49 | + @files_id_list = params[:self_files_id] | ||
| 50 | + | ||
| 51 | + @files_id_list.each do |file_id| | ||
| 52 | + @file = environment.articles.find_by_id(file_id) | ||
| 53 | + @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/ #{@file.url[:profile]}/#{@file.path}" | ||
| 54 | + @files_paths << @real_file_url | ||
| 55 | + unless params[:contact][:message].include? "#{@real_file_url}" | ||
| 56 | + params[:contact][:message] += "<br> Clique <a href='#{@real_file_url}'>aqui</a> para acessar o arquivo ou acesse pela URL: <br>" | ||
| 57 | + params[:contact][:message] += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" | ||
| 58 | + end | ||
| 59 | + end | ||
| 60 | + @message = "AVISO: O aluno deve imprimir este email e entrega-lo na secretaria como comprovante do envio!" | ||
| 61 | + unless params[:contact][:message].include? "#{@message}" | ||
| 62 | + params[:contact][:message] += "<br><br>#{@message}" | ||
| 63 | + end | ||
| 64 | + | ||
| 65 | + @contact = user.build_contact(profile, params[:contact]) | ||
| 66 | + if @contact.deliver | ||
| 67 | + session[:notice] = _('Contact successfully sent') | ||
| 68 | + redirect_to @target | ||
| 69 | + else | ||
| 70 | + session[:notice] = _('Contact not sent') | ||
| 71 | + end | ||
| 72 | + elsif request.post? && params[:confirm] == 'false' | ||
| 73 | + if @target | ||
| 74 | + session[:notice] = _('Email not sent') | ||
| 75 | + redirect_to @target | ||
| 76 | + elsif @parent | ||
| 77 | + redirect_to :action => 'view', :id => @parent.id, :paths_list => @paths_list | ||
| 78 | + else | ||
| 79 | + redirect_to :action => 'index' | ||
| 80 | + end | ||
| 81 | + else | ||
| 82 | + @contact = user.build_contact(profile) | ||
| 83 | + end | ||
| 84 | + end | ||
| 85 | + | ||
| 86 | + def destroy | ||
| 87 | + @article = profile.articles.find(params[:id]) | ||
| 88 | + if request.post? | ||
| 89 | + @article.destroy | ||
| 90 | + session[:notice] = _("\"#{@article.name}\" was removed.") | ||
| 91 | + referer = Rails.application.routes.recognize_path URI.parse(request.referer).path rescue nil | ||
| 92 | + redirect_to referer | ||
| 93 | + end | ||
| 94 | + end | ||
| 95 | +end | ||
| 0 | \ No newline at end of file | 96 | \ No newline at end of file |
plugins/work_assignment/lib/work_assignment_plugin.rb
| @@ -34,10 +34,10 @@ class WorkAssignmentPlugin < Noosfero::Plugin | @@ -34,10 +34,10 @@ class WorkAssignmentPlugin < Noosfero::Plugin | ||
| 34 | !content.profile.members.include?(context.send(:user)) | 34 | !content.profile.members.include?(context.send(:user)) |
| 35 | end | 35 | end |
| 36 | end | 36 | end |
| 37 | - | 37 | +=begin |
| 38 | def content_viewer_controller_filters | 38 | def content_viewer_controller_filters |
| 39 | block = proc do | 39 | block = proc do |
| 40 | - path = params[:page] | 40 | + path = params[:page].join('/') |
| 41 | content = profile.articles.find_by_path(path) | 41 | content = profile.articles.find_by_path(path) |
| 42 | 42 | ||
| 43 | if WorkAssignmentPlugin.is_submission?(content) && !WorkAssignmentPlugin.can_download_submission?(user, content) | 43 | if WorkAssignmentPlugin.is_submission?(content) && !WorkAssignmentPlugin.can_download_submission?(user, content) |
| @@ -50,5 +50,11 @@ class WorkAssignmentPlugin < Noosfero::Plugin | @@ -50,5 +50,11 @@ class WorkAssignmentPlugin < Noosfero::Plugin | ||
| 50 | :options => {:only => 'view_page'}, | 50 | :options => {:only => 'view_page'}, |
| 51 | :block => block } | 51 | :block => block } |
| 52 | end | 52 | end |
| 53 | +=end | ||
| 54 | + def upload_files_extra_contents | ||
| 55 | + proc do | ||
| 56 | + render :partial => 'work_assignment_form', :locals => { :size => '45'} | ||
| 57 | + end | ||
| 58 | + end | ||
| 53 | 59 | ||
| 54 | end | 60 | end |
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
| 1 | module WorkAssignmentPlugin::Helper | 1 | module WorkAssignmentPlugin::Helper |
| 2 | + include CmsHelper | ||
| 2 | def display_submissions(work_assignment, user) | 3 | def display_submissions(work_assignment, user) |
| 3 | return if work_assignment.submissions.empty? | 4 | return if work_assignment.submissions.empty? |
| 4 | content_tag('table', | 5 | content_tag('table', |
| @@ -26,9 +27,16 @@ module WorkAssignmentPlugin::Helper | @@ -26,9 +27,16 @@ module WorkAssignmentPlugin::Helper | ||
| 26 | def display_submission(submission, user) | 27 | def display_submission(submission, user) |
| 27 | content_tag('tr', | 28 | content_tag('tr', |
| 28 | content_tag('td', link_to_submission(submission, user)) + | 29 | content_tag('td', link_to_submission(submission, user)) + |
| 29 | - content_tag('td', time_format(submission.created_at), :colspan => 3), | 30 | + content_tag('td', time_format(submission.created_at))+ |
| 31 | + content_tag('td', '') + | ||
| 32 | + content_tag('td', | ||
| 33 | + if submission.parent.parent.allow_post_content?(user) | ||
| 34 | + display_delete_button(submission) | ||
| 35 | + end | ||
| 36 | + ), | ||
| 30 | :class => "submission-from-#{submission.parent.id}", | 37 | :class => "submission-from-#{submission.parent.id}", |
| 31 | :style => 'display: none' | 38 | :style => 'display: none' |
| 39 | + #content_tag('button', _('Destroy file'), :class => 'button icon-delete ', | ||
| 32 | ) | 40 | ) |
| 33 | end | 41 | end |
| 34 | 42 | ||
| @@ -56,4 +64,7 @@ module WorkAssignmentPlugin::Helper | @@ -56,4 +64,7 @@ module WorkAssignmentPlugin::Helper | ||
| 56 | time.strftime("%Y-%m-%d#{hour+minutes+h}") | 64 | time.strftime("%Y-%m-%d#{hour+minutes+h}") |
| 57 | end | 65 | end |
| 58 | 66 | ||
| 67 | + def display_delete_button(article) | ||
| 68 | + expirable_button article, :delete, _('Delete'), {:controller =>'work_assignment_plugin_cms', :action => 'destroy', :id => article.id }, :method => :post, :confirm => delete_article_message(article) | ||
| 69 | + end | ||
| 59 | end | 70 | end |
plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
| 1 | class WorkAssignmentPlugin::WorkAssignment < Folder | 1 | class WorkAssignmentPlugin::WorkAssignment < Folder |
| 2 | 2 | ||
| 3 | settings_items :publish_submissions, :type => :boolean, :default => false | 3 | settings_items :publish_submissions, :type => :boolean, :default => false |
| 4 | - | ||
| 5 | - attr_accessible :publish_submissions | 4 | + settings_items :email_notification, :type => :boolean, :default => false |
| 6 | 5 | ||
| 7 | def self.icon_name(article = nil) | 6 | def self.icon_name(article = nil) |
| 8 | 'work-assignment' | 7 | 'work-assignment' |
| @@ -29,7 +28,7 @@ class WorkAssignmentPlugin::WorkAssignment < Folder | @@ -29,7 +28,7 @@ class WorkAssignmentPlugin::WorkAssignment < Folder | ||
| 29 | end | 28 | end |
| 30 | 29 | ||
| 31 | def to_html(options = {}) | 30 | def to_html(options = {}) |
| 32 | - proc do | 31 | + lambda do |
| 33 | render :file => 'content_viewer/work_assignment.html.erb' | 32 | render :file => 'content_viewer/work_assignment.html.erb' |
| 34 | end | 33 | end |
| 35 | end | 34 | end |
plugins/work_assignment/public/show_notification_email.js
0 → 100644
| @@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
| 1 | +jQuery(function($) { | ||
| 2 | + function show_hide_token_input() { | ||
| 3 | + if($('input:checkbox[name="article_email_notification"]').attr('checked')){ | ||
| 4 | + $("#email_notifications").css('display', 'inline-block');} | ||
| 5 | + else | ||
| 6 | + $("#email_notifications").css('display', 'none'); | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + show_hide_token_input(); | ||
| 10 | + //Hide / Show the text area | ||
| 11 | + $("#checkbox-0").click(show_hide_token_input); | ||
| 12 | +}); | ||
| 0 | \ No newline at end of file | 13 | \ No newline at end of file |
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 | + | ||
| 4 | +#email_notifications{ | ||
| 5 | + padding: 10px 20px; | ||
| 6 | + display: inline-block; | ||
| 7 | +} | ||
| 8 | + | ||
| 9 | +#email_notifications label{ | ||
| 10 | + width: 117px; | ||
| 11 | + display: block; | ||
| 12 | + float: left; | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +#email_notifications input, #email_notifications textarea{ | ||
| 16 | + display: block; | ||
| 17 | + float: left; | ||
| 18 | + resize: vertical; | ||
| 19 | + width: 330px; | ||
| 20 | + line-height: 1.5em; | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +body.action-cms-upload_files #uploaded_files p:nth-child(3), | ||
| 24 | +body.action-cms-upload_files #uploaded_files p:nth-child(5){ | ||
| 25 | + display: none; | ||
| 26 | + } |
plugins/work_assignment/test/functional/cms_controller_test.rb
| @@ -22,7 +22,7 @@ class CmsControllerTest < ActionController::TestCase | @@ -22,7 +22,7 @@ class CmsControllerTest < ActionController::TestCase | ||
| 22 | 22 | ||
| 23 | get :upload_files, :profile => organization.identifier, :parent_id => work_assignment.id | 23 | get :upload_files, :profile => organization.identifier, :parent_id => work_assignment.id |
| 24 | assert_response :forbidden | 24 | assert_response :forbidden |
| 25 | - assert_template 'access_denied' | 25 | + assert_template 'access_denied.rhtml' |
| 26 | 26 | ||
| 27 | organization.add_member(person) | 27 | organization.add_member(person) |
| 28 | 28 |
plugins/work_assignment/test/functional/content_viewer_controller_test.rb
| @@ -29,13 +29,13 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -29,13 +29,13 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
| 29 | submission = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => folder) | 29 | submission = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => folder) |
| 30 | WorkAssignmentPlugin.stubs(:can_download_submission?).returns(false) | 30 | WorkAssignmentPlugin.stubs(:can_download_submission?).returns(false) |
| 31 | 31 | ||
| 32 | - get :view_page, :profile => organization.identifier, :page => submission.path | 32 | + get :view_page, :profile => organization.identifier, :page => submission.explode_path |
| 33 | assert_response :forbidden | 33 | assert_response :forbidden |
| 34 | - assert_template 'access_denied' | 34 | + assert_template 'access_denied.rhtml' |
| 35 | 35 | ||
| 36 | WorkAssignmentPlugin.stubs(:can_download_submission?).returns(true) | 36 | WorkAssignmentPlugin.stubs(:can_download_submission?).returns(true) |
| 37 | 37 | ||
| 38 | - get :view_page, :profile => organization.identifier, :page => submission.path | 38 | + get :view_page, :profile => organization.identifier, :page => submission.explode_path |
| 39 | assert_response :success | 39 | assert_response :success |
| 40 | end | 40 | end |
| 41 | 41 |
plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
| @@ -38,7 +38,7 @@ class WorkAssignmentTest < ActiveSupport::TestCase | @@ -38,7 +38,7 @@ class WorkAssignmentTest < 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_equal author_folder, submission.parent | 41 | + assert 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/views/cms/_notify_checkbox.html.erb
0 → 100644
plugins/work_assignment/views/cms/_work_assignment_form.html.erb
0 → 100644
| @@ -0,0 +1,4 @@ | @@ -0,0 +1,4 @@ | ||
| 1 | +<%= form_for('uploaded_file', :url => { :controller => 'work_assignment_plugin_cms', :action => 'upload_files' }, :html => {:multipart => true}) do |f| %> | ||
| 2 | + <%= render :partial => 'notify_checkbox', :locals => { :size => '45'} %> | ||
| 3 | + <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> | ||
| 4 | +<% end %> | ||
| 0 | \ No newline at end of file | 5 | \ No newline at end of file |
plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
| 1 | <%= render :partial => 'folder', :locals => {:f => f} %> | 1 | <%= render :partial => 'folder', :locals => {:f => f} %> |
| 2 | 2 | ||
| 3 | -<%= labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %> | 3 | +<%#labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %> |
plugins/work_assignment/views/work_assignment_plugin_cms/_work_assignment_form.html.erb
0 → 100644
| @@ -0,0 +1,5 @@ | @@ -0,0 +1,5 @@ | ||
| 1 | +<% form_for('uploaded_file', :url => { :controller => 'work_assignment_plugin_cms', :action => 'upload_files' }, :html => {:multipart => true}) do |f| %> | ||
| 2 | + <%= render :partial => 'notify_checkbox', :locals => { :size => '45'} %> | ||
| 3 | + <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> | ||
| 4 | + x | ||
| 5 | +<% end %> | ||
| 0 | \ No newline at end of file | 6 | \ No newline at end of file |
plugins/work_assignment/views/work_assignment_plugin_cms/send_email.html.erb
0 → 100644
| @@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
| 1 | + | ||
| 2 | +<%= error_messages_for 'contact' %> | ||
| 3 | + | ||
| 4 | +<%=labelled_form_for :contact do |f| %> | ||
| 5 | + <%= hidden_field_tag(:confirm, 'false') %> | ||
| 6 | + <%= hidden_field_tag(:self_files_id, @files_id_list) %> | ||
| 7 | + | ||
| 8 | + <%= required_fields_message %> | ||
| 9 | + | ||
| 10 | + <%= required f.text_field(:subject) %> | ||
| 11 | + <%# required f.text_field(:dest) %> | ||
| 12 | + <%= required f.text_field(:name) %> | ||
| 13 | + | ||
| 14 | + <%= render :file => 'shared/tiny_mce' %> | ||
| 15 | + <%= required f.text_area(:message, :class => 'mceEditor') %> | ||
| 16 | + | ||
| 17 | + <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> | ||
| 18 | + | ||
| 19 | + <%= submit_button(:send, _('Send'), :onclick => "$('confirm').value = 'true'") %> | ||
| 20 | + <%= submit_button(:cancel, _('Cancel'), :onclick =>"$('confirm').value = 'false'") %> | ||
| 21 | +<% end %> |