From 755e7585964071bc7492e6eb8d1ec71a049cc908 Mon Sep 17 00:00:00 2001 From: nwb Date: Mon, 16 Jun 2014 09:48:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=BE=E7=A8=8B=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=96=87=E4=BB=B6=E5=8A=A8=E6=80=81=E5=92=8C=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 3 ++- app/models/user.rb | 2 +- .../lib/acts_as_activity_provider.rb | 13 ++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index d9ad3915e..175a649c2 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -37,8 +37,9 @@ class Attachment < ActiveRecord::Base acts_as_event :title => :filename, :url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}} - + #课程资源文件 acts_as_activity_provider :type => 'course_files', + :permission => :view_files, :author_key => :author_id, :find_options => {:select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Course.table_name} ON ( #{Attachment.table_name}.container_type='Course' AND #{Attachment.table_name}.container_id = #{Course.table_name}.id )"} diff --git a/app/models/user.rb b/app/models/user.rb index fd4508ce6..0c798eea8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -719,7 +719,7 @@ class User < Principal return @courses_by_role if @courses_by_role @courses_by_role = Hash.new([]) - memberships.each do |membership| + coursememberships.each do |membership| if membership.course membership.roles.each do |role| @courses_by_role[role] = [] unless @courses_by_role.key?(role) 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 95bda9bb0..792f75e56 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 @@ -71,16 +71,15 @@ module Redmine end if provider_options.has_key?(:permission) - scope = scope.scoped(:conditions => Project.allowed_to_condition(user, provider_options[:permission] || :view_project, options)) + if options[:course] + scope = scope.scoped(:conditions => Course.allowed_to_condition(user, provider_options[:permission] || :view_course, options)) + else + scope = scope.scoped(:conditions => Project.allowed_to_condition(user, provider_options[:permission] || :view_project, options)) + end elsif respond_to?(:visible) scope = scope.visible(user, options) elsif options[:course] - if Course.new.methods.include?(event_type.to_s) - 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.scoped(:conditions => Course.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options)) - else - scope = scope.scoped(:conditions =>"1=0") - end + scope = scope.scoped(:conditions => Course.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options)) 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.scoped(:conditions => Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options))