diff --git a/.gitignore b/.gitignore index fdb7a3c6b..22d9e17e6 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ vendor/cache /public/images/avatars /public/files /tags +/config/initializers/gitlab_config.rb diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 42f1e2f20..ce0d7481a 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -56,12 +56,20 @@ class BlogCommentsController < ApplicationController end def destroy @article = BlogComment.find(params[:id]) - if @article.parent_id.nil? #如果是文章被删,那么跳转到用户博客界面 - @article.children.delete - @article.delete - redirect_to user_blogs_path(:user_id=>User.current) + if @article.parent_id.nil? #如果是文章被删,那么跳转到用户博客界面,如果带了course_id过来,那么就要跳转到课程首页 + if params[:course_id] #如果带了课程id过来,说明这是课程大纲,不要删除,只需取消课程大纲就ok了 + @course = Course.find(params[:course_id]) + @course.outline = 0 + @course.save + redirect_to course_path(:id=>params[:course_id]) + else + @article.children.delete + @article.delete + redirect_to user_blogs_path(:user_id=>User.current) + end + else#如果是回复被删, - if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的 + if params[:course_id] #如果带了course_id过来了,那么这是要跳到课程大纲去的 @article.delete redirect_to show_course_outline_course_path(:id=>params[:course_id]) else diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3c211b361..c9d632fec 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -715,6 +715,7 @@ 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 @@ -732,6 +733,7 @@ class CoursesController < ApplicationController def set_course_outline @course.outline = params[:outline_id] @course.save + @is_in_show_outline_page = params[:is_in_show_outline_page] respond_to do |format| format.js end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 55807886b..3db7ada2b 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -47,10 +47,18 @@ class HomeworkCommonController < ApplicationController if params[:homework_common] @homework.name = params[:homework_common][:name] @homework.description = params[:homework_common][:description] + if params[:homework_common][:publish_time] == "" + @homework.publish_time = Date.today + else + @homework.publish_time = params[:homework_common][:publish_time] + end @homework.end_time = params[:homework_common][:end_time] || Time.now @homework.course_id = params[:course_id] homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new + if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 + homework_detail_manual.comment_status = 1 + end homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? @homework.end_time + 7 : params[:evaluation_start] homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end] diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f41dbe6c7..06c1a67e4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -263,7 +263,7 @@ update @course_tag = params[:course] project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT ip = RepositoriesHelper::REPO_IP_ADDRESS - gitlab_address = RepositoriesHelper::REPO_GITLAB_ADDRESS + gitlab_address = Redmine::Configuration['gitlab_address'] if @repository.type.to_s=="Repository::Gitlab" @repos_url = "http://"+gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git" else diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7c41dd038..d79083919 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -243,7 +243,7 @@ class UsersController < ApplicationController #status 1 同意 2 拒绝 def dealwith_apply_request @msg = CourseMessage.find(params[:msg_id]) - + #CourseMessage content存的是role 7教辅 9 教师 case params[:agree] when 'Y' apply_user = User.find(@msg.course_message_id) @@ -368,8 +368,12 @@ class UsersController < ApplicationController if User.current == @user @page = params[:page] ? params[:page].to_i + 1 : 0 user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" - @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true) + if @is_teacher + @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) + else + @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids} and publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) + end @is_in_course = params[:is_in_course].to_i || 0 respond_to do |format| format.js @@ -493,8 +497,12 @@ class UsersController < ApplicationController homework = HomeworkCommon.new homework.name = params[:homework_common][:name] homework.description = params[:homework_common][:description] - homework.end_time = params[:homework_common][:end_time] || Time.now - homework.publish_time = Time.now + homework.end_time = params[:homework_common][:end_time] || Date.today + if params[:homework_common][:publish_time] == "" + homework.publish_time = Date.today + else + homework.publish_time = params[:homework_common][:publish_time] + end homework.homework_type = params[:homework_type].to_i || 1 homework.late_penalty = 10 homework.teacher_priority = 1 @@ -506,7 +514,11 @@ class UsersController < ApplicationController homework_detail_manual = HomeworkDetailManual.new homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3 - homework_detail_manual.comment_status = 1 + if homework.publish_time > Date.today + homework_detail_manual.comment_status = 0 + else + homework_detail_manual.comment_status = 1 + end homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? homework.end_time + 7 : params[:evaluation_start] homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end] homework_detail_manual.evaluation_num = params[:evaluation_num] || 3 diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index ba99fe454..f32bef51b 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -45,6 +45,11 @@ module RepositoriesHelper end end + def user_commit_rep(mail) + user = User.find_by_mail(mail) + user.nil? ? User.find(2) : User.find_by_mail(mail) + end + def render_properties(properties) unless properties.nil? || properties.empty? content = '' diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 03a7644a2..8d421a98f 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -23,7 +23,8 @@ class HomeworkCommon < ActiveRecord::Base :description => :description, :author => :author, :url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}} - after_create :act_as_activity, :send_mail, :act_as_course_activity, :act_as_course_message + after_create :act_as_activity, :send_mail, :act_as_course_message + after_save :act_as_course_activity after_destroy :delete_kindeditor_assets def act_as_activity @@ -33,17 +34,27 @@ class HomeworkCommon < ActiveRecord::Base #课程动态公共表记录 def act_as_course_activity if self.course - self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.course_id) + if self.homework_detail_manual.comment_status == 0 + self.course_acts.destroy_all + else + if self.course_acts.size == 0 + self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.course_id) + end + end end end #课程作业消息记录 def act_as_course_message if self.course - self.course.members.each do |m| - # if m.user_id != self.user_id + if self.homework_detail_manual.comment_status == 0 + self.course_messages.destroy_all + else + self.course.members.each do |m| + # if m.user_id != self.user_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - # end + # end + end end end end @@ -54,7 +65,9 @@ class HomeworkCommon < ActiveRecord::Base end def send_mail - Mailer.run.homework_added(self) + if self.homework_detail_manual.comment_status != 0 + Mailer.run.homework_added(self) + end end def is_program_homework? diff --git a/app/models/user.rb b/app/models/user.rb index b75b67a1a..e68fc7d8e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -260,7 +260,7 @@ class User < Principal @blog = Blog.where("author_id = #{self.id}").all[0] if @blog.nil? #如果某个user的blog不存在,那么就创建一条,并且跳转 - @blog = Blog.create(:name=>(User.find(self.id).realname), + @blog = Blog.create(:name=>(User.find(self.id).realname.blank? ? User.find(self.id).login : User.find(self.id).realname ), :description=>'', :author_id=>self.id) @blog.save diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 8092bee88..74580632f 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -301,26 +301,46 @@ class CoursesService #@state == 5 您还未登录 #@state == 6 申请成功,请等待审核完毕 #@state == 7 您已经发送过申请了,请耐心等待 + #@state == 8 您已经是该课程的教师了 + #@state == 9 您已经是该课程的教辅了 #@state 其他 未知错误,请稍后再试 def join_course params,current_user course = Course.find_by_id params[:object_id] + @state = 10 if course if course_endTime_timeout? course @state = 2 else if current_user.member_of_course?(course) #如果已经是成员 + member = course.members.where("user_id=#{current_user.id} and course_id=#{course.id}")[0] + roleName = member.roles[0].name if member if params[:course_password] == course.password - #如果加入角色为学生 - if params[:role] == "10" + #如果加入角色为学生 并且当前是学生 + if params[:role] == "10" && roleName == "Student" @state = 3 - elsif current_user.allowed_to?(:as_teacher,course) - @state = 3 - else - Mailer.run.join_course_request(course, User.current, params[:role]) - #如果加入角色为教师或者教辅 - 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',:status=>0) - @state = 6 + #如果加入的角色为老师,并且当前已经是老师 + elsif params[:role] == "9" && roleName == "Teacher" + @state = 8 + #如果加入的角色教辅并且当前为教辅 + elsif params[:role] == "7" && roleName == "TeachingAsistant" + @state = 9 + #如果加入角色为教师或者教辅,并且当前是学生,或者是要成为教辅,当前不是教辅,或者要成为教师,当前不是教师。那么要发送请求 + elsif (params[:role] != "10" && roleName == "Student") || (params[:role] == "7" && roleName != "TeachingAsistant" ) || (params[:role] == "9" && roleName != "Teacher" ) + #如果已经发送过消息了,那么就要给个提示 + if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and content = #{params[:role]} and course_message_id = #{User.current.id} and course_id = #{course.id} and status = 0 ").count != 0 + @state = 7 + else + Mailer.run.join_course_request(course, User.current, params[:role]) + 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',:status=>0) + @state = 6 + end + #如果加入角色是学生,但是是当前课程的教师或者教辅 + elsif params[:role] == "10" && roleName != "Student" + member.role_ids = [params[:role]] + member.save + StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) + @state = 0 end else @state = 1 diff --git a/app/views/blog_comments/_simple_ke_reply_form.html.erb b/app/views/blog_comments/_simple_ke_reply_form.html.erb index d65dd3faa..61669058b 100644 --- a/app/views/blog_comments/_simple_ke_reply_form.html.erb +++ b/app/views/blog_comments/_simple_ke_reply_form.html.erb @@ -23,7 +23,7 @@
- 发送 + 发送 <% end%> diff --git a/app/views/courses/_course_outlines_list.html.erb b/app/views/courses/_course_outlines_list.html.erb index b8a8bfd2a..6710c22ba 100644 --- a/app/views/courses/_course_outlines_list.html.erb +++ b/app/views/courses/_course_outlines_list.html.erb @@ -10,6 +10,7 @@ <%= form_tag(url_for(:controller=>'courses',:action=>'set_course_outline',:id=>course.id),:method=>'post',:remote=>'true') do %> +