diff --git a/Gemfile b/Gemfile index 0125e9d60..38364b556 100644 --- a/Gemfile +++ b/Gemfile @@ -44,7 +44,9 @@ group :development do gem 'grape-swagger' gem 'better_errors', '~> 1.1.0' gem 'rack-mini-profiler', '~> 0.9.3' - gem 'win32console' + if RUBY_PLATFORM =~ /w32/ + gem 'win32console' + end end group :development, :test do diff --git a/app/assets/javascripts/org_subfields.js.coffee b/app/assets/javascripts/org_subfields.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/org_subfields.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/org_subfields.css.scss b/app/assets/stylesheets/org_subfields.css.scss new file mode 100644 index 000000000..19263385e --- /dev/null +++ b/app/assets/stylesheets/org_subfields.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the org_subfields controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6387a97a4..cbf2c30bb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -418,6 +418,8 @@ class ApplicationController < ActionController::Base @project = Project.find(params[:project_id]) elsif params[:course_id] @course = Course.find(params[:course_id]) + elsif params[:org_subfield_id] + @org_subfield = OrgSubfield.find(params[:org_subfield_id]) end rescue ActiveRecord::RecordNotFound render_404 diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 37182dbcf..d371ed4cb 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -240,6 +240,8 @@ class AttachmentsController < ApplicationController format.html { redirect_to_referer_or respond_path(@attachment.container) } elsif !@attachment.container.nil? && @attachment.container.is_a?(PhoneAppVersion) format.html { redirect_to_referer_or mobile_version_path } + elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgSubfield) + format.html {redirect_to_referer_or org_subfield_files_path(@attachment.container)} else if @project.nil? format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0c61c449e..1b0ead141 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -25,6 +25,7 @@ class CoursesController < ApplicationController before_filter :authorize_course, :only => [:show, :settings, :update, :course] before_filter :authorize_course_global, :only => [:new,:create] before_filter :toggleCourse, :only => [:finishcourse, :restartcourse] + before_filter :is_deleted, :only => [:show, :settings] before_filter :require_login, :only => [:join, :unjoin] #before_filter :allow_join, :only => [:join] @@ -55,11 +56,11 @@ class CoursesController < ApplicationController def join if User.current.logged? - cs = CoursesService.new - @user = User.current - join = cs.join_course params,@user - @state = join[:state] - @course = join[:course] + cs = CoursesService.new + @user = User.current + join = cs.join_course params,@user + @state = join[:state] + @course = join[:course] # else # @course = Course.find_by_id params[:object_id] # CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest') @@ -70,7 +71,7 @@ class CoursesController < ApplicationController end @object_id = params[:object_id] respond_to do |format| - format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} } + format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} } end end @@ -85,7 +86,7 @@ class CoursesController < ApplicationController end end - + def join_private_courses respond_to do |format| format.js @@ -98,14 +99,14 @@ class CoursesController < ApplicationController c = cs.edit_course params,@course,User.current @course = c[:course] if @course.errors.full_messages.count <= 0 - respond_to do |format| - format.html { - # render :layout => 'base_courses' - flash[:notice] = l(:notice_successful_update) - redirect_to settings_course_url(@course) - } - format.api { render_api_ok } - end + respond_to do |format| + format.html { + # render :layout => 'base_courses' + flash[:notice] = l(:notice_successful_update) + redirect_to settings_course_url(@course) + } + format.api { render_api_ok } + end else respond_to do |format| format.html { @@ -134,8 +135,8 @@ class CoursesController < ApplicationController courses = Course.visible.where("LOWER(name) like '%#{params[:name].to_s.downcase}%'").order("time desc, created_at desc") @courses = paginateHelper courses,10 end - @name = params[:name] - @type = 'courses' + @name = params[:name] + @type = 'courses' respond_to do |format| format.html { render :layout => 'course_base' @@ -277,7 +278,7 @@ class CoursesController < ApplicationController def member ## 有角色参数的才是课程,没有的就是项目 if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) - + @render_file = 'new_member_list' @score_sort_by = "desc" @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' @@ -312,7 +313,7 @@ class CoursesController < ApplicationController def export_course_member_excel @all_members = student_homework_score(0,0,0,"desc") filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}"; - + respond_to do |format| format.xls { send_data(member_to_xls(@all_members,@course.course_groups), :type => "text/excel;charset=utf-8; header=present", @@ -427,7 +428,7 @@ class CoursesController < ApplicationController end def course - @school_id = params[:school_id] + @school_id = params[:school_id] per_page_option = 10 if @school_id == "0" or @school_id.nil? @courses_all = Course.active.visible. @@ -515,8 +516,8 @@ class CoursesController < ApplicationController def index if !User.current.admin? - render_404 - return + render_404 + return end @course_type = params[:course_type] @school_id = params[:school_id] @@ -565,7 +566,7 @@ class CoursesController < ApplicationController respond_to do |format| format.html { - render :layout => 'base' + render :layout => 'base' } format.atom { courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all @@ -581,6 +582,13 @@ class CoursesController < ApplicationController end end + def is_deleted + if @course.is_delete == 1 and !User.current.admin? + render_404 + return + end + end + def get_courses @user = User.current membership = @user.coursememberships.all @@ -634,6 +642,11 @@ class CoursesController < ApplicationController end def show + # 被删除的课程只有超级管理员才能看到,is_delete为1的时候,标记课程被删除 + # if @course.is_delete == 1 && !User.current.admin? + # render_403 + # return + # end #更新创建课程消息状态 create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0) create_course_messages.update_all(:viewed => true) @@ -684,10 +697,10 @@ class CoursesController < ApplicationController end def feedback - @course.journals_for_messages.each do |messages| - query = messages.course_messages.where("user_id = ?", User.current.id) - query.update_all(:viewed => true); - end + @course.journals_for_messages.each do |messages| + query = messages.course_messages.where("user_id = ?", User.current.id) + query.update_all(:viewed => true); + end if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) page = params[:page] @@ -738,20 +751,20 @@ class CoursesController < ApplicationController #从课程创建的老师那里选择课程大纲 def course_outline - @teacher = User.find(@course.tea_id) - @blog_articles = @teacher.blog.articles - @is_in_show_outline_page = params[:is_in_show_outline_page] - respond_to do |format| - format.js - end + @teacher = User.find(@course.tea_id) + @blog_articles = @teacher.blog.articles + @is_in_show_outline_page = params[:is_in_show_outline_page] + respond_to do |format| + format.js + end end #根据关键字搜索,查找方法一样的,但返回内容不一样 def search_course_outline - @article_title = params[:title] - @teacher = User.find(@course.tea_id) - @blog_articles = @teacher.blog.articles.like(@article_title) - render :json=>@blog_articles.to_json + @article_title = params[:title] + @teacher = User.find(@course.tea_id) + @blog_articles = @teacher.blog.articles.like(@article_title) + render :json=>@blog_articles.to_json end #设置或者更改课程的大纲 @@ -771,10 +784,23 @@ class CoursesController < ApplicationController format.html {render :layout => 'base_courses'} end end - #删除课程 - #删除课程只是将课程的is_delete状态改为false,is_delete为false状态的课程只有管理员可以看到 - def destroy + #删除课程 + #删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到 + def destroy + @course.update_attributes(:is_delete => true) + @course = nil + redirect_to user_url(User.current) + end + + # 恢复已删除的课程 + def renew + if User.current.admin? + @course.update_attributes(:is_delete => false) + redirect_to course_path(@course) + else + return 404 + end end private @@ -797,7 +823,7 @@ class CoursesController < ApplicationController def can_show_course @first_page = FirstPage.find_by_page_type('project') if @first_page.try(:show_course) == 2 - render_404 + render_404 end end diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index a99ab32ec..2a75d0580 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -18,13 +18,13 @@ class ExerciseController < ApplicationController end_exercises.each do |exercise| exercise.update_column('exercise_status', 3) end - if @course.is_public == 0 && !User.current.member_of_course?(@course) + if @course.is_public == 0 && !(User.current.member_of_course?(@course)||User.current.admin?) render_403 return end remove_invalid_exercise(@course) @is_teacher = User.current.allowed_to?(:as_teacher,@course) - if @is_teacher + if @is_teacher || User.current.admin? exercises = @course.exercises.order("created_at asc") else exercises = @course.exercises.where(:exercise_status => 2).order("created_at asc") @@ -48,13 +48,13 @@ class ExerciseController < ApplicationController end_exercises.each do |exercise| exercise.update_column('exercise_status', 3) end - unless User.current.member_of_course?(@course) + unless User.current.member_of_course?(@course) || User.current.admin? render_403 return end @exercise = Exercise.find params[:id] @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - if @exercise.exercise_status != 2 && (!User.current.allowed_to?(:as_teacher,@course) || User.current.admin?) + if @exercise.exercise_status != 2 && (!(User.current.allowed_to?(:as_teacher,@course) || User.current.admin?)) render_403 return end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index b15be4896..328446fbb 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -186,7 +186,7 @@ class FilesController < ApplicationController @order = "" @is_remote = false if params[:project_id] - @isproject = true + @container_type = 0 if params[:sort] params[:sort].split(",").each do |sort_type| @@ -246,7 +246,7 @@ class FilesController < ApplicationController format.js end elsif params[:course_id] - @isproject = false + @container_type = 1 if params[:sort] params[:sort].split(",").each do |sort_type| @@ -297,6 +297,13 @@ class FilesController < ApplicationController @tag_list = attachment_tag_list @all_attachments render :layout => 'base_courses' + elsif params[:org_subfield_id] + @container_type = 2 + @organization = Organization.find(params[:organization_id]) + @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] + show_attachments @containers + render :layout => 'base_org' + # @subfield = params[:org_subfield_id] end end @@ -421,8 +428,39 @@ class FilesController < ApplicationController redirect_to course_files_url(@course) } end - end + elsif @org_subfield + @addTag=false + # if params[:in_org_subfield_toolbar] + # @in_org_subfield_toolbar = params[:in_org_subfield_toolbar] + # end + attachments = Attachment.attach_filesex(@org_subfield, params[:attachments], params[:org_subfield_attachment_type]) + # if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') + # Mailer.run.attachments_added(attachments[:files]) + # end + + # TODO: 临时用 nyan + sort_init 'created_on', 'desc' + sort_update 'created_on' => "#{Attachment.table_name}.created_on", + 'filename' => "#{Attachment.table_name}.filename", + 'size' => "#{Attachment.table_name}.filesize", + 'downloads' => "#{Attachment.table_name}.downloads" + + @containers = [OrgSubfield.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@org_subfield.id)] #modify by Long Jun + # @containers += @org_subfield.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort + + show_attachments @containers + + @attachtype = 0 + @contenttype = 0 + + respond_to do |format| + format.js + format.html { + redirect_to org_subfield_files_url(@org_subfield) + } + end + end end end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 687ef9503..a8d6dfe8f 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -126,14 +126,33 @@ class HomeworkCommonController < ApplicationController if @homework_detail_manual.comment_status == 1 student_works = @homework.student_works if student_works && student_works.size >= 2 - student_works.each_with_index do |work, index| - user = work.user - n = @homework_detail_manual.evaluation_num - n = n < student_works.size ? n : student_works.size - 1 - assigned_homeworks = get_assigned_homeworks(student_works, n, index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) - student_works_evaluation_distributions.save + if @homework.homework_type == 3 + student_work_projects = @homework.student_work_projects.where("student_work_id is not null") + student_work_projects.each_with_index do |pro_work, pro_index| + n = @homework_detail_manual.evaluation_num + n = n < student_works.size ? n : student_works.size - 1 + work_index = -1 + student_works.each_with_index do |stu_work, stu_index| + if stu_work.id.to_i == pro_work.student_work_id.to_i + work_index = stu_index + end + end + assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + else + student_works.each_with_index do |work, index| + user = work.user + n = @homework_detail_manual.evaluation_num + n = n < student_works.size ? n : student_works.size - 1 + assigned_homeworks = get_assigned_homeworks(student_works, n, index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) + student_works_evaluation_distributions.save + end end end @homework_detail_manual.update_column('comment_status', 2) @@ -143,7 +162,8 @@ class HomeworkCommonController < ApplicationController Mailer.send_mail_anonymous_comment_open(@homework).deliver else @statue = 2 - end + + end else @statue = 3 end @@ -262,6 +282,7 @@ class HomeworkCommonController < ApplicationController @user_activity_id = -1 end @is_in_course = params[:is_in_course] + @course_activity = params[:course_activity].to_i end private @@ -276,6 +297,7 @@ class HomeworkCommonController < ApplicationController @homework = HomeworkCommon.find params[:id] @homework_detail_manual = @homework.homework_detail_manual @homework_detail_programing = @homework.homework_detail_programing + @homework_detail_group = @homework.homework_detail_group @course = @homework.course rescue render_404 diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index edf055370..7cdc838e2 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -142,6 +142,13 @@ class IssuesController < ApplicationController @project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq + #id name email + #1. issues list persons + #2. project persons + @at_persons = @journals.map(&:user) + @issue.project.users + @at_persons = @at_persons.uniq{|u| u.id}.delete_if{|u| u.id == User.current.id} + @at_persons = nil + respond_to do |format|`` format.html { retrieve_previous_and_next_issue_ids diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 9b090de9a..6f173b7c2 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -169,6 +169,11 @@ class MessagesController < ApplicationController course_activity.updated_at = Time.now course_activity.save end + forge_activity = ForgeActivity.where("forge_act_type='Message' and forge_act_id=#{@topic.id}").first + if forge_activity + forge_activity.updated_at = Time.now + forge_activity.save + end user_activity = UserActivity.where("act_type='Message' and act_id =#{@topic.id}").first if user_activity user_activity.updated_at = Time.now diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index f462a64e7..0883b3799 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -85,7 +85,7 @@ class MyController < ApplicationController flash[:notice] = l(:notice_mail_notification_updated) redirect_to my_account_url else - redirect_to signin_url + redirect_to signin_url end end @@ -109,12 +109,23 @@ class MyController < ApplicationController # Edit user's account def account @user = User.current + lg=@user.login @pref = @user.pref diskfile = disk_filename('User', @user.id) diskfile1 = diskfile + 'temp' begin if request.post? + # 修改邮箱的时候同步修改到gitlab + if @user.mail != params[:user][:mail] + g = Gitlab.client + begin + g.edit_user(@user.gid, :email => params[:user][:mail]) + rescue + logger.error "sync user's email of gitlab failed!" + end + end + @user.safe_attributes = params[:user] @user.pref.attributes = params[:pref] @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') @@ -212,7 +223,7 @@ class MyController < ApplicationController end flash.now[:error] = l(:notice_account_old_wrong_password) end - render :template => 'my/account',:layout=>'base_users_new' + render :template => 'my/account',:layout=>'new_base_user' end # Create a new feeds key diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index 02527bdfc..b8584fea3 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -11,10 +11,17 @@ class OrgDocumentCommentsController < ApplicationController @org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id) @org_document_comment.title = params[:org_document_comment][:title] @org_document_comment.content = params[:org_document_comment][:content] + if params[:field_id] + @org_document_comment.org_subfield_id = params[:field_id].to_i + end if @org_document_comment.save flash.keep[:notice] = l(:notice_successful_create) - OrgActivity - redirect_to organization_org_document_comments_path(@organization) + EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document_comment.id, :created_at => @org_document_comment.updated_at) + if params[:field_id] + redirect_to organization_path(@organization, :org_subfield_id => params[:field_id]) + else + redirect_to organization_org_document_comments_path(@organization) + end else redirect_to new_org_document_comment_path(:organization_id => @organization.id) end @@ -36,13 +43,18 @@ class OrgDocumentCommentsController < ApplicationController if @org_document.parent.nil? act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first act.update_attributes(:updated_at => @org_document.updated_at) + EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document.id, :created_at => Time.now) end respond_to do |format| format.html { if params[:flag].to_i == 0 redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id) else - redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id) + if params[:flag].to_i == 1 + redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id) + else + redirect_to organization_path(@org_document.organization.id, :org_subfield_id => params[:org_subfield_id]) + end end } end @@ -81,10 +93,10 @@ class OrgDocumentCommentsController < ApplicationController def destroy @org_document_comment = OrgDocumentComment.find(params[:id]) org = @org_document_comment.organization + if @org_document_comment.id == org.home_id + org.update_attributes(:home_id => nil) + end if @org_document_comment.destroy - if @org_document_comment.id == org.id - org.home_id == nil - end end respond_to do |format| format.js diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb new file mode 100644 index 000000000..1dc7885fe --- /dev/null +++ b/app/controllers/org_subfields_controller.rb @@ -0,0 +1,24 @@ +class OrgSubfieldsController < ApplicationController + def create + @subfield = OrgSubfield.create(:name => params[:name]) + @organization = Organization.find(params[:organization_id]) + @organization.org_subfields << @subfield + @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) + end + + def destroy + @subfield = OrgSubfield.find(params[:id]) + @organization = Organization.find(@subfield.organization_id) + @subfield.destroy + end + + def update + @subfield = OrgSubfield.find(params[:id]) + @organization = Organization.find(@subfield.organization_id) + @subfield.update_attributes(:name => params[:name]) + end + + def show + + end +end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index b326051e6..38402f68e 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -37,6 +37,19 @@ class OrganizationsController < ApplicationController @organization = Organization.new render :layout => 'new_base' end + + def edit + @organization = Organization.find(params[:id]) + end + + def destroy + @organization = Organization.find(params[:id]) + @organization.destroy + respond_to do |format| + format.html{ redirect_to admin_organization_path } + end + end + def create @organization = Organization.new @organization.name = params[:organization][:name] @@ -55,29 +68,35 @@ class OrganizationsController < ApplicationController def show if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) @organization = Organization.find(params[:id]) - project_ids = @organization.projects.map(&:id) << 0 - course_ids = @organization.courses.map(&:id) << 0 - course_types = "('Message','News','HomeworkCommon','Poll','Course')" - case params[:type] - when nil - @org_activities = OrgActivity.where("(container_id =? and container_type =?) " + - "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+ - "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))", - @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) - when 'project_issue' - @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'project_message' - @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'org' - @org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_homework' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_news' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_message' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_poll' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + if params[:org_subfield_id] + @org_subfield = OrgSubfield.find(params[:org_subfield_id]) + @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 + @org_activities = OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})").order('updated_at desc').page(params[:page] || 1).per(10) + else + project_ids = @organization.projects.map(&:id) << 0 + course_ids = @organization.courses.map(&:id) << 0 + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + case params[:type] + when nil + @org_activities = OrgActivity.where("(container_id =? and container_type =?) " + + "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+ + "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))", + @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) + when 'project_issue' + @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'project_message' + @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'org' + @org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_homework' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_news' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_message' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_poll' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + end end @page = params[:page] respond_to do |format| @@ -142,6 +161,12 @@ class OrganizationsController < ApplicationController # end end + def cancel_homepage + @org = Organization.find(params[:id]) + @org.home_id = nil + @org.save + end + def autocomplete_search @project = Project.find(params[:project_id]) #@flag = params[:flag] || false @@ -220,6 +245,13 @@ class OrganizationsController < ApplicationController end end + def logout + logout_user + respond_to do |format| + format.html {redirect_to organization_path(params[:id])} + end + end + def search_projects @organization = Organization.find(params[:id]) condition = '%%' diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 715f56d3d..ab2cfa2ba 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -30,7 +30,7 @@ class ProjectsController < ApplicationController before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_project] before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] - before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] + before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar] before_filter :file, :statistics #:watcherlist # 除非项目内人员,不可查看成员, TODO: 完了写报表里去 # before_filter :memberAccess, only: :member @@ -320,9 +320,20 @@ class ProjectsController < ApplicationController @activity.scope_select {|t| !has["show_#{t}"].nil?} =end + @page = params[:page] ? params[:page].to_i + 1 : 0 # 根据私密性,取出符合条件的所有数据 if User.current.member_of?(@project) || User.current.admin? - @events_pages = ForgeActivity.where("project_id = ? and forge_act_type != ?",@project, "Document" ).order("created_at desc").page(params['page'|| 1]).per(20); + case params[:type] + when nil + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'ProjectCreateInfo')",@project).order("updated_at desc").limit(10).offset(@page * 10) + when 'issue' + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'",@project).order("updated_at desc").limit(10).offset(@page * 10) + when 'news' + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'",@project).order("updated_at desc").limit(10).offset(@page * 10) + when 'message' + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Message'",@project).order("updated_at desc").limit(10).offset(@page * 10) + end + #events = @activity.events(@date_from, @date_to) else @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public @@ -686,7 +697,11 @@ class ProjectsController < ApplicationController flash[:error] = l(:error_can_not_archive_project) end end - redirect_to admin_projects_url(:status => params[:status]) + if params[:type] == "project" + redirect_to user_path(User.current) + else + redirect_to admin_projects_url(:status => params[:status]) + end end def unarchive diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index c1e124063..f0b15e8f8 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -31,7 +31,7 @@ class RepositoriesController < ApplicationController default_search_scope :changesets before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo] - before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] + before_filter :find_repository, :only => [:edit, :update, :destroy, :committers, :forked] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo,:to_gitlab] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked] @@ -69,20 +69,22 @@ class RepositoriesController < ApplicationController project = project_from_current_project(@project.id, User.current.id) redirect_to project_path(project) else - # 单个用户只能拥有一个名字一样的版本库,否则不能fork - # if is_sigle_identifier?(User.current, @repository.identifier) - # REDO: 那些人有权限forked项目 + # 自己不能fork自己的项目 + if User.current.id == @project.user_id + flash[:notice] = l(:project_gitlab_fork_own) + redirect_to repository_url(@repository) + else g = Gitlab.client + if User.current.gid.nil? + g.sync_user(User.current) + end gproject = g.fork(@project.gpid, User.current.gid) if gproject copy_project(@project, gproject) forked_count = @project.forked_count.to_i + 1 @project.update_attributes(:forked_count => forked_count) end - # else - # flash[:notice] = l(:project_gitlab_fork_double_message) - # redirect_to settings_project_url(@project, :tab => 'repositories') - # end + end end end @@ -347,27 +349,13 @@ update # end - #add by hx - if g.commits(@project.gpid , :page=>25).count==0 - count = count_commits(@project.gpid , 0 , 25) - elsif g.commits(@project.gpid , :page=>50).count ==0 - count = count_commits(@project.gpid , 25 , 50)+ 25 * 20 - elsif g.commits(@project.gpid , :page=>75).count ==0 - count = count_commits(@project.gpid , 50 , 75)+ 50 * 20 - elsif g.commits(@project.gpid , :page=>100).count== 0 - count = count_commits(@project.gpid , 75 , 100) + 75 * 20 - elsif g.commits(@project.gpid , :page=>125).count==0 - count = count_commits(@project.gpid , 100 , 125) + 100 * 20 - elsif g.commits(@project.gpid , :page=>150).count==0 - count = count_commits(@project.gpid , 125 , 150) + 125 * 20 - else - count = count_commits(@project.gpid , 150 ,200) + 150 * 20 - end - @changesets = g.commits(@project.gpid) + + + @changesets = g.commits(@project.gpid, :ref_name => @rev) # @changesets = @repository.latest_changesets(@path, @rev) # @changesets_count = @repository.latest_changesets(@path, @rev).count - @changesets_all_count = count + @changesets_all_count = 0 @changesets_latest_coimmit = @changesets[0] @properties = @repository.properties(@path, @rev) @repositories = @project.repositories @@ -410,8 +398,28 @@ update limit = 20 #每次页面的换回值从1开始,但是gitlab的页面查询是从0开始,所以先改变page的类型减一在改回来 @commits = g.commits(@project.gpid, page:(params[:page].to_i - 1).to_s) + + #add by hx + if g.commits(@project.gpid , :page=>200).count > 0 + count = 4020 + elsif g.commits(@project.gpid , :page=>25).count==0 + count = count_commits(@project.gpid , 0 , 25) + elsif g.commits(@project.gpid , :page=>50).count ==0 + count = count_commits(@project.gpid , 25 , 50)+ 25 * 20 + elsif g.commits(@project.gpid , :page=>75).count ==0 + count = count_commits(@project.gpid , 50 , 75)+ 50 * 20 + elsif g.commits(@project.gpid , :page=>100).count== 0 + count = count_commits(@project.gpid , 75 , 100) + 75 * 20 + elsif g.commits(@project.gpid , :page=>125).count==0 + count = count_commits(@project.gpid , 100 , 125) + 100 * 20 + elsif g.commits(@project.gpid , :page=>150).count==0 + count = count_commits(@project.gpid , 125 , 150) + 125 * 20 + else + count = count_commits(@project.gpid , 150 ,200) + 150 * 20 + end + #页面传递必须要str类型,但是Paginator的初始化必须要num类型,需要类型转化 - @commits_count = params[:commit_count].to_i + @commits_count = count @commits_pages = Redmine::Pagination::Paginator.new @commits_count,limit,params[:page] @commit = g.commit(@project.gpid,@rev) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index dd2a5b5fc..b79adda2d 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -3,8 +3,8 @@ class StudentWorkController < ApplicationController include StudentWorkHelper require 'bigdecimal' require "base64" - before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:set_score_rule,:forbidden_anonymous_comment,:delete_work] - before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work] + before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students] + before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment] before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :set_score_rule, :forbidden_anonymous_comment] @@ -95,12 +95,27 @@ class StudentWorkController < ApplicationController @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name @show_all = true elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + else + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + end elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 - my_work = @homework.student_works.where(:user_id => User.current.id) + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + my_work = @homework.student_works.where(:id => pro.student_work_id) + else + my_work = @homework.student_works.where(:user_id => User.current.id) + end @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + else + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + end if my_work.empty? @stundet_works = [] else @@ -116,12 +131,27 @@ class StudentWorkController < ApplicationController @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name @show_all = true elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + else + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + end elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 - my_work = @homework.student_works.where(:user_id => User.current.id) + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + my_work = @homework.student_works.where(:id => pro.student_work_id) + else + my_work = @homework.student_works.where(:user_id => User.current.id) + end @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + else + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + end if my_work.empty? @stundet_works = [] else @@ -190,6 +220,10 @@ class StudentWorkController < ApplicationController student_work.user_id = User.current.id student_work.save_attachments(params[:attachments]) render_attachment_warning_if_needed(student_work) + if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 + @student_work_project = @homework.student_work_projects.where("user_id = #{User.current.id}").first + student_work.project_id = @student_work_project.project_id + end #提交作品时,计算是否迟交 if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") student_work.late_penalty = @homework.late_penalty @@ -197,6 +231,35 @@ class StudentWorkController < ApplicationController student_work.late_penalty = 0 end if student_work.save + if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 + @student_work_project.student_work_id = student_work.id + @student_work_project.save + members = params[:group_member_ids].split(',') + for i in 1 .. members.count-1 + stu_project = StudentWorkProject.new + stu_project.homework_common_id = @homework.id + stu_project.student_work_id = student_work.id + stu_project.project_id = @student_work_project.project_id + stu_project.user_id = members[i].to_i + stu_project.is_leader = 0 + stu_project.save + end + elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0 + members = params[:group_member_ids].split(',') + for i in 0 .. members.count-1 + stu_project = StudentWorkProject.new + stu_project.homework_common_id = @homework.id + stu_project.student_work_id = student_work.id + stu_project.project_id = -1 + stu_project.user_id = members[i].to_i + if i == 0 + stu_project.is_leader = 1 + else + stu_project.is_leader = 0 + end + stu_project.save + end + end course_activity = CourseActivity.where("course_act_type='HomeworkCommon' and course_act_id =#{@homework.id}").first if course_activity course_activity.updated_at = Time.now @@ -207,6 +270,9 @@ class StudentWorkController < ApplicationController user_activity.updated_at = Time.now user_activity.save end + course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"new",:course_message_id=>student_work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录 + course_message.save + @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first respond_to do |format| format.js @@ -236,10 +302,11 @@ class StudentWorkController < ApplicationController @submit_result = true @work.name = params[:student_work][:name] @work.description = params[:student_work][:description] - @work.project_id = params[:student_work][:project] @work.save_attachments(params[:attachments]) render_attachment_warning_if_needed(@work) if @work.save + course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"edit",:course_message_id=>@work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录 + course_message.save =begin respond_to do |format| format.html { @@ -276,6 +343,18 @@ class StudentWorkController < ApplicationController 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 + end + end respond_to do |format| format.html { redirect_to student_work_index_url(:homework => @homework.id) @@ -288,12 +367,36 @@ class StudentWorkController < ApplicationController @work = StudentWork.where("user_id =? and homework_common_id =?", User.current.id, @homework.id).first if @work @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 + end + end end redirect_to user_homeworks_user_path(User.current.id) end def retry_work 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 + end + end @student_work = StudentWork.new respond_to do |format| format.js @@ -500,8 +603,9 @@ class StudentWorkController < ApplicationController if params[:student_path] redirect_to student_work_index_url(:homework => @homework.id) else - @user_activity_id = params[:user_activity_id] - @is_in_course = params[:is_in_course] + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i respond_to do |format| format.js end @@ -527,7 +631,102 @@ class StudentWorkController < ApplicationController @course_activity = params[:course_activity].to_i end + def revise_attachment + Attachment.attach_filesex(@work, params[:attachments], params[:attachment_type]) + revise_attachments = @work.attachments.where("attachtype = 7").reorder("created_on desc") + if revise_attachments.count == 2 + revise_attachments.last.destroy + end + #@attachment = @work.attachments.where("attachtype = 7").order("created_on desc").first + respond_to do |format| + format.js + end + end + + def new_student_work_project + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + + #创建作业的关联项目 + def student_work_project + @project = StudentWorkProject.new + @project.homework_common_id = @homework.id + @project.project_id = (Project.find params[:projectName].to_i).id + @project.user_id = User.current.id + @project.is_leader = 1 + if @project.save + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + + end + + #查找学生创建的项目列表 + def search_user_projects + condition = '%%' + if !params[:name].nil? + condition = "%#{params[:name].strip}%".gsub(" ","") + end + @project_ids = Project.where("user_id = #{User.current.id} and name like '#{condition}'") + @first = params[:first].to_i + respond_to do |format| + format.js + end + end + + #查找课程的学生 + def search_course_students + name = "" + unless params[:name].nil? + name = params[:name] + end + all_student_ids = "(" + @homework.course.student.map{|student| student.student_id}.join(",") + ")" + all_students = User.where("id in #{all_student_ids}") + @commit_student_ids = @homework.student_work_projects.map{|student| student.user_id} + @users = searchstudent_by_name all_students,name + respond_to do |format| + format.js + end + end + + def cancel_relate_project + relate_pro = StudentWorkProject.where("user_id = #{User.current.id} and homework_common_id = #{@homework.id}").first + if relate_pro.destroy + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + end + private + def searchstudent_by_name users, name + mems = [] + if name != "" + name = name.to_s.downcase + users.each do |m| + username = m.lastname.to_s.downcase + m.firstname.to_s.downcase + if(m.login.to_s.downcase.include?(name) || m.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name)) + mems << m + end + end + else + mems = users + end + mems + end + def hsd_committed_work?(user, homework) sw = StudentWork.where("user_id =? and homework_common_id =?", user, homework).first sw.nil? ? result = false : result = true @@ -724,7 +923,7 @@ class StudentWorkController < ApplicationController #成绩计算 def set_final_score homework,student_work if homework && homework.homework_detail_manual - if homework.homework_type == 1 #匿评作业 + if homework.homework_type != 2 #匿评作业 if homework.teacher_priority == 1 #教师优先 if student_work.teacher_score student_work.final_score = student_work.teacher_score diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d20fbc05c..91bd4a00c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -551,12 +551,21 @@ class UsersController < ApplicationController ) end end + end + #分组作业 + if homework.homework_type == 3 + homework_detail_group = HomeworkDetailGroup.new + homework.homework_detail_group = homework_detail_group + homework_detail_group.min_num = params[:min_num].to_i + homework_detail_group.max_num = params[:max_num].to_i + homework_detail_group.base_on_project = params[:base_on_project].to_i end if homework.save homework_detail_manual.save if homework_detail_manual homework_detail_programing.save if homework_detail_programing + homework_detail_group.save if homework_detail_group if params[:is_in_course] == "1" redirect_to homework_common_index_path(:course => homework.course_id) diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index c9c4dcce3..df9fd30f2 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -104,6 +104,15 @@ class WordsController < ApplicationController @user = User.find(@journal_destroyed.jour_id) @jours_count = @user.journals_for_messages.where('m_parent_id IS NULL').count @is_user = true + elsif @journal_destroyed.jour_type == 'HomeworkCommon' + @homework = HomeworkCommon.find @journal_destroyed.jour_id + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i end respond_to do |format| format.js diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ad4da60a7..aed57010b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2437,18 +2437,27 @@ module ApplicationHelper link_to "作品(#{homework.student_works.count})",student_work_index_path(:homework => homework.id),:class => "c_blue" else #学生显示提交作品、修改作品等按钮 work = cur_user_works_for_homework homework + project = cur_user_projects_for_homework homework if work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") - link_to "提交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue' + if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 + link_to "提交作品(#{homework.student_works.count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品' + else + link_to "提交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue' + end elsif work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") - link_to "补交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_red' + if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 + link_to "补交作品(#{homework.student_works.count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品' + else + link_to "补交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_red' + end else if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 #匿评作业,且作业状态不是在开启匿评之前 link_to "作品匿评", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "开启匿评后不可修改作品" elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 - link_to "匿评结束", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "匿评已结束" + link_to "查看作品(#{homework.student_works.count})", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "匿评已结束" elsif homework.homework_type == 2 && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")#编程作业不能修改作品 link_to "修改作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue' - elsif Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + elsif Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") && work.user_id == User.current.id link_to "修改作品(#{homework.student_works.count})", edit_student_work_path(work.id),:class => 'c_blue' else link_to "查看作品(#{homework.student_works.count})", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "作业截止后不可修改作品" @@ -2461,6 +2470,24 @@ module ApplicationHelper end + def relate_project homework,is_teacher,is_in_course,user_activity_id,course_activity + if User.current.member_of_course?(homework.course) + if is_teacher + #link_to "已关联(#{homework.student_work_projects.count})",student_work_index_path(:homework => homework.id),:class => "c_blue" + else + projects = cur_user_projects_for_homework homework + works = cur_user_works_for_homework homework + if works.nil? && projects.nil? + link_to "关联项目",new_student_work_project_student_work_index_path(:homework => homework.id,:is_in_course=>is_in_course,:user_activity_id=>user_activity_id,:course_activity=>course_activity),remote: true,:class=> 'c_blue', :title=> '请选择分组作业关联的项目' + elsif works.nil? + link_to "取消关联",cancel_relate_project_student_work_index_path(:homework => homework.id,:is_in_course=>is_in_course,:user_activity_id=>user_activity_id,:course_activity=>course_activity), :confirm => "您确定要取消关联吗?", remote: true,:class => "c_blue", :title=> '取消关联项目' + else + #link_to "已关联(#{homework.student_work_projects.count})",student_work_index_path(:homework => homework.id),:class => "c_blue" + end + end + end + end + def student_anonymous_comment homework if homework.homework_detail_manual case homework.homework_detail_manual.comment_status @@ -2476,7 +2503,20 @@ module ApplicationHelper #获取当前用户在指定作业下提交的作业的集合 def cur_user_works_for_homework homework - homework.student_works.where("user_id = ?",User.current).first + work = homework.student_works.where("user_id = ?",User.current).first + if homework.homework_type == 3 + pro = homework.student_work_projects.where("user_id = #{User.current.id}").first + if pro.nil? || pro.student_work_id == "" || pro.student_work_id.nil? + work = nil + else + work = StudentWork.find pro.student_work_id + end + end + work + end + #获取当前用户在指定作业下关联的项目的集合 + def cur_user_projects_for_homework homework + homework.student_work_projects.where("user_id = ?",User.current).first end def file_preview_tag(file, html_options={}) @@ -2621,4 +2661,38 @@ int main(int argc, char** argv){ true end end + + def import_ke(default_opt={}) + opt = {enable_at: true, prettify: false, init_activity: false}.merge default_opt + ss = '' + if opt[:enable_at] + ss = '" + end + + ss += javascript_include_tag("/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg') + if opt[:enable_at] + ss += javascript_include_tag('/assets/kindeditor/at/jquery.caret.min.js', '/assets/kindeditor/at/jquery.atwho.js', '/assets/kindeditor/at/config.js') + ss += stylesheet_link_tag("/assets/kindeditor/at/jquery.atwho.css") + end + + if opt[:prettify] + ss += javascript_include_tag 'prettify' + ss += stylesheet_link_tag 'prettify' + end + + if opt[:init_activity] + ss += javascript_include_tag "init_activity_KindEditor" + end + + ss.html_safe + end + end diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 9a1765ddc..cf9cbcc32 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -113,7 +113,8 @@ module FilesHelper if attachment.is_public? || (attachment.container_type == "Project" && User.current.member_of?(attachment.project)) || (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))|| - attachment.author_id == User.current.id + attachment.author_id == User.current.id || + attachment.container_type == "OrgSubfield" result << attachment end end diff --git a/app/helpers/org_subfields_helper.rb b/app/helpers/org_subfields_helper.rb new file mode 100644 index 000000000..a9f8a396f --- /dev/null +++ b/app/helpers/org_subfields_helper.rb @@ -0,0 +1,2 @@ +module OrgSubfieldsHelper +end diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index e1cf3464e..df5c872f8 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -126,4 +126,15 @@ module StudentWorkHelper end type end + + def revise_attachment_status homework, attach + date = Time.parse(format_time(attach.created_on.to_s)).strftime("%Y-%m-%d") + status = "" + if homework.homework_detail_manual && ((homework.anonymous_comment == 0 &&homework.homework_detail_manual.evaluation_start.to_s <= date) || (homework.anonymous_comment == 1 && homework.end_time < date)) + status = "此时其他同学作品已公开" + else + status = "此时其他同学作品尚未公开" + end + return status + end end \ No newline at end of file diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 8d4a1a524..ad5655b02 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -22,6 +22,7 @@ class Attachment < ActiveRecord::Base belongs_to :container, :polymorphic => true belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'" belongs_to :course, foreign_key: 'container_id', conditions: "attachments.container_type = 'Course'" + belongs_to :org_subfield, foreign_key: 'container_id', conditions: "attachements.container_type = 'OrgSubfield'" belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'" belongs_to :author, :class_name => "User", :foreign_key => "author_id" belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id" diff --git a/app/models/course.rb b/app/models/course.rb index 8647b82df..0194a2a9d 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -20,7 +20,7 @@ class Course < ActiveRecord::Base end end - attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name + attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 @@ -32,7 +32,7 @@ class Course < ActiveRecord::Base :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})" has_many :principals, :through => :member_principals, :source => :principal has_many :users, :through => :members - has_many :org_courses + has_many :org_courses, :dependent => :destroy has_many :organizations, :through => :org_courses # has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy @@ -86,7 +86,8 @@ class Course < ActiveRecord::Base 'is_public', 'description', 'class_period', - 'open_student' + 'open_student', + 'is_delete' acts_as_customizable @@ -94,7 +95,7 @@ class Course < ActiveRecord::Base scope :active, lambda { where(:status => STATUS_ACTIVE) } scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } scope :all_public, lambda { where(:is_public => true) } - scope :visible, lambda {|*args| where(Course.visible_condition(args.shift || User.current, *args)) } + scope :visible, lambda {|*args| where(Course.where("is_delete =?", 0).visible_condition(args.shift || User.current, *args)) } scope :allowed_to, lambda {|*args| user = User.current permission = nil @@ -114,7 +115,7 @@ class Course < ActiveRecord::Base where(" LOWER(name) LIKE :p ", :p => pattern) end } - scope :indexable,lambda { where('is_public = 1') } + scope :indexable,lambda { where('is_public = 1 and is_delete = 0') } def self.search(query) __elasticsearch__.search( { @@ -399,12 +400,12 @@ class Course < ActiveRecord::Base # __elasticsearch__.delete_document # end def create_course_ealasticsearch_index - if self.is_public == 1 + if self.is_public == 1 and self.is_delete == 0 #公开 和 没有被删除的课程才被索引 self.__elasticsearch__.index_document end end def update_course_ealasticsearch_index - if self.is_public == 1 #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 + if self.is_public == 1 and self.is_delete == 0 #如果是初次更新成为公开或者恢复被删除的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 begin self.__elasticsearch__.update_document rescue => e diff --git a/app/models/course_message.rb b/app/models/course_message.rb index 11b0165c5..79d27f3c5 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -1,5 +1,5 @@ class CourseMessage < ActiveRecord::Base - # status说明: status在课程不同的类型,区分不同的功能 + # status说明: status在课程不同的类型,区分不同的功能 status = 9 作品的提交记录 # HomeworkCommon:status: # nil:发布了作业; 1:作业截止时间到了提醒!;2:开启匿评; 3:关闭匿评; 4:匿评开始失败 attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status @@ -19,7 +19,7 @@ class CourseMessage < ActiveRecord::Base def add_user_message #unless self.course_message_type == 'JoinCourseRequest' - if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? + if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? && self.status != 9 self.message_alls << MessageAll.new(:user_id => self.user_id) end #end diff --git a/app/models/editor_of_document.rb b/app/models/editor_of_document.rb new file mode 100644 index 000000000..15d9e7e37 --- /dev/null +++ b/app/models/editor_of_document.rb @@ -0,0 +1,4 @@ +class EditorOfDocument < ActiveRecord::Base + belongs_to :user, :class_name => 'User', :foreign_key => 'editor_id' + belongs_to :org_document_comment +end \ No newline at end of file diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index bb5f30442..c98c5475b 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -46,18 +46,24 @@ class ForgeActivity < ActiveRecord::Base end def add_org_activity - if self.forge_act_type == 'Message' && !self.forge_act.parent_id.nil? - org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{self.forge_act.parent.id}").first + org_activity = OrgActivity.where("org_act_type = '#{self.forge_act_type.to_s}' and org_act_id = #{self.forge_act_id}").first + if org_activity org_activity.created_at = self.created_at org_activity.save else - OrgActivity.create(:user_id => self.user_id, - :org_act_id => self.forge_act_id, - :org_act_type => self.forge_act_type, - :container_id => self.project_id, - :container_type => 'Project', - :created_at => self.created_at, - :updated_at => self.updated_at) + if self.forge_act_type == 'Message' && !self.forge_act.parent_id.nil? + org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{self.forge_act.parent.id}").first + org_activity.created_at = self.created_at + org_activity.save + else + OrgActivity.create(:user_id => self.user_id, + :org_act_id => self.forge_act_id, + :org_act_type => self.forge_act_type, + :container_id => self.project_id, + :container_type => 'Project', + :created_at => self.created_at, + :updated_at => self.updated_at) + end end end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 8d421a98f..0ad667bd1 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -9,6 +9,8 @@ class HomeworkCommon < ActiveRecord::Base belongs_to :user has_one :homework_detail_manual, :dependent => :destroy has_one :homework_detail_programing, :dependent => :destroy + has_one :homework_detail_group, :dependent => :destroy + has_many :student_work_projects, :dependent => :destroy has_many :homework_tests, :dependent => :destroy has_many :student_works, :dependent => :destroy, :conditions => "is_test=0" has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 @@ -74,6 +76,10 @@ class HomeworkCommon < ActiveRecord::Base self.homework_type == 2 && self.homework_detail_programing end + def is_group_homework? + self.homework_type == 3 && self.homework_detail_group + end + ###添加回复 def self.add_homework_jour(user, notes, id , options = {}) homework = HomeworkCommon.find(id) diff --git a/app/models/homework_detail_group.rb b/app/models/homework_detail_group.rb new file mode 100644 index 000000000..0a9cb5fe2 --- /dev/null +++ b/app/models/homework_detail_group.rb @@ -0,0 +1,4 @@ +class HomeworkDetailGroup < ActiveRecord::Base + belongs_to :homework_common + attr_accessible :base_on_project, :homework_common_id, :max_num, :min_num +end diff --git a/app/models/memo.rb b/app/models/memo.rb index 2ead1cbb6..ee9f4c8db 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -18,10 +18,28 @@ class Memo < ActiveRecord::Base #elasticsearch kaminari init Kaminari::Hooks.init Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari - settings index: { number_of_shards: 5 } do + settings index: { + number_of_shards: 5 , + analysis: { + char_filter: { + and_filter: { + type: "mapping", + mappings: [ "&=> and "] + } + }, + analyzer: { + my_analyzer: { + type: 'custom', + tokenizer: 'standard', + filter: ['classic'], + char_filter: ['html_strip'] + } + } + } + } do mappings dynamic: 'false' do - indexes :subject, analyzer: 'smartcn',index_options: 'offsets' - indexes :content, analyzer: 'smartcn',index_options: 'offsets' + indexes :subject, analyzer: 'smartcn',index_options: 'offsets'#, char_filter: 'html_strip' + indexes :content, analyzer:'my_analyzer',index_options: 'offsets',search_analyzer: 'smartcn' indexes :updated_at,index:"not_analyzed" ,type:'date' end end diff --git a/app/models/message.rb b/app/models/message.rb index 92ec0235e..d8f62171a 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -186,7 +186,7 @@ class Message < ActiveRecord::Base # Description def act_as_forge_activity # 如果project为空,那么就是课程相关的消息 - if !self.board.project.nil? + if !self.board.project.nil? && self.parent_id.nil? self.forge_acts << ForgeActivity.new(:user_id => self.author_id, :project_id => self.board.project.id) end diff --git a/app/models/org_document_comment.rb b/app/models/org_document_comment.rb index 7b9f9cd75..e2ce350ce 100644 --- a/app/models/org_document_comment.rb +++ b/app/models/org_document_comment.rb @@ -3,7 +3,7 @@ class OrgDocumentComment < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :organization belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' - + has_many :editor_of_documents, :dependent => :destroy acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc" has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy after_create :document_save_as_org_activity diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb new file mode 100644 index 000000000..f95bb3eba --- /dev/null +++ b/app/models/org_subfield.rb @@ -0,0 +1,9 @@ +class OrgSubfield < ActiveRecord::Base + belongs_to :organization, :foreign_key => :organization_id + has_many :org_document_comments, :dependent => :destroy + has_many :files + acts_as_attachable + + def project + end +end \ No newline at end of file diff --git a/app/models/organization.rb b/app/models/organization.rb index d3755b5ee..350dc3080 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -5,7 +5,8 @@ class Organization < ActiveRecord::Base has_many :projects,:through => :org_projects has_many :courses, :through => :org_courses has_many :org_document_comments, :dependent => :destroy - has_many :org_courses + has_many :org_courses, :dependent => :destroy + has_many :org_subfields, :dependent => :destroy has_many :users, :through => :org_members validates_uniqueness_of :name after_create :save_as_org_activity diff --git a/app/models/project.rb b/app/models/project.rb index 6495dbe26..cd4036810 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -43,6 +43,7 @@ class Project < ActiveRecord::Base end end + has_many :student_work_projects,:dependent => :destroy has_many :student_works has_many :time_entry_activities has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" @@ -86,6 +87,7 @@ class Project < ActiveRecord::Base # end #ADDED BY NIE + has_one :project_score, :dependent => :destroy has_many :project_infos, :dependent => :destroy has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy has_many :user_grades, :class_name => "UserGrade", :dependent => :destroy diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 010ede635..144f3859f 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -4,12 +4,14 @@ class StudentWork < ActiveRecord::Base belongs_to :homework_common belongs_to :user + has_many :student_work_projects has_many :student_works_evaluation_distributions, :dependent => :destroy has_many :student_works_scores, :dependent => :destroy belongs_to :project has_many :student_work_tests, order: 'id desc' # course's message has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + has_many :attachments, :dependent => :destroy before_destroy :delete_praise before_save :set_program_score, :set_src @@ -44,7 +46,7 @@ class StudentWork < ActiveRecord::Base #成绩计算 def set_final_score homework,student_work if homework && homework.homework_detail_manual - if homework.homework_type == 1 #匿评作业 + if homework.homework_type != 2 #匿评作业 if homework.teacher_priority == 1 #教师优先 if student_work.teacher_score student_work.final_score = student_work.teacher_score diff --git a/app/models/student_work_project.rb b/app/models/student_work_project.rb new file mode 100644 index 000000000..676071817 --- /dev/null +++ b/app/models/student_work_project.rb @@ -0,0 +1,7 @@ +class StudentWorkProject < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :homework_common + belongs_to :student_work + belongs_to :project + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 17b66a43d..0c8d65481 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -107,6 +107,7 @@ class User < Principal has_many :student_works, :dependent => :destroy has_many :student_works_evaluation_distributions, :dependent => :destroy has_many :student_works_scores, :dependent => :destroy + has_many :student_work_projects, :dependent => :destroy #end has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, @@ -226,7 +227,7 @@ class User < Principal validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, :case_sensitive => false validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false # Login must contain letters, numbers, underscores only - validates_format_of :login, :with => /\A[a-z0-9_\-@\.]*\z/i + validates_format_of :login, :with => /\A[a-z0-9_\-\.]*\z/i validates_length_of :login, :maximum => LOGIN_LENGTH_LIMIT validates_length_of :firstname, :maximum => 30 validates_length_of :lastname, :maximum => 30 @@ -409,10 +410,14 @@ class User < Principal else name = lastname+firstname end - name = name.empty? || name.nil? ? login : name - name + name.empty? || name.nil? ? login : name end ## end + + def get_at_show_name + name = show_name + name = "#{name} #{self.login}" if name != self.login + end #added by nie def count_new_journal_reply diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 236dbc731..8df42fb41 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -228,13 +228,22 @@ class UsersService end course_list end - + #修改密码 def change_password params @current_user = User.find(params[:current_user_id]) if @current_user.check_password?(params[:password]) @current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation] @current_user.save + # 修改密码同步gitlab密码修改 + unless @current_user.gid.nil? + begin + g = Gitlab.client + g.edit_user(@current_user.gid, :password => params[:new_password]) + rescue Exception => e + logger.error "change users password failed! ===> #{e}" + end + end #raise @current_user.errors.full_message #return @current_user else diff --git a/app/views/admin/messages.html.erb b/app/views/admin/messages.html.erb index f87741dd9..e4d053d49 100644 --- a/app/views/admin/messages.html.erb +++ b/app/views/admin/messages.html.erb @@ -1,4 +1,6 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: false) %> +<% end %>
<%= textAreailizable act, :description %>
<%= l :label_create_time %> :<%= format_time(e.project.created_on) %>
<%= act.description.html_safe %>
- <%= l :label_activity_time %> :<%= format_activity_day(act.created_on) %> <%= format_time(act.created_on, false) %>
-
<%= act.notes.html_safe %>
- <%= l :label_activity_time %> :<%= format_activity_day(act.created_on) %> <%= format_time(act.created_on, false) %>
<%= textAreailizable act,:content %>
-
<%= textAreailizable act,:description %>
- <%= l :label_create_time %> :<%= format_activity_day(act.created_on) %> <%= format_time(act.created_on, false) %>
<%= textAreailizable act,:description %>
- <%= l :label_create_time %> :<%= format_activity_day(act.created_on) %> <%= format_time(act.created_on, false) %>
<%= text_format(work.description) if work.description%> +
+ 作品名称:<%=@student_work.name%> +
++ 作品描述:<%=@student_work.description%> +
++ 附件: + <% if @student_work.attachments.empty? %> + <%= "无附件"%> + <% else %> +
作品信息完整性校验中,请稍等...
作品信息完整性校验中,请稍等...
<%=project.project_score.score.to_i %>
+