diff --git a/Gemfile b/Gemfile index 3431ad649..e5f2a7054 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,7 @@ group :test do gem "mocha", "~> 0.13.3" gem 'capybara', '~> 2.0.0' gem 'nokogiri', '< 1.6.0' + gem 'factory_girl' platforms :mri, :mingw do group :rmagick do @@ -43,7 +44,7 @@ group :development, :test do gem 'spork-testunit' gem 'guard-spork' gem 'guard-test', '~> 1.0.0' - #gem 'ruby-prof' + gem 'ruby-prof' unless RUBY_PLATFORM =~ /w32/ gem 'pry' gem 'pry-nav' end diff --git a/Gemfile.lock b/Gemfile.lock index 5d5f167ca..4159a32a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -78,6 +78,8 @@ GEM coffee-script-source (1.7.1) erubis (2.7.0) execjs (2.2.1) + factory_girl (4.4.0) + activesupport (>= 3.0.0) fastercsv (1.5.5) ffi (1.9.3) ffi (1.9.3-x86-mingw32) @@ -247,6 +249,7 @@ DEPENDENCIES capybara (~> 2.0.0) coderay (~> 1.0.6) coffee-rails (~> 3.2.1) + factory_girl fastercsv (~> 1.5.0) guard-rails guard-spork diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index b283b4792..4964bf6a6 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -55,32 +55,35 @@ class AttachmentsController < ApplicationController candown = false if @attachment.container.has_attribute?(:project) && @attachment.container.project project = @attachment.container.project - candown= User.current.member_of?(project) + candown= User.current.member_of?(project) || (project.is_public==1 && @attachment.is_public == 1) elsif @attachment.container.is_a?(Project) project = @attachment.container - candown= User.current.member_of?(project) + candown= User.current.member_of?(project) || (project.is_public==1 && @attachment.is_public == 1) elsif @attachment.container.has_attribute?(:course) && @attachment.container.course course = @attachment.container.course - candown= User.current.member_of_course?(course) + candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) elsif @attachment.container.is_a?(Course) course = @attachment.container - candown= User.current.member_of_course?(course) + candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) elsif @attachment.container.class.to_s=="HomeworkAttach" && @attachment.container.bid.reward_type == 3 candown = true + else + candown = @attachment.is_public == 1 end if candown || User.current.admin? @attachment.increment_download + + if stale?(:etag => @attachment.digest) + # images are sent inline + send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), + :type => detect_content_type(@attachment), + :disposition => (@attachment.image? ? 'inline' : 'attachment') + end + else render_403 :message => :notice_not_authorized end - - if stale?(:etag => @attachment.digest) - # images are sent inline - send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), - :type => detect_content_type(@attachment), - :disposition => (@attachment.image? ? 'inline' : 'attachment') - end rescue => e redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html" end diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb index f34e72402..ae9336161 100644 --- a/app/controllers/stores_controller.rb +++ b/app/controllers/stores_controller.rb @@ -38,7 +38,7 @@ class StoresController < ApplicationController LIMIT = 12 unless const_defined?(:LIMIT) def index @projects_attach = project_classification(0).take(LIMIT) - @courses_attach = Attachment.includes(:course).where("courses.is_public = ?", 1). + @courses_attach = Attachment.includes(:course).where("courses.is_public = 1"). where(container_type: 'Course'). limit(LIMIT) # @projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1). diff --git a/app/helpers/stores_helper.rb b/app/helpers/stores_helper.rb index 0c7fdac43..b4cd47eb1 100644 --- a/app/helpers/stores_helper.rb +++ b/app/helpers/stores_helper.rb @@ -16,6 +16,8 @@ module StoresHelper news_path(container) when 'Project' project_files_path(container) + when 'Course' + course_files_path(container) when 'Version' # version_path(container) project_files_path(container.project) diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index d9913539f..a1547bc2b 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -11,7 +11,9 @@
<%= link_to(l(:label_upload_files), 'javascript:void(0);', :class => 'icon m5p5 button_submit', :onclick => "$('#relation_file_div').slideUp();$('#upload_file_div').slideToggle('slow');") if User.current.allowed_to?(:manage_files, @course) %> <%= link_to(l(:label_relation_files), 'javascript:void(0);', :onclick => "$('#upload_file_div').slideUp();$('#relation_file_div').slideToggle();", :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @course) %> - +

+
+ <% if attachmenttypes.any? %>       @@ -24,7 +26,7 @@ <%= select_tag "attach_sufix_browse", content_tag(:option, l(:attachment_all), :value => '0') +options_for_select(sufixtypes), :onchange => "course_attachment_contenttypes_searchex(this.value)" %> <% end %> - +
diff --git a/app/views/files/_project_file.html.erb b/app/views/files/_project_file.html.erb index 1212db052..67067a638 100644 --- a/app/views/files/_project_file.html.erb +++ b/app/views/files/_project_file.html.erb @@ -11,7 +11,9 @@
<%= link_to(l(:label_upload_files), 'javascript:void(0);', :class => 'icon m5p5 button_submit', :onclick => "$('#relation_file_div').slideUp();$('#upload_file_div').slideToggle('slow');") if User.current.allowed_to?(:manage_files, @project) %> <%= link_to(l(:label_relation_files), 'javascript:void(0);', :onclick => "$('#upload_file_div').slideUp();$('#relation_file_div').slideToggle();", :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @project) %> - +

+
+ <% if attachmenttypes.any? %>       @@ -24,6 +26,7 @@ <%= select_tag "attach_sufix_browse", content_tag(:option, l(:attachment_all), :value => '0') +options_for_select(sufixtypes), :onchange => "attachment_contenttypes_searchex(this.value)" %> <% end %> +