diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index cd1de16fc..0c61c449e 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -374,6 +374,7 @@ class CoursesController < ApplicationController def settings if User.current.allowed_to?(:as_teacher,@course) + @select_tab = params[:tab] @issue_custom_fields = IssueCustomField.sorted.all @issue_category ||= IssueCategory.new @member ||= @course.members.new diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 0c794fe33..a99ab32ec 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -9,6 +9,10 @@ class ExerciseController < ApplicationController publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) publish_exercises.each do |exercise| exercise.update_column('exercise_status', 2) + course = exercise.course + course.members.each do |m| + exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) + end end end_exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now) end_exercises.each do |exercise| @@ -35,6 +39,10 @@ class ExerciseController < ApplicationController publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) publish_exercises.each do |exercise| exercise.update_column('exercise_status', 2) + course = exercise.course + course.members.each do |m| + exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) + end end end_exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now) end_exercises.each do |exercise| @@ -332,6 +340,9 @@ class ExerciseController < ApplicationController @exercise.exercise_status = 2 @exercise.publish_time = Time.now if @exercise.save + @exercise.course.members.each do |m| + @exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2) + end #redirect_to exercise_index_url(:course_id=> @course.id) respond_to do |format| format.js @@ -347,6 +358,7 @@ class ExerciseController < ApplicationController @exercise.exercise_questions.each do |exercise_question| exercise_question.exercise_answers.destroy_all end + @exercise.course_messages.destroy_all @exercise.exercise_users.destroy_all @exercise.exercise_status = 1 @exercise.publish_time = nil @@ -500,6 +512,10 @@ class ExerciseController < ApplicationController @exercise.update_attributes(:show_result => params[:show_result]) @exercise.update_attributes(:exercise_status => 2) @exercise.update_attributes(:publish_time => Time.now) + course = @exercise.course + course.members.each do |m| + @exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) + end redirect_to exercise_url(@exercise) return elsif @exercise.publish_time > Time.now diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 4181090a5..2d2c058d4 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -73,6 +73,7 @@ class MemosController < ApplicationController end end #end + format.js format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } format.json { render json: @memo, status: :created, location: @memo } else @@ -152,6 +153,7 @@ class MemosController < ApplicationController end def update + @flag = false respond_to do |format| if( #@memo.update_column(:subject, params[:memo][:subject]) && @memo.update_column(:content, params[:memo][:content]) && @@ -159,10 +161,12 @@ class MemosController < ApplicationController @memo.update_column(:lock, params[:memo][:lock]) && @memo.update_column(:subject,params[:memo][:subject])) @memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads])) - @memo.save + @flag = @memo.save # @memo.root.update_attribute(:updated_at, @memo.updated_at) + format.js format.html {redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}"} else + format.js format.html { render action: "edit" } format.json { render json: @person.errors, status: :unprocessable_entity } end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 2bd54954a..c1e124063 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -64,32 +64,53 @@ class RepositoriesController < ApplicationController end def forked - # 被forked的标识如果不满足单个用户唯一性,则不执行fork - if is_sigle_identifier?(User.current, @repository.identifier) - # REDO: 那些人有权限forked项目 - g = Gitlab.client - gproject = g.post ("/projects/fork/#{@project.gpid}?user_id=#{User.current.gid}") - if gproject - copy_project(@project, gproject) - end + # 如果当前用户已经fork过该项目,不会新fork项目,则跳至已fork的项 + unless has_forked?(@project, User.current) + project = project_from_current_project(@project.id, User.current.id) + redirect_to project_path(project) else - flash[:notice] = l(:project_gitlab_fork_double_message) - redirect_to settings_project_url(@project, :tab => 'repositories') + # 单个用户只能拥有一个名字一样的版本库,否则不能fork + # if is_sigle_identifier?(User.current, @repository.identifier) + # REDO: 那些人有权限forked项目 + g = Gitlab.client + 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 + + # 判断用户是否已经fork过该项目 + def has_forked?(project, user) + projects = Project.where("user_id =?", user) + projects.map(&:forked_from_project_id).detect{|s| s == @project.id}.nil? ? true : false + end + + # 获取当前用户fork过的项目 + def project_from_current_project(project, user) + project = Project.where("user_id =? and forked_from_project_id =?",user, project).first end # copy a project for fork - def copy_project(project, gproject) + def copy_project(tproject, gproject) project = Project.new - project.name = @project.name - project.is_public = @project.is_public - project.status = @project.status - project.description = @project.description - project.hidden_repo = @project.hidden_repo + project.name = tproject.name + project.is_public = tproject.is_public + project.status = tproject.status + project.description = tproject.description + project.hidden_repo = tproject.hidden_repo project.user_id = User.current.id project.project_type = 0 - project.project_new_type = @project.project_new_type + project.project_new_type = tproject.project_new_type project.gpid = gproject.id + project.forked_from_project_id = tproject.id if project.save r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first m = Member.new(:user => User.current, :roles => [r]) @@ -124,16 +145,16 @@ class RepositoriesController < ApplicationController def copy_repository(project, gproject) # 避免 - if is_sigle_identifier?(project.user_id, gproject.name) + # if is_sigle_identifier?(project.user_id, gproject.name) repository = Repository.factory('Git') repository.project_id = project.id repository.type = 'Repository::Gitlab' repository.url = gproject.name repository.identifier = gproject.name repository = repository.save - else - flash[:notice] = l(:project_gitlab_create_double_message) - end + # else + # flash[:notice] = l(:project_gitlab_create_double_message) + # end end def newrepo diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9ff833f48..834009d71 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -92,7 +92,7 @@ class UsersController < ApplicationController end # 用户消息 - # 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复 + # 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复,exercise:课程测验 # issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment) def user_messages if !User.current.logged? @@ -128,7 +128,7 @@ class UsersController < ApplicationController #课程相关消息 when 'homework' - @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork') and user_id =?", @user).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =?", @user).order("created_at desc") when 'course_message' @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc") when 'course_news' @@ -1429,6 +1429,7 @@ class UsersController < ApplicationController @course = @user.courses .select { |course| @user.allowed_to?(:as_teacher,course)} end + @search = params[:search] #这里仅仅是传递需要发送的资源id @send_id = params[:send_id] @send_ids = params[:checkbox1] || params[:send_ids] @@ -1445,6 +1446,7 @@ class UsersController < ApplicationController else @projects = @user.projects end + @search = params[:search] #这里仅仅是传递需要发送的资源id @send_id = params[:send_id] @send_ids = params[:checkbox1] || params[:send_ids] #搜索的时候 和 直接 用表格提交的时候的send_ids diff --git a/app/models/exercise.rb b/app/models/exercise.rb index d23e8f115..c91e59fd9 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -6,4 +6,18 @@ class Exercise < ActiveRecord::Base has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number" has_many :exercise_users, :dependent => :destroy has_many :users, :through => :exercise_users #该测试被哪些用户提交答案过 + # 课程消息 + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + after_create :acts_as_course_message + def acts_as_course_message + if self.course + if self.exercise_status == 2 #未发布 + #self.course.members.each do |m| + self.course_messages << CourseMessage.create(:user_id => User.current.id, :course_id => self.course_id, :viewed => false,:status=>2) + #end + # else + # self.course_messages.destroy_all 这里的destory_all值得商榷。因为我这里是通过status来控制不同的status的 + end + end + end end diff --git a/app/views/courses/member.html.erb b/app/views/courses/member.html.erb index ce336373b..3aa7d4b57 100644 --- a/app/views/courses/member.html.erb +++ b/app/views/courses/member.html.erb @@ -1,9 +1,14 @@ -