From 59051972e16962cd6dcbe05554d72c45870eb337 Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 11 Jun 2014 15:52:47 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E8=AF=BE=E7=A8=8B=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E5=88=A0=E9=99=A4=202.=E4=BF=AE=E6=94=B9=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E8=B5=84=E6=BA=90=E4=B8=8A=E4=BC=A0=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 ++ app/controllers/attachments_controller.rb | 24 +++++++++++++++---- app/models/attachment.rb | 4 ++++ app/views/files/_course_new.html.erb | 2 +- app/views/files/_new.html.erb | 2 +- app/views/files/create.js.erb | 4 ++++ .../lib/acts_as_activity_provider.rb | 4 +++- 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 03b626f7..46fc6818 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 99160b0c..0b05f91d 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 71676467..d9ad3915 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 65954320..960b2d39 100644 --- a/app/views/files/_course_new.html.erb +++ b/app/views/files/_course_new.html.erb @@ -1,7 +1,7 @@

<%=l(:label_attachment_new)%>

<% attachmenttypes = course.attachmenttypes %> <%= error_messages_for 'attachment' %> -<%= form_tag(course_files_path(course), :multipart => true,:remote => false,:method => :post,:name=>"upload_form", :class => "tabular") do %> +<%= form_tag(course_files_path(course), :multipart => true,:remote => true,:method => :post,:name=>"upload_form", :class => "tabular") do %>

<% if attachmenttypes.any? %> diff --git a/app/views/files/_new.html.erb b/app/views/files/_new.html.erb index 27bd4911..af65bbcf 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 %>

diff --git a/app/views/files/create.js.erb b/app/views/files/create.js.erb index 443fdfec..c8a250fe 100644 --- a/app/views/files/create.js.erb +++ b/app/views/files/create.js.erb @@ -25,6 +25,10 @@ $('#put-tag-form #name').val(""); $("#attachments_fields").children().remove(); $("#upload_file_count").text("未上传文件"); $('#upload_file_div').slideToggle('slow'); +<%if @project%> $("#all_browse_div").html('<%= j(render partial: "show_all_attachment")%>'); +<%elsif @course%> +$("#all_browse_div").html('<%= j(render partial: "course_show_all_attachment")%>'); +<%end%> <% end %> diff --git a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb index 23984840..c719629a 100644 --- a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb +++ b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb @@ -118,6 +118,8 @@ module Redmine scope = scope.visible(user1, options) elsif provider_options.has_key?(:func) && provider_options[:func].eql?('memos') scope = scope + elsif event_type.to_s == 'course_files' + scope = scope else ActiveSupport::Deprecation.warn "acts_as_activity_provider with implicit :permission option is deprecated. Add a visible scope to the #{self.name} model or use explicit :permission option." # scope = scope @@ -125,7 +127,7 @@ module Redmine end scope.all(provider_options[:find_options].dup) end - + end end end