diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 03b626f7d..46fc68184 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -238,6 +238,8 @@ class ApplicationController < ActionController::Base allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global) elsif @course allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @courses, :global => global) + else + allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global) end if allowed diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 99160b0c0..0b05f91d1 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -124,10 +124,19 @@ class AttachmentsController < ApplicationController end respond_to do |format| - if @project.nil? - format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum,@attachment.container) } + # modify by nwb + if @attachment.container_type == 'Course' + if @course.nil? + format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } + else + format.html { redirect_to_referer_or course_path(@course) } + end else - format.html { redirect_to_referer_or project_path(@project)} + if @project.nil? + format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } + else + format.html { redirect_to_referer_or project_path(@project) } + end end format.js @@ -190,9 +199,14 @@ private def find_project @attachment = Attachment.find(params[:id]) # Show 404 if the filename in the url is wrong + # modify by nwb raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename - unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' - @project = @attachment.project + if @attachment.container_type == 'Course' + @course = @attachment.course + else + unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' + @project = @attachment.project + end end rescue ActiveRecord::RecordNotFound render_404 diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 71676467a..d9ad3915e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -193,6 +193,10 @@ class Attachment < ActiveRecord::Base container.try(:project) end + def course + container + end + def visible?(user=User.current) if container_id container && container.attachments_visible?(user) diff --git a/app/views/files/_course_new.html.erb b/app/views/files/_course_new.html.erb index 659543201..960b2d399 100644 --- a/app/views/files/_course_new.html.erb +++ b/app/views/files/_course_new.html.erb @@ -1,7 +1,7 @@
<% if attachmenttypes.any? %> diff --git a/app/views/files/_new.html.erb b/app/views/files/_new.html.erb index 27bd4911a..af65bbcf4 100644 --- a/app/views/files/_new.html.erb +++ b/app/views/files/_new.html.erb @@ -2,7 +2,7 @@ <% versions = project.versions.sort %> <% attachmenttypes = project.attachmenttypes %> <%= error_messages_for 'attachment' %> -<%= form_tag(project_files_path(project), :multipart => true,:remote => false,:method => :post,:name=>"upload_form", :class => "tabular") do %> +<%= form_tag(project_files_path(project), :multipart => true,:remote => true,:method => :post,:name=>"upload_form", :class => "tabular") do %>