diff --git a/app/api/mobile/entities/activity.rb b/app/api/mobile/entities/activity.rb index 6f5a3db74..9deeec58e 100644 --- a/app/api/mobile/entities/activity.rb +++ b/app/api/mobile/entities/activity.rb @@ -83,15 +83,15 @@ module Mobile if ac.container_type == "Course" case ac.act_type when "HomeworkCommon" - "课程作业" + "班级作业" when "News" - "课程通知" + "班级通知" when "Message" - "课程问答区" + "班级讨论区" when "Poll" - "课程问卷" + "班级问卷" when "Course" - "课程" + "班级" end elsif ac.container_type == "Project" case ac.act_type diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 731a251f2..02dfe9a45 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -30,6 +30,8 @@ class AccountController < ApplicationController user = UserExtensions.where(:user_id => User.current.id).first if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil? redirect_to my_account_path(:tip => 1) + elsif user.identity == 3 && user.school_id.nil? + redirect_to my_account_path(:tip => 1) else redirect_to user_path(User.current) end @@ -357,6 +359,8 @@ class AccountController < ApplicationController user = UserExtensions.where(:user_id => User.current.id).first if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil? redirect_to my_account_path(:tip => 1) + elsif user.identity == 3 && user.school_id.nil? + redirect_to my_account_path(:tip => 1) else redirect_back_or_default User.current #redirect_to my_account_url diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index fa2c87f8c..7ec532d79 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -202,6 +202,11 @@ class AttachmentsController < ApplicationController end @attachment.save @newfiledense = filedense + end + if @project + + elsif @course + end respond_to do |format| format.js diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index b5c174b0c..9d90cb9f2 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -12,11 +12,13 @@ class AvatarController < ApplicationController @source_id = params[:source_id] @temp_file = params[:avatar][:image] @image_file = @temp_file.original_filename + @is_direct = params[:is_direct] else unless request.raw_post.nil? @source_type = params[:source_type] @source_id = params[:source_id] @temp_file = request.raw_post + @is_direct = params[:is_direct] if @temp_file.size > 0 if @temp_file.respond_to?(:original_filename) @image_file = @temp_file.original_filename @@ -38,7 +40,7 @@ class AvatarController < ApplicationController @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) # 用户头像上传时进行特别处理 - if @source_type == 'User' + if @is_direct == '1' && (@source_type == 'User' || @source_type == 'Course' || @source_type == 'Project') diskfile += "temp" @urlfile += "temp" end @@ -105,7 +107,7 @@ class AvatarController < ApplicationController path = File.dirname(diskfile) if File.directory?(path) && File.exist?(diskfile) # 用户头像进行特别处理 - if @source_type == 'User' + if @source_type == 'User' || @source_type == 'Course' || @source_type == 'Project' diskfile1 = diskfile + 'temp' File.open(diskfile1, "wb") do |f| buffer = "DELETE" diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index cd3870e9a..988768414 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -325,6 +325,7 @@ class FilesController < ApplicationController @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] show_attachments @containers + # get_attachment_for_tip(@all_attachments) @tag_list = attachment_tag_list @all_attachments @@ -377,6 +378,7 @@ class FilesController < ApplicationController @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] show_attachments @containers + # get_attachment_for_tip(@all_attachments) @tag_list = attachment_tag_list @all_attachments @@ -440,6 +442,39 @@ class FilesController < ApplicationController end + # 获取提示中私有、公开总数信息 + def get_attachment_for_tip all_attachment + + @tip_all_public_attachments = all_attachment.select{|attach| attach.is_public == 1}.count + if params[:project_id] + if User.current.member_of?(@project) || User.current.admin? + @tip_all_attachments = all_attachment.count + @tip_all_private_attachments = all_attachment.select{|attach| attach.is_public == 0}.count + else + if params[:tag_name] + @tip_all_attachments = all_attachment.count + @tip_all_private_attachments = 0 + else + @tip_all_attachments = Attachment.where(:container_id => params[:project_id], :container_type => "Project").count + @tip_all_private_attachments = Attachment.where(:container_id => params[:project_id], :container_type => "Project", :is_public => 0).count + end + end + elsif params[:course_id] + if User.current.member_of_course?(@course) || User.current.admin? + @tip_all_attachments = all_attachment.count + @tip_all_private_attachments = all_attachment.select{|attach| attach.is_public == 0}.count + else + if params[:tag_name] + @tip_all_attachments = all_attachment.count + @tip_all_private_attachments = 0 + else + @tip_all_attachments = Attachment.where(:container_id => params[:course_id], :container_type => "Course").count + @tip_all_private_attachments = Attachment.where(:container_id => params[:course_id], :container_type => "Course", :is_public => 0).count + end + end + end + end + def quote_resource_show @file = Attachment.find(params[:id]) @can_quote = attachment_candown @file @@ -883,6 +918,7 @@ class FilesController < ApplicationController end @all_attachments = @result + get_attachment_for_tip(@all_attachments) @limit = 10 @feedback_count = @all_attachments.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 2f50c8105..6704f7401 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -94,8 +94,10 @@ class HomeworkCommonController < ApplicationController end end + status = false if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 homework_detail_manual.comment_status = 1 + status = true end eval_start = homework_detail_manual.evaluation_start if eval_start.nil? || (eval_start <= @homework.end_time && homework_detail_manual.comment_status <= 1) @@ -145,6 +147,10 @@ class HomeworkCommonController < ApplicationController @homework_detail_programing.save if @homework_detail_programing @homework_detail_group.save if @homework_detail_group + if @homework.homework_type != 3 && homework_detail_manual.comment_status == 1 && status + create_works_list @homework + end + if params[:is_manage] == "1" redirect_to manage_or_receive_homeworks_user_path(User.current.id) elsif params[:is_manage] == "2" diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index f108c685a..4c9411538 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -521,10 +521,10 @@ class IssuesController < ApplicationController def delete_journal @issue = Issue.find(params[:id]) begin - forge_acts = ForgeMessage.where(:forge_message_type => "Journal", :forge_message_id => params[:journal_id]).first - forge_acts.destroy unless forge_acts.nil? - at_message = AtMessage.where(:at_message_type => "Journal", :at_message_id => params[:journal_id]).first - at_message.destroy unless at_message.nil? + forge_acts = ForgeMessage.where(:forge_message_type => "Journal", :forge_message_id => params[:journal_id]) + forge_acts.destroy_all unless forge_acts.empty? + at_message = AtMessage.where(:at_message_type => "Journal", :at_message_id => params[:journal_id]) + at_message.destroy_all unless at_message.empty? Journal.delete(params[:journal_id]) rescue Exception => e puts e diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index d661350c6..97222f0bd 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -229,7 +229,7 @@ class MembersController < ApplicationController user_ids.each do |user_id| member = Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) - role_ids = attrs.delete(:role_ids) + role_ids = params[:membership][:role_ids] #role = Role.find(params[:membership][:role_ids]) # 这里的判断只能通过角色名,可以弄成常量 if role_ids && role_ids.include?("10") diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 3aefdfd1d..c4935a1af 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -90,14 +90,34 @@ class MyController < ApplicationController end def clear_user_avatar_temp - @user = User.current - diskfile = disk_filename('User', @user.id) + if params[:course] + @course = Course.find params[:course] + diskfile = disk_filename('Course', @course.id) + elsif params[:project] + @project = Project.find params[:project] + diskfile = disk_filename('Project', @project.id) + else + @user = User.current + diskfile = disk_filename('User', @user.id) + end diskfile1 = diskfile + 'temp' File.delete(diskfile1) if File.exist?(diskfile1) end + def save_user_avatar - @user = User.current - diskfile = disk_filename('User', @user.id) + if params[:source_id] && params[:source_type] + case params[:source_type] + when 'User' + @user = User.current + diskfile = disk_filename('User', @user.id) + when 'Course' + @course = Course.find params[:source_id] + diskfile = disk_filename('Course', @course.id) + when 'Project' + @project = Project.find params[:source_id] + diskfile = disk_filename('Project', @project.id) + end + end diskfile1 = diskfile + 'temp' begin FileUtils.mv diskfile1, diskfile, force: true if File.exist? diskfile1 @@ -145,8 +165,10 @@ class MyController < ApplicationController @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') #@user.login = params[:login] unless @user.user_extensions.nil? - if @user.user_extensions.identity == 2 + # 如果用户是从业者,将单位名称保存至学校id字段 + if @user.user_extensions.identity == 3 # @user.firstname = params[:enterprise_name] + @user.user_extensions.school_id = params[:occupation] end end @@ -157,7 +179,6 @@ class MyController < ApplicationController # @se.occupation = params[:occupation] # end @se.school_id = params[:occupation] - @se.gender = params[:sex] @se.location = params[:province] if params[:province] @se.location_city = params[:city] if params[:city] @@ -180,6 +201,7 @@ class MyController < ApplicationController @user.login = lg end end + # 不管前面是否有异常,如果文件已存在就删除 ensure File.delete(diskfile1) if File.exist?(diskfile1) end diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 5e21f9af0..b67a74439 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -1,8 +1,10 @@ class PullRequestsController < ApplicationController + before_filter :authorize_logged before_filter :find_project_and_repository before_filter :connect_gitlab, :only => [:index, :show, :create, :accept_pull_request, :pull_request_commits, :pull_request_changes, :new, :update_pull_request, :pull_request_comments, :create_pull_request_comment] + layout "base_projects" include PullRequestsHelper include ApplicationHelper @@ -235,6 +237,13 @@ class PullRequestsController < ApplicationController end private + def authorize_logged + if !User.current.logged? + redirect_to signin_path + return + end + end + def connect_gitlab @g = Gitlab.client end diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index a0b275dc7..3a9eff0ce 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -241,6 +241,21 @@ class QualityAnalysisController < ApplicationController complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=#{filter}").read @complexity =JSON.parse(complexity_date).first + # 获取排名结果 + @g = Gitlab.client + @author_infos = @g.rep_user_stats(@project.gpid, :rev => @branch) + @user_quality_infos = [] + @author_infos.each do |author_info| + email = author_info.email + changes = author_info.changes.to_i + unresolved_issues = open(@sonar_address + "/api/issues/search?projectKeys=#{@resource_id}&authors=#{email}&resolved=false").read + unresolved_issue_count = JSON.parse(unresolved_issues)["total"].to_i + all_issues = open(@sonar_address + "/api/issues/search?projectKeys=#{@resource_id}&authors=#{email}").read + all_issue_count = JSON.parse(all_issues)["total"].to_i + ratio = (changes == 0 ? 0 : format("%0.4f",unresolved_issue_count.to_f/changes.to_f)) + @user_quality_infos << {:email => email, :changes => changes, :unresolved_issue_count => unresolved_issue_count, :ratio => ratio, :all_issue_count => all_issue_count} + end + # 按名称转换成hash键值对 @ha = {} @complexity["msr"].each do |com| diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 722845ef7..5e13149df 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -734,24 +734,33 @@ class StudentWorkController < ApplicationController end def destroy - if @work.destroy - if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 - pros = @work.student_work_projects.where("is_leader = 0") - pros.each do |pro| - pro.destroy - end - project = @work.student_work_projects.where("is_leader = 1").first - project.update_attributes(:student_work_id => nil) - elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0 - @work.student_work_projects.each do |pro2| - pro2.destroy + if @homework.homework_type == 3 + if @work.destroy + if @homework.homework_detail_group.base_on_project == 1 + pros = @work.student_work_projects.where("is_leader = 0") + pros.each do |pro| + pro.destroy + end + project = @work.student_work_projects.where("is_leader = 1").first + project.update_attributes(:student_work_id => nil) + elsif @homework.homework_detail_group.base_on_project == 0 + @work.student_work_projects.each do |pro2| + pro2.destroy + end end end - respond_to do |format| - format.html { - redirect_to student_work_index_url(:homework => @homework.id) - } - end + else + @work.attachments.destroy_all + @work.student_works_scores.destroy_all + @work.course_messages.destroy_all + @work.student_work_tests.destroy_all + @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil,:final_score => nil,:teacher_score => nil,:student_score => nil,:teaching_asistant_score => nil,:system_score => 0,:work_score => nil) + @work.update_column("work_score",nil) + end + respond_to do |format| + format.html { + redirect_to student_work_index_url(:homework => @homework.id) + } end end @@ -793,6 +802,8 @@ class StudentWorkController < ApplicationController end elsif @homework.homework_type == 1 @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil) + @work.attachments.destroy_all + @work.course_messages.destroy_all end @student_work = StudentWork.new respond_to do |format| diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e929153ad..b385fe610 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -42,7 +42,7 @@ class UsersController < ApplicationController :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list, - :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks] + :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -1115,23 +1115,8 @@ class UsersController < ApplicationController homework_detail_programing.save if homework_detail_programing homework_detail_group.save if homework_detail_group - if homework.homework_type != 3 - students = homework.course.student - if !homework.course.nil? && !students.empty? - name = homework.name - name_str = name + "的作品提交" - str = "" - students.each do |student| - if str != "" - str += "," - end - str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')" - end - #('#{name}的作品提交',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}') - sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str - #StudentWork.create(:name => "#{name}的作品提交", :homework_common_id => homework.id, :user_id => student.student_id) - ActiveRecord::Base.connection.execute sql - end + if homework.homework_type != 3 && homework_detail_manual.comment_status == 1 + create_works_list homework end if params[:quotes] && !params[:quotes].blank? @@ -1474,15 +1459,15 @@ class UsersController < ApplicationController #显示更多用户课程 def user_courses4show @page = params[:page].to_i + 1 - @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(10).offset(@page * 10) - @all_count = @user.courses.visible.where("is_delete =?", 0).count + @courses = @user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(10).offset(@page * 10) + @all_count = @user.favorite_courses.visible.where("is_delete =?", 0).count end #显示更多用户项目 def user_projects4show @page = params[:page].to_i + 1 - @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10).offset(@page * 10) - @all_count = @user.projects.visible.count + @projects = @user.favorite_projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10).offset(@page * 10) + @all_count = @user.favorite_projects.visible.count end def user_course_activities @@ -2167,6 +2152,7 @@ class UsersController < ApplicationController #这里仅仅是传递需要发送的资源id @send_id = params[:send_id] @send_ids = params[:checkbox1] || params[:send_ids] + @hidden_unproject = hidden_unproject_infos respond_to do |format| format.js end @@ -2186,6 +2172,7 @@ class UsersController < ApplicationController #这里仅仅是传递需要发送的资源id @send_id = params[:send_id] @send_ids = params[:checkbox1] || params[:send_ids] #搜索的时候 和 直接 用表格提交的时候的send_ids + @hidden_unproject = hidden_unproject_infos respond_to do |format| format.js end @@ -3349,6 +3336,7 @@ class UsersController < ApplicationController #这里仅仅是传递需要发送的资源id @send_id = params[:send_id] @send_ids = params[:checkbox1] || params[:send_ids] + @hidden_unproject = hidden_unproject_infos respond_to do |format| format.js end @@ -3439,6 +3427,28 @@ class UsersController < ApplicationController end end + #收藏班级/项目 + def cancel_or_collect + if params[:project] + @project = Project.find params[:project] + member = Member.where("user_id = #{@user.id} and project_id = #{@project.id}") + elsif params[:course] + @course = Course.find params[:course] + member = Member.where("user_id = #{@user.id} and course_id = #{@course.id}") + end + unless member.empty? + member.first.update_attribute(:is_collect, member.first.is_collect == 0 ? 1 : 0) + end + if @project + @projects = @user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10) + elsif @course + @courses = @user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(10) + end + respond_to do |format| + format.js + end + end + def user_projectlist @order, @c_sort, @type, @list_type = 1, 2, 1, 1 #limit = 5 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aabacb6e0..3c125a185 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,6 +37,13 @@ module ApplicationHelper # super # end + # 隐藏项目以外的信息 + # return: true 显示,false 不显示 + def hidden_unproject_infos + hidden_info = Setting.find_by_name("hidden_non_project") + (hidden_info && hidden_info.value == "1") ? true : false + end + # 通过系统外部邮箱查找用户,如果用户不存在则用邮箱替换 def get_user_by_mail mail user = User.find_by_mail(mail) @@ -820,16 +827,17 @@ module ApplicationHelper return @result end + def show_attachment_tip container_id, container_type + atts = Attachment.where(:container_id => container_id, :container_type => container_type, :is_public => 0) + atts.count > 0 ? true :false + end + # 必须是项目成,项目必须提交过代码 def allow_pull_request project return false if project.gpid.nil? g = Gitlab.client count = g.user_static(project.gpid, :rev => "master").count - if User.current.member_of?(project) && count > 0 - true - else - false - end + count end # 判断版本库是否初始为gitlab @@ -2519,7 +2527,7 @@ module ApplicationHelper def footer_logo(ul_class=nil, li_class=nil) logos = [] logos.push(link_to image_tag('/images/footer_logo/nudt.png',:alt=>"nudt"),"http://www.nudt.edu.cn/special.asp?classid=12" ) - logos.push(link_to image_tag('/images/footer_logo/peking_eecs.png', :alt=>"peking_eecs"), "http://eecs.pku.edu.cn" ) + logos.push(link_to image_tag('/images/footer_logo/peking_eecs.png', :alt=>"peking_eecs"), "http://www.sei.pku.edu.cn/" ) logos.push(link_to image_tag('/images/footer_logo/buaa_scse.png', :alt=>"buaa_scse"), "http://scse.buaa.edu.cn/" ) logos.push(link_to image_tag('/images/footer_logo/iscas.png', :alt=>"iscas"), "http://www.iscas.ac.cn" ) logos.push(link_to image_tag('/images/footer_logo/inforbus.png', :alt=>"inforbus"), "http://www.inforbus.com" ) @@ -3447,8 +3455,26 @@ def course_syllabus_option user = User.current type end +def create_works_list homework + students = homework.course.student + if !homework.course.nil? && !students.empty? + name = homework.name + name_str = name + "的作品提交" + str = "" + students.each do |student| + if str != "" + str += "," + end + str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')" + end + sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str + ActiveRecord::Base.connection.execute sql + end +end + # 获取项目动态更新时间 def get_forge_act_message(act, type) forge_act = ForgeActivity.where(:forge_act_id => act.id, :forge_act_type => type).first format_time(forge_act.nil? ? act.created_on : forge_act.try(:updated_at)) end + diff --git a/app/helpers/org_member_helper.rb b/app/helpers/org_member_helper.rb index e16051eaf..8e7d1e2ef 100644 --- a/app/helpers/org_member_helper.rb +++ b/app/helpers/org_member_helper.rb @@ -7,7 +7,7 @@ module OrgMemberHelper scope = [] end principals = paginateHelper scope,10 - s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals') links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| link_to text, host_with_protocol + "/org_member/org_member_autocomplete?" + parameters.merge(:q => params[:q],:flag => true,:org=> org, :format => 'js').to_query, :remote => true } diff --git a/app/models/member.rb b/app/models/member.rb index cb15e067b..bb336e936 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -52,6 +52,9 @@ class Member < ActiveRecord::Base ids += member_roles.select {|mr| !mr.inherited_from.nil?}.collect(&:role_id) new_role_ids = ids - role_ids + if (new_role_ids.include?(7) || new_role_ids.include?(9)) && role_ids.include?(10) + member_roles.where("role_id = 10").first.update_column('is_current', 0) + end # Add new roles if new_role_ids.include?(7) && new_role_ids.include?(10) member_roles << MemberRole.new(:role_id => 7) diff --git a/app/models/principal.rb b/app/models/principal.rb index 0c87ec0c6..e65816e83 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -131,6 +131,22 @@ class Principal < ActiveRecord::Base columns.uniq.map {|field| "#{table}.#{field}"} end + #收藏的课程 + def favorite_courses + members = Member.where("user_id = #{self.id} and course_id != -1 and is_collect = 1") + course_ids = members.empty? ? "(-1)" : "(" + members.map{|member| member.course_id}.join(",") + ")" + courses = Course.where("id in #{course_ids}") + return courses + end + + #收藏的项目 + def favorite_projects + members = Member.where("user_id = #{self.id} and project_id != -1 and project_id != 0 and is_collect = 1") + project_ids = members.empty? ? "(-1)" : "(" + members.map{|member| member.project_id}.join(",") + ")" + projects = Project.where("id in #{project_ids}") + return projects + end + protected # Make sure we don't try to insert NULL values (see #4632) diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 09ef15583..183570081 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -1,6 +1,6 @@ #学生提交作品表 class StudentWork < ActiveRecord::Base - attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time + attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time belongs_to :homework_common belongs_to :user diff --git a/app/models/tracker.rb b/app/models/tracker.rb index af56d23bf..4ef18b7b0 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -34,7 +34,7 @@ class Tracker < ActiveRecord::Base end has_and_belongs_to_many :projects - has_and_belongs_to_many :courses + # has_and_belongs_to_many :courses has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id' acts_as_list diff --git a/app/models/user.rb b/app/models/user.rb index b863c1f70..f2b2b6824 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1162,18 +1162,20 @@ class User < Principal #为新注册用户发送留言 def add_new_jour - if Message.where("id=19504").any? and Message.where("id=19291").any? and Message.where("id=19292").any? - lead_message1 = Message.find(19292) - notes1 = lead_message1.content - lead_message2 = Message.find(19291) - notes2 = lead_message2.content - lead_message3 = Message.find(19504) - notes3 = lead_message3.content - #user_id 默认为课程使者创建 - self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes1, :reply_id => 0, :status => true, :is_readed => false, :private => 0) - self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes2, :reply_id => 0, :status => true, :is_readed => false, :private => 0) - self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes3, :reply_id => 0, :status => true, :is_readed => false, :private => 0) - end + if Setting.find_by_name("hidden_non_project") && Setting.find_by_name("hidden_non_project").value != "0" + if Message.where("id=19504").any? and Message.where("id=19291").any? and Message.where("id=19292").any? + lead_message1 = Message.find(19292) + notes1 = lead_message1.content + lead_message2 = Message.find(19291) + notes2 = lead_message2.content + lead_message3 = Message.find(19504) + notes3 = lead_message3.content + #user_id 默认为课程使者创建 + self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes1, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes2, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes3, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + end + end end # 更新邮箱的同事,更新invite_lists表中的邮箱信息 diff --git a/app/views/avatar/_new_avatar_form.html.erb b/app/views/avatar/_new_avatar_form.html.erb index 2593bf1f5..d13a2a4d5 100644 --- a/app/views/avatar/_new_avatar_form.html.erb +++ b/app/views/avatar/_new_avatar_form.html.erb @@ -17,7 +17,8 @@ :upload_path => upload_avatar_path(:format => 'js'), :description_placeholder => nil ,# l(:label_optional_description) :source_type => source.class.to_s, - :source_id => source.id.to_s + :source_id => source.id.to_s, + :is_direct => 0 } %> <% content_for :header_tags do %> diff --git a/app/views/avatar/upload.js.erb b/app/views/avatar/upload.js.erb index 41cf3ab77..c2fa23242 100644 --- a/app/views/avatar/upload.js.erb +++ b/app/views/avatar/upload.js.erb @@ -1,4 +1,4 @@ -<% if @source_type=='User' %> +<% if @is_direct == '1' && (@source_type=='User'|| @source_type == 'Course' || @source_type == 'Project') %> var imgSpan = $("img[nhname='avatar_image']"); imgSpan.attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'}); <% else %> diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 46191b5d3..6759e33ce 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -22,7 +22,7 @@
共有 <%= @all_attachments.count%> 个资源
-- <%= render :partial => 'course_file_filter_order', :locals => {:remote => @is_remote, :sort => @sort, :order => @order} %> -
+ + + +共有 <%= @all_attachments.count%> 个资源
++ <%= render :partial => 'course_file_filter_order', :locals => {:remote => @is_remote, :sort => @sort, :order => @order} %> +
共有 <%= @all_attachments.count%> 个资源
<% if @order == "asc" %> @@ -100,6 +103,14 @@