From ab6c21314d9436fd0add8c474674202093551d13 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Thu, 12 Mar 2015 21:57:35 +0800 Subject: [PATCH] =?UTF-8?q?#1503=20=E8=80=81=E5=B8=88=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=9A=84=E4=BD=9C=E4=B8=9A=E5=8F=AF=E4=BB=A5=E5=9C=A8=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E5=8A=A8=E6=80=81=E4=B8=AD=E6=98=BE=E7=A4=BA=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 4 +++- app/models/bid.rb | 9 ++++++++- app/models/user.rb | 2 +- lib/redmine.rb | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 8fae547c4..f4cb3b665 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -872,13 +872,15 @@ class CoursesController < ApplicationController "show_course_news" => true, "show_course_messages" => true, "show_bids" => true, - "show_course_journals_for_messages" => true + "show_course_journals_for_messages" => true, + "show_homeworks" => true } @date_to ||= Date.today + 1 # @date_from = (@date_to - @days) > @course.created_at.to_date ? (@date_to - @days) : @course.created_at.to_date #@date_from = @date_to - @days-1.years @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) + @author ||= @course.teacher # 决定显示所用用户或单个用户活动 @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, :with_subprojects => false, diff --git a/app/models/bid.rb b/app/models/bid.rb index e5de47b24..10476b4d3 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -61,14 +61,21 @@ class Bid < ActiveRecord::Base end } + scope :course_visible, lambda {|*args| + includes(:courses).where(Course.allowed_to_condition(args.shift || User.current, :view_homeworks, *args)) + } + acts_as_watchable acts_as_taggable - acts_as_event :title => Proc.new {|o| "#{l(:label_requirement)} ##{o.id}: #{o.name}" }, + acts_as_event :title => Proc.new {|o| "#{l(:label_course_homework)} ##{o.id}: #{o.name}" }, :description => :description, :author => :author, :url => Proc.new {|o| {:controller => 'bids', :action => 'show', :id => o.id}} + acts_as_activity_provider :type => 'homeworks', + :author_key => :author_id + acts_as_activity_provider :find_options => {:include => [:projects, :author]}, :author_key => :author_id diff --git a/app/models/user.rb b/app/models/user.rb index 83e08254c..4c740aad5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -776,7 +776,7 @@ class User < Principal (block_given? ? yield(role, self) : true) } #添加课程相关的权限判断 - elsif context && context.is_a?(Course) + elsif context && context.is_a?(Course) return false unless context.allows_to?(action) # Admin users are authorized for anything else return true if admin? diff --git a/lib/redmine.rb b/lib/redmine.rb index 2fd0c6460..6a74b4d3c 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -119,6 +119,8 @@ Redmine::AccessControl.map do |map| map.permission :course_attachments_download,{:attachments => :download},:belong_to_course => true map.permission :contest_attachments_download,{:attachments => :download},:belong_to_contest => true + map.permission :view_homeworks, {}, :public => true, :read => true + map.course_module :files do |map| # map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin map.permission :view_course_files, {:files => :index, :versions => :download}, :read => true,:belong_to_course => true @@ -480,6 +482,8 @@ Redmine::Activity.map do |activity| activity.register :course_journals_for_messages , :class_name => 'JournalsForMessage' activity.register :course_news, :class_name => 'News' activity.register :course_messages, :default => false, :class_name => 'Message' + + activity.register :homeworks, :class_name => 'Bid' end Redmine::Search.map do |search|