diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 78ac4d208..54346c0cc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -236,13 +236,7 @@ class ApplicationController < ActionController::Base # Authorize the user for the requested action def authorize(ctrl = params[:controller], action = params[:action], global = false) #modify by NWB - if @project - 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 + allowed = authorize_allowed(params[:controller], params[:action],global) if allowed true @@ -255,6 +249,17 @@ class ApplicationController < ActionController::Base end end + def authorize_allowed(ctrl = params[:controller], action = params[:action], global = false) + #modify by NWB + if @project + 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 + allowed + end def authorize_attachment_download(ctrl = params[:controller], action = params[:action], global = false) case @attachment.container_type when "Memo" diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 12852c63d..e0d7feff5 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -213,11 +213,12 @@ class CoursesController < ApplicationController q = "#{params[:name].strip}" #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? if params[:incourse] - @results = searchStudent_by_name(@course, q) + @results = searchmember_by_name(@@member_scores, q) elsif params[:ingroup] @group = CourseGroup.find(params[:search_group_id]) - @results = searchgroupstudent_by_name(@group, @course, q) + @results = @results =searchgroupmember_by_name(@@member_scores, @group, q) end + @result_count = @results.count @results = paginateHelper @results @@ -233,8 +234,7 @@ class CoursesController < ApplicationController end @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true - @members = searchStudent(@course) - @membercount = @members.count + @course_groups = @course.course_groups end @@ -243,8 +243,7 @@ class CoursesController < ApplicationController @subPage_title = l :label_student_list @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true - @members = searchStudent(@course) - @membercount = @members.count + @course_groups = @course.course_groups end @@ -257,10 +256,28 @@ class CoursesController < ApplicationController end @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true - @members = searchStudent(@course) - @membercount = @members.count + @course_groups = @course.course_groups end + + def valid_ajax + req = Hash.new(false) + req[:message] = '' + + valid_attr = params[:valid] + valid_value = params[:value] + + faker = CourseGroup.new + + if valid_attr.eql?('name') + faker.name = valid_value + faker.valid? + req[:valid] = faker.errors[:name].blank? + req[:message] = faker.errors[:name] + end + req[:message] = l(:modal_valid_passing) if req[:message].blank? + render :json => req + end def join_group @subPage_title = l :label_student_list group = CourseGroup.find(params[:object_id]) @@ -292,26 +309,18 @@ class CoursesController < ApplicationController @is_remote = true if params[:group_id] && params[:group_id] != "0" @group = CourseGroup.find(params[:group_id]) - @results = searchStudent_by_group(@group, @course) + @results = @@member_scores.find_all {|mem| mem.course_group_id == group.id} else - @results = searchStudent(@course) + @results = @@member_scores end @@result = @results + @members = searchStudent(@course) @membercount = @members.count @results = paginateHelper @results end - def search_group_members group - @subPage_title = l :label_student_list - @render_file = 'member_list' - @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' - @is_remote = true - @members = searchStudent(@course) - @membercount = @members.count - @results = searchStudent_by_group(group, @course) - @@result = @results - @results = paginateHelper @results - end + + def member ## 有角色参数的才是课程,没有的就是项目 if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) @@ -324,11 +333,14 @@ class CoursesController < ApplicationController case params[:role] when '1' @subPage_title = l :label_teacher_list - @members = searchTeacherAndAssistant(@course) + @members = @teachers when '2' @subPage_title = l :label_student_list - - @members = searchStudent_sort(@course, 'desc') + teachers = @teachers.map{|teacher| teacher.user_id}.join(",") + @@member_scores = student_homework_score teachers + @members = @@member_scores + # @member_scores = @@member_scores + # @members = searchStudent_sort(@course, 'desc', @@member_scores) @membercount = @members.count else @@ -352,6 +364,7 @@ class CoursesController < ApplicationController @show_serch = params[:role] == '2' @subPage_title = l :label_student_list @render_file = 'member_list' + unless @@result.nil? @results = @@result.reverse @@result = @results @@ -360,6 +373,7 @@ class CoursesController < ApplicationController end # 显示每个学生的作业评分详情 def show_member_score + @member_score = Member.find(params[:member_id]) if params[:member_id] respond_to do |format| format.html {render :layout => 'course_base'} @@ -867,5 +881,35 @@ class CoursesController < ApplicationController end end + def student_homework_score teachers + homework_scores = Member.find_by_sql("SELECT id, user_id,course_id, course_group_id,created_on,IFNULL(SUM(CASE WHEN t_score <> 0 AND t_score IS NOT NULL THEN t_score ELSE s_score END),0) as score + FROM ( + SELECT members.id as id, members.user_id AS user_id, members.course_id AS course_id, members.created_on as created_on,members.course_group_id AS course_group_id, + (SELECT AVG(seems_rateable_rates.stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (3040,4762,4765)) AS t_score, + (SELECT AVG(seems_rateable_rates.stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (3040,4762,4765)) AS s_score + FROM `homework_attaches` , members + WHERE members.course_id = #{@course.id} + AND members.user_id NOT IN (#{teachers}) AND homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) + AND homework_attaches.user_id = members.user_id + ) AS table1 GROUP BY user_id ORDER BY score DESC") + homework_scores + end + #获取课程的老师列表 + def find_course_teachers course + searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",") + end + + #当加入,退出分班时查询分班的学生 + def search_group_members group + @subPage_title = l :label_student_list + @render_file = 'member_list' + @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + @is_remote = true + @members = searchStudent(@course) + @membercount = @members.count + @results = @@member_scores.find_all {|mem| mem.course_group_id == group.id} + @@result = @results + @results = paginateHelper @results + end end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 2f33ab554..d87992ec8 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -201,6 +201,7 @@ class FilesController < ApplicationController def quote_resource_show @file = Attachment.find(params[:id]) + @can_quote = attachment_candown @file end def new diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4049c2ae8..e6ab0f431 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -377,7 +377,7 @@ class UsersController < ApplicationController } scope = User.logged.status(@status) @search_by = params[:search_by] ? params[:search_by][:id] : 0 - scope = scope.like(params[:name],@search_by) if params[:name].present? + scope = scope.like(params[:name],"0") if params[:name].present? @user_count = scope.count @user_pages = Paginator.new @user_count, @limit, params['page'] @user_base_tag = params[:id] ? 'base_users':'users_base' @@ -433,9 +433,16 @@ class UsersController < ApplicationController else activity = Activity.where(where_condition).where('user_id = ?', @user.id).order('id desc') end + @activity_count = activity.count @activity_pages = Paginator.new @activity_count, pre_count, params['page'] - @activity = activity.offset(@activity_pages.offset).limit(@activity_pages.per_page).all + activity_page = activity.slice(@activity_pages.offset,@activity_pages.per_page * 2) + activity_page = activity_page.reject { |e| + ((e.act_type=="Issue") && ( !e.act.visible?(User.current))) || + ((e.act_type == "Journal") && (!e.act.project.visible?(User.current))) || + ((e.act_type == "Bid") && ((!User.current.member_of_course?(e.act.courses.first) || !User.current.admin?))) + } + @activity = activity.slice(0,@activity_pages.per_page) @state = 0 end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index ec3b9aad6..a5ae7d760 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -175,22 +175,7 @@ module CoursesHelper end members end - def searchStudent_sort project, sort_by - #searchPeopleByRoles(project, StudentRoles) - members = [] - project.members.each do |m| - if m && m.user && m.user.allowed_to?(:as_student,project) - members << m - - end - end - members.sort!{ |mem1, mem2| mem1.student_homework_score[1].to_f <=> mem2.student_homework_score[1].to_f} - if sort_by == "desc" - members.reverse! - end - members - end def searchStudent_by_name project, name @@ -206,6 +191,32 @@ module CoursesHelper end members end + def searchmember_by_name members, name + #searchPeopleByRoles(project, StudentRoles) + mems = [] + members.each do |m| + + username = m.user[:lastname].to_s + m.user[:firstname].to_s + if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name)) + mems << m + end + + end + mems + end + def searchgroupmember_by_name members, name, group + #searchPeopleByRoles(project, StudentRoles) + mems = [] + members.each do |m| + if m.course_group_id == group.id + username = m.user[:lastname].to_s + m.user[:firstname].to_s + if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name)) + mems << m + end + end + end + mems + end def searchgroupstudent_by_name(group, project, name) members = [] group.members.each do |m| diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index dfa485a70..8390fc61c 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -227,7 +227,7 @@ module IssuesHelper strings = [] values_by_field = {} details.each do |detail| - unless detail.property == 'attachment' + if detail.property == 'cf' field_id = detail.prop_key field = CustomField.find_by_id(field_id) @@ -243,7 +243,7 @@ module IssuesHelper end end strings << show_detail(detail, no_html, options) - end + end values_by_field.each do |field_id, changes| detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 935fb440e..842e1f1b7 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -98,7 +98,7 @@ module WatchersHelper # modify by nwb # 主讲教师不允许退出课程 return '' if user.id == course.tea_id - joined = user.member_of_course?(course) + joined = course.members.map{|m| m.user}.include? user text = joined ? l(:label_exit_course) : l(:label_new_join) url = joined ? join_path(:object_id => course.id) : try_join_path(:object_id => course.id) method = joined ? 'delete' : 'post' diff --git a/app/models/issue.rb b/app/models/issue.rb index 09e093177..4dc685b3b 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -51,7 +51,7 @@ class Issue < ActiveRecord::Base acts_as_nested_set :scope => 'root_id', :dependent => :destroy - acts_as_attachable :after_add => :attachment_added, :after_remove => :attachment_removed + acts_as_attachable :before_add => :attachment_added, :after_remove => :attachment_removed acts_as_customizable acts_as_watchable acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"], @@ -1359,7 +1359,7 @@ class Issue < ActiveRecord::Base # Callback on file attachment def attachment_added(obj) - if @current_journal && !obj.new_record? && @current_journal.journalized_id == obj.author_id + if @current_journal && @current_journal.user_id == obj.author_id && JournalDetail.find_all_by_value(obj.filename).count == 0 @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => obj.id, :value => obj.filename) end end diff --git a/app/models/member.rb b/app/models/member.rb index 32d0f5c73..446bb02e7 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -116,18 +116,16 @@ class Member < ActiveRecord::Base # 查找每个学生每个作业的评分 def student_homework_score - teachers = find_course_teachers(self.course) - score_count = 0 - homework_scores = HomeworkAttach.find_by_sql("SELECT homework_attaches.bid_id as bid_id, bids.name as name, + homework_score = HomeworkAttach.find_by_sql("SELECT bids.`name`, 0 as score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' - AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers}) ) AS t_score, + AND rateable_id = homework_attaches.id ) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' - AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score + AND rateable_id = homework_attaches.id ) AS s_score FROM homework_attaches, bids where homework_attaches.user_id = #{self.user_id} - and homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses where course_id = #{self.course_id} - and homework_attaches.bid_id = bids.id)") - homework_scores.each do |homework| + and homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses where course_id = #{self.course_id}) + AND homework_attaches.bid_id = bids.id ") + homework_score.each do |homework| if !homework.t_score.nil? && homework.t_score != 0 score = homework.t_score else @@ -139,7 +137,7 @@ class Member < ActiveRecord::Base end score_count = score_count + score end - [homework_scores, format("%0.2f", score_count)] + [homework_score, format("%0.2f", score_count)] end protected @@ -148,10 +146,7 @@ class Member < ActiveRecord::Base end - #获取课程的老师列表 - def find_course_teachers course - searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",") - end + def searchTeacherAndAssistant project #searchPeopleByRoles(project, TeacherRoles) members = [] diff --git a/app/models/user.rb b/app/models/user.rb index cae5f1aa2..e966742f1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -206,11 +206,11 @@ class User < Principal pattern = "%#{arg.to_s.strip.downcase}%" #where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern) if type == "0" - where(" LOWER(login) LIKE :p ", :p => pattern) + where(" LOWER(login) LIKE '#{pattern}' ") elsif type == "1" - where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern) + where(" LOWER(concat(lastname, firstname)) LIKE '#{pattern}' ") else - where(" LOWER(mail) LIKE :p ", :p => pattern) + where(" LOWER(mail) LIKE '#{pattern}' ") end end } diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index 7937912e4..2d6c35555 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -45,7 +45,7 @@ - + - -
+ <%= link_to(bid.author.lastname+bid.author.firstname, user_path(bid.author)) %> @@ -55,6 +55,8 @@ <%= link_to(bid.name, course_for_bid_path(bid), :class => 'bid_path') %> + <% if User.current.logged? && is_cur_course_student(@course) %> <% cur_user_homework = cur_user_homework_for_bid(bid) %> @@ -83,8 +85,8 @@ <%end%> <%= link_to( - l(:button_edit), - {:action => 'edit', :controller=>'bids', :course_id =>@course.id, :bid_id => bid.id} + l(:button_edit), + {:action => 'edit', :controller=>'bids', :course_id =>@course.id, :bid_id => bid.id} ) %> <%#= link_to( @@ -156,7 +158,7 @@
+ <%= l(:label_create_time) %> :  @@ -176,7 +178,6 @@ <% end %>
diff --git a/app/views/common/403.html b/app/views/common/403.html index f3696c4ea..a89be932d 100644 --- a/app/views/common/403.html +++ b/app/views/common/403.html @@ -7,7 +7,7 @@ body{ font-size:12px; font-family:"微软雅黑","宋体"; line-height:1.9; background:#fff; font-style:normal;} div,html,img,ul,li,p,body,h1,h2,h3,h4,p,a,table,tr,td,fieldset,input,span{ margin:0; padding:0;} div,img,tr,td{ border:0;} -table,tr,td{border:0 cellspacing:0; cellpadding:0;} +table,tr,td{border:0; cellspacing:0; cellpadding:0;} ul,li{ list-style-type:none} .cl{ clear:both; overflow:hidden; } a{ text-decoration:none; } diff --git a/app/views/common/404.html b/app/views/common/404.html index 8453e0a41..0d632c4c8 100644 --- a/app/views/common/404.html +++ b/app/views/common/404.html @@ -7,7 +7,7 @@ body{ font-size:12px; font-family:"微软雅黑","宋体"; line-height:1.9; background:#fff;} div,html,img,ul,li,p,body,h1,h2,h3,h4,p,a,table,tr,td,fieldset,input,span{ margin:0; padding:0;} div,img,tr,td{ border:0;} -table,tr,td{border:0 cellspacing:0; cellpadding:0;} +table,tr,td{border:0; cellspacing:0; cellpadding:0;} ul,li{ list-style-type:none} .cl{ clear:both; overflow:hidden; } a{ text-decoration:none; } diff --git a/app/views/contests/index.html.erb b/app/views/contests/index.html.erb index 5867d7fcd..75b892461 100644 --- a/app/views/contests/index.html.erb +++ b/app/views/contests/index.html.erb @@ -21,36 +21,36 @@ diff --git a/app/views/courses/_courses_jours.html.erb b/app/views/courses/_courses_jours.html.erb index 68b92c00e..23c74ed4b 100644 --- a/app/views/courses/_courses_jours.html.erb +++ b/app/views/courses/_courses_jours.html.erb @@ -1,8 +1,10 @@
- <% reply_allow = JournalsForMessage.create_by_user? User.current %> + <%# reply_allow = JournalsForMessage.create_by_user? User.current %> -

<%= l(:label_user_response) %>

+

+ <%= l(:label_user_response) %> +

<% if !User.current.logged?%>
@@ -30,5 +32,7 @@
<%= render :partial => 'history',:locals => { :contest => @contest, :journals => @jour, :state => false} %>
-
    <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
+
    + <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> +
\ No newline at end of file diff --git a/app/views/courses/_groups_name.html.erb b/app/views/courses/_groups_name.html.erb index e1b138666..1fe02dfeb 100644 --- a/app/views/courses/_groups_name.html.erb +++ b/app/views/courses/_groups_name.html.erb @@ -1,17 +1,19 @@ - - +