1.优化课程通知动态和权限判断

2.优化课程通知讨论区动态和权限判断
This commit is contained in:
nwb 2014-06-16 10:38:38 +08:00
parent 755e758596
commit 59a261d96d
6 changed files with 18 additions and 7 deletions

View File

@ -588,6 +588,7 @@ class CoursesController < ApplicationController
has = { has = {
"show_course_files" => true, "show_course_files" => true,
"show_course_news" => true,
"show_course_messages" => true, "show_course_messages" => true,
"show_bids" => true, "show_bids" => true,
"show_course_journals_for_messages" => true "show_course_journals_for_messages" => true
@ -599,7 +600,7 @@ class CoursesController < ApplicationController
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
:with_subprojects => false, :with_subprojects => false,
:author => @author) :author => @author)
@activity.scope_select {|t| !has["show_#{t}"].nil?} @activity.scope_select {|t| has["show_#{t}"]}
events = @activity.events(@date_from, @date_to) events = @activity.events(@date_from, @date_to)
@offset, @limit = api_offset_and_limit({:limit => 10}) @offset, @limit = api_offset_and_limit({:limit => 10})

View File

@ -67,6 +67,10 @@ class Message < ActiveRecord::Base
includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args)) includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
} }
scope :course_visible, lambda {|*args|
includes(:board => :course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_messages, *args))
}
safe_attributes 'subject', 'content' safe_attributes 'subject', 'content'
safe_attributes 'locked', 'sticky', 'board_id', safe_attributes 'locked', 'sticky', 'board_id',

View File

@ -38,7 +38,7 @@ class News < ActiveRecord::Base
#added by nwb #added by nwb
#课程新闻独立于项目 #课程新闻独立于项目
acts_as_activity_provider :type => 'course_news', acts_as_activity_provider :type => 'course_news',
:find_options => {:include => [:project, :author]}, :find_options => {:include => [:course, :author]},
:author_key => :author_id :author_key => :author_id
acts_as_watchable acts_as_watchable
@ -52,7 +52,7 @@ class News < ActiveRecord::Base
} }
scope :course_visible, lambda {|*args| scope :course_visible, lambda {|*args|
includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_news, *args)) includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_news, *args))
} }
safe_attributes 'title', 'summary', 'description' safe_attributes 'title', 'summary', 'description'

View File

@ -45,6 +45,8 @@ class AddCourseRoles < ActiveRecord::Migration
role.permissions.append(:search_course ) role.permissions.append(:search_course )
end end
role.permissions.append(:view_course_files ) role.permissions.append(:view_course_files )
role.permissions.append(:view_course_journals_for_messages )
role.permissions.append(:view_course_messages )
role.save role.save
end end
end end

View File

@ -77,7 +77,11 @@ module Redmine
scope = scope.scoped(:conditions => Project.allowed_to_condition(user, provider_options[:permission] || :view_project, options)) scope = scope.scoped(:conditions => Project.allowed_to_condition(user, provider_options[:permission] || :view_project, options))
end end
elsif respond_to?(:visible) elsif respond_to?(:visible)
if options[:course]
scope = scope.course_visible(user, options)
else
scope = scope.visible(user, options) scope = scope.visible(user, options)
end
elsif options[:course] elsif options[:course]
scope = scope.scoped(:conditions => Course.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options)) scope = scope.scoped(:conditions => Course.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options))
else else

View File

@ -106,7 +106,7 @@ Redmine::AccessControl.map do |map|
map.permission :edit_course, {:courses => [:settings, :edit, :update]}, :require => :member map.permission :edit_course, {:courses => [:settings, :edit, :update]}, :require => :member
map.permission :close_course, {:courses => [:close, :reopen]}, :require => :member, :read => true map.permission :close_course, {:courses => [:close, :reopen]}, :require => :member, :read => true
map.permission :select_course_modules, {:courses => :modules}, :require => :member map.permission :select_course_modules, {:courses => :modules}, :require => :member
map.permission :view_course_journals_for_messages, {:gantts => [:show, :update]}, :read => true map.permission :view_course_journals_for_messages, {:courses => :feedback}, :require => :member,:read => true
map.course_module :files do |map| map.course_module :files do |map|
map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin
@ -114,7 +114,7 @@ Redmine::AccessControl.map do |map|
end end
map.course_module :news do |map| map.course_module :news do |map|
map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member
map.permission :view_news, {:news => [:index, :show]}, :public => true, :read => true map.permission :view_course_news, {:news => [:index, :show]}, :public => true, :read => true
map.permission :comment_news, {:comments => :create} map.permission :comment_news, {:comments => :create}
end end
#作业模块权限 #作业模块权限
@ -124,7 +124,7 @@ Redmine::AccessControl.map do |map|
map.course_module :boards do |map| map.course_module :boards do |map|
map.permission :manage_boards, {:boards => [:new, :create, :edit, :update, :destroy]}, :require => :member map.permission :manage_boards, {:boards => [:new, :create, :edit, :update, :destroy]}, :require => :member
map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true, :read => true map.permission :view_course_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true, :read => true
map.permission :add_messages, {:messages => [:new, :reply, :quote]} map.permission :add_messages, {:messages => [:new, :reply, :quote]}
map.permission :edit_messages, {:messages => :edit}, :require => :member map.permission :edit_messages, {:messages => :edit}, :require => :member
map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin