From f383f501eceeaa9d98f3446ea4689e6f2c7e58da Mon Sep 17 00:00:00 2001 From: z9hang Date: Mon, 9 Jun 2014 13:47:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9D=83=E9=99=90=E4=BB=A3?= =?UTF-8?q?=E7=A0=81:=E5=88=A4=E6=96=AD=E7=94=A8=E6=88=B7=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E4=B8=BA=E9=A1=B9=E7=9B=AE=E7=9A=84=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E3=80=81=E5=88=A4=E6=96=AD=E7=94=A8=E6=88=B7=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E4=B8=BA=E8=AF=BE=E7=A8=8B=E7=9A=84=E8=80=81=E5=B8=88?= =?UTF-8?q?=E3=80=81=E5=AD=A6=E7=94=9F=E7=94=B1=E6=A0=B9=E6=8D=AErole=5Fid?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=94=B9=E4=B8=BA=E6=A0=B9=E6=8D=AE=E5=85=B6?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softapplications_controller.rb | 13 ++++-- app/helpers/bids_helper.rb | 21 +++++++-- app/helpers/courses_helper.rb | 46 ++++++++++++++----- app/helpers/shares_helper.rb | 12 +++-- app/helpers/user_score_helper.rb | 15 ++++-- 5 files changed, 79 insertions(+), 28 deletions(-) diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index b8d81b108..362a04f57 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -108,11 +108,16 @@ class SoftapplicationsController < ApplicationController # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page'] @membership.each do |membership| unless(membership.project.project_type==1) - membership.member_roles.each{|role| - if(role.role_id == 3) + #membership.member_roles.each{|role| + # if(role.role_id == 3) + # @option << membership.project + # end + #} + + #拥有编辑项目权限的可操作该项目 + if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) @option << membership.project - end - } + end end end diff --git a/app/helpers/bids_helper.rb b/app/helpers/bids_helper.rb index 40cec6edb..a41867c64 100644 --- a/app/helpers/bids_helper.rb +++ b/app/helpers/bids_helper.rb @@ -157,13 +157,24 @@ module BidsHelper end #当前用户是不是指定课程的学生 def is_cur_course_student? course - people = [] - course.members.includes(:user, :roles).each do |member| - if [5,10].include? member.roles.first.id - people << member.user + #people = [] + #course.members.includes(:user, :roles).each do |member| + # if [5,10].include? member.roles.first.id + # people << member.user + # end + #end + #people.include?(User.current) + #修改:能新建占位且不能新建任务的角色判定为学生 + is_student = false + @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + unless(membership.project.project_type==0) + if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false) + is_student = true + end end end - people.include?(User.current) + is_student end # def select_option_helper option diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 5531f3f82..1d268997b 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -137,25 +137,47 @@ module CoursesHelper Course.find_by_extra(try(extra)) end #判断制定用户是不是当前课程的老师 - def is_course_teacher user,course - people = [] - course.members.includes(:roles, :user).each do |member| - role_id = member.roles.first.id - if TeacherRoles.include? role_id - people << member.user + def is_course_teacher (user,course) + #people = [] + #course.members.includes(:roles, :user).each do |member| + # role_id = member.roles.first.id + # if TeacherRoles.include? role_id + # people << member.user + # end + #end + #people.include?(user) + #修改为根据用户是否有发布任务的权限来判断用户是否是课程的老师 + is_teacher = false + @membership = user.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + unless(membership.project.project_type==0) + if user.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) + is_teacher = true + end end end - people.include?(user) + is_teacher end #当前用户是不是指定课程的学生 def is_cur_course_student? course - people = [] - course.members.includes(:roles, :user).each do |member| - if StudentRoles.include? member.roles.first.id - people << member.user + #people = [] + #course.members.includes(:roles, :user).each do |member| + # if StudentRoles.include? member.roles.first.id + # people << member.user + # end + #end + #people.include?(User.current) + #修改:能新建占位且不能新建任务的角色判定为学生 + is_student = false + @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + unless(membership.project.project_type==0) + if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false) + is_student = true + end end end - people.include?(User.current) + is_student end #获取当前用户在指定作业下提交的作业的集合 def cur_user_homework_for_bid bid diff --git a/app/helpers/shares_helper.rb b/app/helpers/shares_helper.rb index f2cbc6ab9..9e0828133 100644 --- a/app/helpers/shares_helper.rb +++ b/app/helpers/shares_helper.rb @@ -4,11 +4,15 @@ def options_from_select_project(user) @option = [] @membership.each do |membership| unless(membership.project.project_type==1) - membership.member_roles.each{|role| - if(role.role_id == 3) + #membership.member_roles.each{|role| + # if(role.role_id == 3) + # @option << membership.project + # end + #} + #拥有编辑项目权限的可操作该项目 + if user.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) @option << membership.project - end - } + end end end options_for_select(@option) diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index d9ab8730a..3101b823c 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -228,12 +228,21 @@ module UserScoreHelper isManager = 0 members = Member.where('user_id = ?', user.id) members.each do |m| - roles = m.member_roles - roles.each do |r| - if r.role_id == 3 + #roles = m.member_roles + #roles.each do |r| + # if r.role_id == 3 + # isManager = 1 + # end + #end + @membership = m.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + #拥有编辑项目权限的可操作该项目 + if m.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) isManager = 1 end end + + end level = 0