Commit e42003f520c18c8fa0e46a834ceb106ffb942e0c
Committed by
Tallys Martins
1 parent
17c8b3be
Exists in
master
and in
22 other branches
Updated cms upload method on work_assignmet plugin.
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Showing
2 changed files
with
20 additions
and
14 deletions
Show diff stats
plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
| 1 | class WorkAssignmentPluginCmsController < CmsController | 1 | class WorkAssignmentPluginCmsController < CmsController |
| 2 | 2 | ||
| 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
| 4 | - | 4 | + |
| 5 | def upload_files | 5 | def upload_files |
| 6 | @uploaded_files = [] | 6 | @uploaded_files = [] |
| 7 | @article = @parent = check_parent(params[:parent_id]) | 7 | @article = @parent = check_parent(params[:parent_id]) |
| 8 | @email_notification = params[:article_email_notification] | 8 | @email_notification = params[:article_email_notification] |
| 9 | - | 9 | + |
| 10 | @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier | 10 | @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier |
| 11 | if @article | 11 | if @article |
| 12 | record_coming | 12 | record_coming |
| 13 | end | 13 | end |
| 14 | if request.post? && params[:uploaded_files] | 14 | if request.post? && params[:uploaded_files] |
| 15 | params[:uploaded_files].each do |file| | 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 | 16 | + unless file == '' |
| 17 | + @uploaded_files << UploadedFile.create( | ||
| 18 | + { | ||
| 19 | + :uploaded_data => file, | ||
| 20 | + :profile => profile, | ||
| 21 | + :parent => @parent, | ||
| 22 | + :last_changed_by => user, | ||
| 23 | + :author => user, | ||
| 24 | + }, | ||
| 25 | + :without_protection => true | ||
| 26 | + ) | ||
| 27 | + end | ||
| 28 | + end | ||
| 23 | @errors = @uploaded_files.select { |f| f.errors.any? } | 29 | @errors = @uploaded_files.select { |f| f.errors.any? } |
| 24 | if @errors.any? | 30 | if @errors.any? |
| 25 | render :action => 'upload_files', :id => @parent_id | 31 | render :action => 'upload_files', :id => @parent_id |
| @@ -48,7 +54,7 @@ class WorkAssignmentPluginCmsController < CmsController | @@ -48,7 +54,7 @@ class WorkAssignmentPluginCmsController < CmsController | ||
| 48 | @files_paths = [] | 54 | @files_paths = [] |
| 49 | @files_string = params[:self_files_id] | 55 | @files_string = params[:self_files_id] |
| 50 | @files_id_list = @files_string.split(' ') | 56 | @files_id_list = @files_string.split(' ') |
| 51 | - | 57 | + |
| 52 | @files_id_list.each do |file_id| | 58 | @files_id_list.each do |file_id| |
| 53 | @file = environment.articles.find_by_id(file_id) | 59 | @file = environment.articles.find_by_id(file_id) |
| 54 | @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" | 60 | @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" |
| @@ -100,7 +106,7 @@ class WorkAssignmentPluginCmsController < CmsController | @@ -100,7 +106,7 @@ class WorkAssignmentPluginCmsController < CmsController | ||
| 100 | @files_paths = [] | 106 | @files_paths = [] |
| 101 | @files_string = params[:self_files_id] | 107 | @files_string = params[:self_files_id] |
| 102 | @files_id_list = @files_string.split(' ') | 108 | @files_id_list = @files_string.split(' ') |
| 103 | - | 109 | + |
| 104 | @files_id_list.each do |file_id| | 110 | @files_id_list.each do |file_id| |
| 105 | @file = environment.articles.find_by_id(file_id) | 111 | @file = environment.articles.find_by_id(file_id) |
| 106 | @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" | 112 | @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" |
plugins/work_assignment/lib/work_assignment_plugin.rb
| @@ -37,7 +37,7 @@ class WorkAssignmentPlugin < Noosfero::Plugin | @@ -37,7 +37,7 @@ class WorkAssignmentPlugin < Noosfero::Plugin | ||
| 37 | 37 | ||
| 38 | def content_viewer_controller_filters | 38 | def content_viewer_controller_filters |
| 39 | block = proc do | 39 | block = proc do |
| 40 | - path = params[:page].join('/') | 40 | + path = params[:page] |
| 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) |
| @@ -51,7 +51,7 @@ class WorkAssignmentPlugin < Noosfero::Plugin | @@ -51,7 +51,7 @@ class WorkAssignmentPlugin < Noosfero::Plugin | ||
| 51 | :block => block } | 51 | :block => block } |
| 52 | end | 52 | end |
| 53 | 53 | ||
| 54 | - | 54 | + |
| 55 | def upload_files_extra_contents | 55 | def upload_files_extra_contents |
| 56 | proc do | 56 | proc do |
| 57 | if params[:parent_id] | 57 | if params[:parent_id] |
| @@ -60,7 +60,7 @@ class WorkAssignmentPlugin < Noosfero::Plugin | @@ -60,7 +60,7 @@ class WorkAssignmentPlugin < Noosfero::Plugin | ||
| 60 | content = profile.articles.find_by_path(path) | 60 | content = profile.articles.find_by_path(path) |
| 61 | 61 | ||
| 62 | if content.type == "WorkAssignmentPlugin::WorkAssignment" | 62 | if content.type == "WorkAssignmentPlugin::WorkAssignment" |
| 63 | - render :partial => 'work_assignment_form', :locals => { :size => '45'} | 63 | + render :partial => 'work_assignment_form', :locals => { :size => '45'} |
| 64 | end | 64 | end |
| 65 | else | 65 | else |
| 66 | render :partial => 'upload_file_form', :locals => { :size => '45'} | 66 | render :partial => 'upload_file_form', :locals => { :size => '45'} |