Merge branch 'cxt_course' of http://git.trustie.net/jacknudt/trustieforge into cxt_course

Conflicts:
	app/helpers/application_helper.rb
cxt_course
huang 9 years ago
commit 86516df88a

@ -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/

@ -0,0 +1,3 @@
// Place all the styles related to the shield_activities controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

@ -7,10 +7,14 @@ class AtController < ApplicationController
@logger = Logger.new(Rails.root.join('log', 'at.log').to_s) @logger = Logger.new(Rails.root.join('log', 'at.log').to_s)
users = find_at_users(params[:type], params[:id]) users = find_at_users(params[:type], params[:id])
@users = users @users = users
@users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id } if users @users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }.sort{|x,y| to_pinyin(x.show_name) <=> to_pinyin(y.show_name)} if users
end end
private private
def to_pinyin(s)
Pinyin.t(s).downcase
end
def find_at_users(type, id) def find_at_users(type, id)
@logger.info("#{type}, #{id}") @logger.info("#{type}, #{id}")
case type case type

@ -185,7 +185,6 @@ class AttachmentsController < ApplicationController
end end
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16) @attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
saved = @attachment.save saved = @attachment.save
respond_to do |format| respond_to do |format|
format.js format.js
format.api { format.api {
@ -198,12 +197,43 @@ class AttachmentsController < ApplicationController
end end
end end
def upload_attachment_version
@flag = false
Attachment.transaction do
@old_attachment = Attachment.find params[:old_attachment_id]
#取出当前上传的文件
@attachment = Attachment.find(params[:attachments ].first[1][:attachment_id])
#将需要修改的记录保存到历史记录
@history = AttachmentHistory.new
@history.attributes = @old_attachment.attributes.dup.except("id")
@history.attachment_id = params[:old_attachment_id]
#需要更新版本号,需要拿到原来该文件最大的历史版本号
@old_history = @old_attachment.attachment_histories.reorder('version desc').first
@history.version = @old_history.nil? ? 1 : @old_history.version + 1
@history.save #历史记录保存完毕
#将最新保存的记录 数据替换到 需要修改的文件记录
@old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public")
@old_attachment.save
#删除当前记录
@attachment.delete
@flag = true
end
respond_to do |format|
format.js
end
end
def destroy def destroy
if @attachment.container.respond_to?(:init_journal) if @attachment.container.respond_to?(:init_journal)
@attachment.container.init_journal(User.current) @attachment.container.init_journal(User.current)
end end
if @attachment.container if @attachment.container
@attachment.container.attachments.delete(@attachment) if @attachment.container_type == "Issue"
@attachment.destroy
else
@attachment.container.attachments.delete(@attachment)
end
else else
@attachment.destroy @attachment.destroy
end end
@ -242,6 +272,8 @@ class AttachmentsController < ApplicationController
format.html { redirect_to_referer_or mobile_version_path } format.html { redirect_to_referer_or mobile_version_path }
elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgSubfield) elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgSubfield)
format.html {redirect_to_referer_or org_subfield_files_path(@attachment.container)} format.html {redirect_to_referer_or org_subfield_files_path(@attachment.container)}
elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgDocumentComment)
format.html {redirect_to_referer_or org_document_comment_path(@attachment.container)}
else else
if @project.nil? if @project.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
@ -253,7 +285,7 @@ class AttachmentsController < ApplicationController
format.js format.js
end end
end end
def delete_homework def delete_homework
@bid = @attachment.container.bid @bid = @attachment.container.bid
# Make sure association callbacks are called # Make sure association callbacks are called
@ -316,13 +348,13 @@ class AttachmentsController < ApplicationController
end end
respond_to do |format| respond_to do |format|
format.js format.js
end end
rescue NoMethodError rescue NoMethodError
@save_flag = false @save_flag = false
@save_message = [] << l(:error_attachment_empty) @save_message = [] << l(:error_attachment_empty)
respond_to do |format| respond_to do |format|
format.js format.js
end end
end end
@ -492,6 +524,15 @@ class AttachmentsController < ApplicationController
end end
end end
#找到文件的所有的历史版本
def attachment_versions
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
respond_to do |format|
format.js
end
end
private private
def find_project def find_project
@attachment = Attachment.find(params[:id]) @attachment = Attachment.find(params[:id])

@ -10,7 +10,7 @@ class AvatarController < ApplicationController
unless request.content_type == 'application/octet-stream' unless request.content_type == 'application/octet-stream'
@source_type = params[:source_type] @source_type = params[:source_type]
@source_id = params[:source_id] @source_id = params[:source_id]
@temp_file = params[:avatar][:image] @temp_file = params[:avatar][:image]
@image_file = @temp_file.original_filename @image_file = @temp_file.original_filename
else else
unless request.raw_post.nil? unless request.raw_post.nil?
@ -23,7 +23,7 @@ class AvatarController < ApplicationController
#image_file.force_encoding("UTF-8") if filename.respond_to?(:force_encoding) #image_file.force_encoding("UTF-8") if filename.respond_to?(:force_encoding)
else else
@image_file=params[:filename] @image_file=params[:filename]
end end
@temp_file = StringIO.new(@temp_file) @temp_file = StringIO.new(@temp_file)
end end
end end

@ -52,7 +52,11 @@ class BlogCommentsController < ApplicationController
render_attachment_warning_if_needed(@article) render_attachment_warning_if_needed(@article)
else else
end end
redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id]) if params[:is_homepage]
redirect_to user_blogs_path(params[:user_id])
else
redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id])
end
end end
def destroy def destroy
@article = BlogComment.find(params[:id]) @article = BlogComment.find(params[:id])

@ -1,5 +1,5 @@
class BlogsController < ApplicationController class BlogsController < ApplicationController
before_filter :find_blog,:except => [:index,:create,:new] before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage]
before_filter :find_user before_filter :find_user
def index def index
@articls = @user.blog.articles @articls = @user.blog.articles
@ -26,6 +26,18 @@ class BlogsController < ApplicationController
def edit def edit
end end
def set_homepage
@blog = Blog.find(params[:id])
@blog.update_attribute(:homepage_id, params[:article_id])
redirect_to user_blogs_path(params[:user_id])
end
def cancel_homepage
@blog = Blog.find(params[:id])
@blog.update_attribute(:homepage_id, nil)
redirect_to user_blogs_path(params[:user_id])
end
private private
def find_blog def find_blog
if params[:blog_id] if params[:blog_id]

@ -18,8 +18,8 @@
class BoardsController < ApplicationController class BoardsController < ApplicationController
layout 'base_projects'#by young layout 'base_projects'#by young
default_search_scope :messages default_search_scope :messages
before_filter :find_project_by_project_id, :find_board_if_available before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields]
before_filter :authorize, :except => [:new, :show, :create, :index] before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields]
accept_rss_auth :index, :show accept_rss_auth :index, :show
@ -79,13 +79,12 @@ class BoardsController < ApplicationController
end end
end end
end end
# 更新@消息为已读
@project.boards.each do |board| @project.boards.each do |board|
board.messages.each do |m| board.messages.each do |m|
User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!} User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!}
end end
end end
elsif @course elsif @course
query_course_messages = @board.messages query_course_messages = @board.messages
query_course_messages.each do |query_course_message| query_course_messages.each do |query_course_message|
@ -106,43 +105,19 @@ class BoardsController < ApplicationController
@is_new = params[:is_new] @is_new = params[:is_new]
@topic_count = @board ? @board.topics.count : 0 @topic_count = @board ? @board.topics.count : 0
if @project if @project
@topic_pages = Paginator.new @topic_count, per_page_option, params['page'] if @board
#现在发布帖子的时候置顶功能已经没有了。所以取消这个置顶排序 #{Message.table_name}.sticky DESC, limit = 10;
@topics = @board.topics. @topic_count = @board.topics.count();
reorder("#{Message.table_name}.created_on desc"). @topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
includes(:last_reply). @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
limit(@topic_pages.per_page). limit(limit).offset(@topic_pages).includes(:last_reply).
offset(@topic_pages.offset). preload(:author, {:last_reply => :author}).all();
else
preload(:author, {:last_reply => :author}). @topics = [];
all end
elsif @course elsif @course
#
# board_topics = @board ? @board.topics.reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc").
# includes(:last_reply).
# # limit(@topic_pages.per_page).
# # offset(@topic_pages.offset).
#
# preload(:author, {:last_reply => :author}).
# all : []
# @topics = paginateHelper board_topics,10
if (@board) if (@board)
limit = 10; limit = 10;
#pageno = params[:page];
#if(pageno == nil || pageno=='')
# dw_topic = nil;
# if( params[:parent_id]!=nil && params[:parent_id]!='' )
# dw_topic = @board.topics.where(id:params[:parent_id]).first();
# end
# if( dw_topic != nil )
# dw_count = @board.topics.where('(sticky>?) or (sticky=? and created_on>?)',dw_topic.sticky,dw_topic.sticky,dw_topic.created_on).count();
# dw_count = dw_count+1;
# pageno = dw_count%10==0 ? (dw_count/limit) : (dw_count/limit+1)
# end
#end
#if(pageno == nil || pageno=='')
# pageno=1;
#end
@topic_count = @board.topics.count(); @topic_count = @board.topics.count();
@topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10 @topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc"). @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
@ -225,6 +200,16 @@ class BoardsController < ApplicationController
redirect_to_settings_in_projects redirect_to_settings_in_projects
end end
def join_to_org_subfields
if params[:id]
@board = Board.find(params[:id])
@org_subfield_ids = params[:org_subfield_ids]
@org_subfield_ids.each do |id|
OrgSubfieldBoard.create(:org_subfield_id => id.to_i, :board_id => params[:id].to_i)
end
end
end
private private
def redirect_to_settings_in_projects def redirect_to_settings_in_projects
redirect_to settings_project_url(@project, :tab => 'boards') redirect_to settings_project_url(@project, :tab => 'boards')

@ -54,16 +54,9 @@ class CommentsController < ApplicationController
# end # end
# # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add end # # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add end
#flash[:notice] = l(:label_comment_added) #flash[:notice] = l(:label_comment_added)
course_activity = CourseActivity.where("course_act_type='News' and course_act_id =#{@news.id}").first update_course_activity(@news.class,@news.id)
if course_activity update_user_activity(@news.class,@news.id)
course_activity.updated_at = Time.now update_org_activity(@news.class,@news.id)
course_activity.save
end
user_activity = UserActivity.where("act_type='News' and act_id =#{@news.id}").first
if user_activity
user_activity.updated_at = Time.now
user_activity.save
end
end end
if params[:user_activity_id] if params[:user_activity_id]

@ -1,3 +1,4 @@
#encoding: utf-8
class CoursesController < ApplicationController class CoursesController < ApplicationController
# layout 'base_courses' # layout 'base_courses'
include CoursesHelper include CoursesHelper
@ -38,15 +39,17 @@ class CoursesController < ApplicationController
end end
limit = 15 limit = 15
course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:id]}").map(&:organization_id) course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:id]}").map(&:organization_id)
if course_org_ids.empty? #@orgs_not_in_course = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit)
@orgs_not_in_course = Organization.where("(is_public or creator_id =?) and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit) #@org_count = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).count
@org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count if course_org_ids.empty?
else @orgs_not_in_course = User.current.organizations.where("name like ?",condition).page((params[:page].to_i || 1)).per(limit)
course_org_ids = "(" + course_org_ids.join(',') + ")" @org_count = @orgs_not_in_course.count
@orgs_not_in_course = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit) else
@org_count = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count course_org_ids = "(" + course_org_ids.join(',') + ")"
end @orgs_not_in_course = User.current.organizations.where("organizations.id not in #{course_org_ids} and organizations.name like ?", condition).page((params[:page].to_i || 1)).per(limit)
# @course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count @org_count = @orgs_not_in_course.empty? ? 0 : @orgs_not_in_course.count
end
@course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count
@orgs_page = Paginator.new @org_count, limit,params[:page] @orgs_page = Paginator.new @org_count, limit,params[:page]
@hint_flag = params[:hint_flag] @hint_flag = params[:hint_flag]
#render :json => {:orgs => @orgs_not_in_course, :count => @org_count}.to_json #render :json => {:orgs => @orgs_not_in_course, :count => @org_count}.to_json
@ -399,6 +402,25 @@ class CoursesController < ApplicationController
end end
def private_or_public
if @course.is_public == 0
@course.update_attributes(:is_public => 1)
else
@course.update_attributes(:is_public => 0)
end
if @course.is_public == 0
course_status = CourseStatus.find_by_course_id(@course.id)
course_status.destroy if course_status
elsif @course.is_public == 1
course_status = CourseStatus.find_by_course_id(@course.id)
course_status.destroy if course_status
course_status = CourseStatus.create(:course_id => @course.id, :grade => 0)
end
respond_to do |format|
format.js
end
end
def search_member def search_member
if User.current.allowed_to?(:as_teacher,@course) || User.current.admin if User.current.allowed_to?(:as_teacher,@course) || User.current.admin
q = "#{params[:name].strip}" q = "#{params[:name].strip}"
@ -417,6 +439,73 @@ class CoursesController < ApplicationController
def create def create
cs = CoursesService.new cs = CoursesService.new
@course = cs.create_course(params,User.current)[:course] @course = cs.create_course(params,User.current)[:course]
if params[:copy_course]
copy_course = Course.find params[:copy_course].to_i
@course.update_attributes(:open_student => copy_course.open_student, :publish_resource => copy_course.publish_resource)
if params[:checkAll]
attachments = copy_course.attachments
attachments.each do |attachment|
attach_copied_obj = attachment.copy
attach_copied_obj.tag_list.add(attachment.tag_list) # tag关联
attach_copied_obj.container = @course
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.copy_from = attachment.copy_from.nil? ? attachment.id : attachment.copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
attach_copied_obj.save
update_quotes attach_copied_obj
end
elsif params[:course_attachment_type]
copy_attachments = []
params[:course_attachment_type].each do |type|
case type
when "1"
tag_name = l(:label_courseware)
when "2"
tag_name = l(:label_software)
when "3"
tag_name = l(:label_media)
when "4"
tag_name = l(:label_code)
when "6"
tag_name = "论文"
else
tag_name = ""
end
if tag_name == ""
tag_attachments = copy_course.attachments.select{|attachment|
!attachment.tag_list.include?('课件') &&
!attachment.tag_list.include?('软件') &&
!attachment.tag_list.include?('媒体') &&
!attachment.tag_list.include?('代码') &&
!attachment.tag_list.include?('论文') }
else
tag_attachments = copy_course.attachments.select{|attachment| attachment.tag_list.include?(tag_name)}
end
tag_attachments.each do |attach|
next if copy_attachments.include?(attach)
copy_attachments << attach
end
end
unless copy_attachments.blank?
copy_attachments.each do |c_attach|
attach_copied_obj = c_attach.copy
attach_copied_obj.tag_list.add(c_attach.tag_list) # tag关联
attach_copied_obj.container = @course
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.copy_from = c_attach.copy_from.nil? ? c_attach.id : c_attach.copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
attach_copied_obj.save
update_quotes attach_copied_obj
end
end
end
end
if @course if @course
respond_to do |format| respond_to do |format|
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)
@ -732,6 +821,11 @@ class CoursesController < ApplicationController
#param id:已有课程ID #param id:已有课程ID
def copy_course def copy_course
if @course if @course
@new_course = Course.new
respond_to do |format|
format.js
end
=begin
@new_course = Course.new @course.attributes @new_course = Course.new @course.attributes
@new_course.tea_id = User.current.id @new_course.tea_id = User.current.id
@new_course.created_at = DateTime.now @new_course.created_at = DateTime.now
@ -750,6 +844,7 @@ class CoursesController < ApplicationController
@new_course.course_infos << course @new_course.course_infos << course
redirect_to settings_course_url @new_course redirect_to settings_course_url @new_course
end end
=end
else else
render_404 render_404
end end
@ -810,6 +905,33 @@ class CoursesController < ApplicationController
end end
private private
def update_quotes attachment
if attachment.copy_from
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")
else
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}")
end
attachment.quotes = get_qute_number attachment
attachment.save
attachments.each do |att|
att.quotes = attachment.quotes
att.save
end
end
def get_qute_number attachment
if attachment.copy_from
result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}")
else
result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}")
end
if result.nil? || result.count <= 0
return 0
else
return result[0].number
end
end
def allow_join course def allow_join course
if course_endTime_timeout? course if course_endTime_timeout? course
respond_to do |format| respond_to do |format|

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -63,6 +63,7 @@ class HomeworkCommonController < ApplicationController
end end
@homework.end_time = params[:homework_common][:end_time] || Time.now @homework.end_time = params[:homework_common][:end_time] || Time.now
@homework.course_id = params[:course_id] @homework.course_id = params[:course_id]
@homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0
homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new
if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0

@ -81,10 +81,11 @@ class IssuesController < ApplicationController
@status_id = params[:status_id] @status_id = params[:status_id]
@subject = params[:subject] @subject = params[:subject]
@issue_count = @query.issue_count @issue_count = @query.issue_count
@issue_pages = Paginator.new @issue_count, @limit, params['page'].to_i + 1 @issue_pages = Paginator.new @issue_count, @limit, params['page']
params[:page] = (params[:page] || 1).to_i + 1 #页码需要加1
@offset ||= @issue_pages.offset @offset ||= @issue_pages.offset
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
:order => sort_clause, :order => 'issues.updated_on desc',
:offset => @offset, :offset => @offset,
:limit => @limit) :limit => @limit)
if params[:set_filter] if params[:set_filter]
@ -136,6 +137,7 @@ class IssuesController < ApplicationController
end end
end end
# end # end
@jour_reply = Journal.new
@journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
@journals.each_with_index {|j,i| j.indice = i+1} @journals.each_with_index {|j,i| j.indice = i+1}
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
@ -152,6 +154,7 @@ class IssuesController < ApplicationController
@project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young @project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young
@available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
@journal = Journal.new(:journalized => @issue)
respond_to do |format| respond_to do |format|
format.html { format.html {
@ -400,14 +403,16 @@ class IssuesController < ApplicationController
jour.user_id = User.current.id jour.user_id = User.current.id
jour.notes = params[:notes] jour.notes = params[:notes]
jour.journalized = @issue jour.journalized = @issue
jour.save_attachments(params[:attachments])
jour.save jour.save
user_activity = UserActivity.where("act_type='Issue' and act_id =#{@issue.id}").first update_user_activity(@issue.class,@issue.id)
user_activity.updated_at = jour.created_on update_forge_activity(@issue.class,@issue.id)
user_activity.save
@user_activity_id = params[:user_activity_id] @user_activity_id = params[:user_activity_id]
if params[:issue_id] if params[:issue_id]
@issue_id = params[:issue_id] @issue_id = params[:issue_id]
end end
@priorities = IssuePriority.active
respond_to do |format| respond_to do |format|
format.js format.js
end end
@ -450,9 +455,9 @@ class IssuesController < ApplicationController
@issue = Issue.find params[:id] @issue = Issue.find params[:id]
jour.journalized = @issue jour.journalized = @issue
jour.save jour.save
user_activity = UserActivity.where("act_type='Issue' and act_id =#{@issue.id}").first update_user_activity(@issue.class,@issue.id)
user_activity.updated_at = jour.created_on update_forge_activity(@issue.class,@issue.id)
user_activity.save
respond_to do |format| respond_to do |format|
format.js format.js
end end

@ -22,8 +22,8 @@ class MessagesController < ApplicationController
default_search_scope :messages default_search_scope :messages
before_filter :find_board, :only => [:new, :preview,:edit] before_filter :find_board, :only => [:new, :preview,:edit]
before_filter :find_attachments, :only => [:preview] before_filter :find_attachments, :only => [:preview]
before_filter :find_message, :except => [:new, :preview] before_filter :find_message, :except => [:new, :preview, :join_org_subfield, :get_subfield_on_click_org, :join_org_subfields]
before_filter :authorize, :except => [:preview, :edit, :destroy, :new] before_filter :authorize, :except => [:preview, :edit, :destroy, :new,:join_org_subfield, :get_subfield_on_click_org, :join_org_subfields]
helper :boards helper :boards
helper :watchers helper :watchers
@ -75,7 +75,7 @@ class MessagesController < ApplicationController
@replies = paginateHelper messages_replies,10 @replies = paginateHelper messages_replies,10
@reply = Message.new(:subject => "RE: #{@message.subject}") @reply = Message.new(:subject => "RE: #{@message.subject}")
render :action => "show", :layout => "base_courses"#by young render :action => "show", :layout => "base_courses"#by young
else elsif @project
@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
@replies = @topic.children. @replies = @topic.children.
includes(:author, :attachments, {:board => :project}). includes(:author, :attachments, {:board => :project}).
@ -86,6 +86,18 @@ class MessagesController < ApplicationController
@reply = Message.new(:subject => "RE: #{@message.subject}") @reply = Message.new(:subject => "RE: #{@message.subject}")
render :action => "show", :layout => "base_projects"#by young render :action => "show", :layout => "base_projects"#by young
else
@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
@replies = @topic.children.
includes(:author, :attachments, {:board => :project}).
reorder("#{Message.table_name}.created_on DESC").
limit(@reply_pages.per_page).
offset(@reply_pages.offset).
all
@reply = Message.new(:subject => "RE: #{@message.subject}")
@organization = @org_subfield.organization
render :action => "show", :layout => "base_org"#by young
end end
end end
@ -164,26 +176,11 @@ class MessagesController < ApplicationController
@reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject] @reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject]
# @reply.reply_id = params[:id] # @reply.reply_id = params[:id]
@topic.children << @reply @topic.children << @reply
course_activity = CourseActivity.where("course_act_type='Message' and course_act_id =#{@topic.id}").first update_course_activity(@topic.class,@topic.id)
if course_activity update_user_activity(@topic.class,@topic.id)
course_activity.updated_at = Time.now update_forge_activity(@topic.class,@topic.id)
course_activity.save update_org_activity(@topic.class,@topic.id)
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
user_activity.save
end
org_activity = OrgActivity.where("org_act_type='Message' and org_act_id =#{@topic.id}").first
if org_activity
org_activity.updated_at = Time.now
org_activity.save
end
#@topic.update_attribute(:updated_on, Time.now) #@topic.update_attribute(:updated_on, Time.now)
if !@reply.new_record? if !@reply.new_record?
if params[:asset_id] if params[:asset_id]
@ -199,6 +196,8 @@ class MessagesController < ApplicationController
end end
if params[:user_activity_id] if params[:user_activity_id]
@user_activity_id = params[:user_activity_id] @user_activity_id = params[:user_activity_id]
@is_course = params[:is_course]
@is_board = params[:is_board]
respond_to do |format| respond_to do |format|
format.js format.js
end end
@ -219,39 +218,52 @@ class MessagesController < ApplicationController
@isReply = false @isReply = false
if @project if @project
(render_403; return false) unless @message.editable_by?(User.current) (render_403; return false) unless @message.editable_by?(User.current)
else elsif @course
(render_403; return false) unless @message.course_editable_by?(User.current) (render_403; return false) unless @message.course_editable_by?(User.current)
else
(render_403; return false) unless @message.org_subfield_editable_by?(User.current)
end end
@message.safe_attributes = params[:message] @message.safe_attributes = params[:message]
if request.post? && @message.save if request.post? && @message.save
attachments = Attachment.attach_files(@message, params[:attachments]) attachments = Attachment.attach_files(@message, params[:attachments])
render_attachment_warning_if_needed(@message) render_attachment_warning_if_needed(@message)
flash[:notice] = l(:notice_successful_update) #flash[:notice] = l(:notice_successful_update)
@message.reload @message.reload
if params[:is_board] if params[:is_course] && params[:is_course].to_i == 0
redirect_to user_activities_path(User.current.id)
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
if @project if @project
redirect_to project_boards_path(@project) redirect_to project_path(@project)
elsif @course elsif @course
redirect_to course_boards_path(@course) redirect_to course_activity_path(@course)
end end
else elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
redirect_to board_message_url(@message.board, @message.root, :r => (@message.parent_id && @message.id))
end
elsif request.get? || request.post?
if params[:is_board]
if @project if @project
redirect_to project_boards_path(@project) redirect_to project_boards_path(@project)
elsif @course elsif @course
redirect_to course_boards_path(@course) redirect_to course_boards_path(@course)
end end
else else
respond_to do |format| redirect_to board_message_url(@message.board, @message.root, :r => (@message.parent_id && @message.id))
format.html { end
layout_file = @project ? 'base_projects' : 'base_courses' elsif request.get? || request.post?
render :layout => layout_file if params[:is_course] && params[:is_board]
} @is_course = params[:is_course]
end @is_board = params[:is_board]
end
respond_to do |format|
format.html {
if @project
layout_file = 'base_projects'
elsif @course
layout_file = 'base_courses'
elsif @org_subfield
@organization = @org_subfield.organization
layout_file = 'base_org'
end
render :layout => layout_file
}
end end
end end
end end
@ -260,26 +272,46 @@ class MessagesController < ApplicationController
def destroy def destroy
if @project if @project
(render_403; return false) unless @message.destroyable_by?(User.current) (render_403; return false) unless @message.destroyable_by?(User.current)
else elsif @course
(render_403; return false) unless @message.course_destroyable_by?(User.current) (render_403; return false) unless @message.course_destroyable_by?(User.current)
else
(render_403; return false) unless @message.org_subfield_editable_by?(User.current)
end end
r = @message.to_param r = @message.to_param
@message.destroy @message.destroy
# modify by nwb # modify by nwb
if @project if @project
if params[:is_board] if params[:is_course] && params[:is_course].to_i == 0
redirect_to project_boards_url(@project) redirect_to user_activities_path(User.current.id)
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
redirect_to project_path(@project)
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
redirect_to project_boards_path(@project)
elsif @message.parent
redirect_to board_message_url(@board, @message.parent, :r => r)
else else
redirect_to board_message_url(@board, @topic, :r => @reply) redirect_to project_board_url(@project, @board)
end end
elsif @course elsif @course
if params[:is_course] && params[:is_course].to_i == 0
redirect_to user_activities_path(User.current.id)
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
redirect_to course_activity_path(@course)
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
redirect_to course_boards_path(@course)
elsif @message.parent
redirect_to board_message_url(@board, @message.parent, :r => r)
else
redirect_to course_boards_path(@course)
end
elsif @org_subfield
if params[:is_board] if params[:is_board]
redirect_to course_boards_url(@course) redirect_to organization_path(:id => @org_subfield.organization_id, :org_subfield_id => @org_subfield.id)
else else
if @message.parent if @message.parent
redirect_to board_message_url(@board, @message.parent, :r => r) redirect_to board_message_url(@board, @message.parent, :r => r)
else else
redirect_to course_board_url(@course, @board) redirect_to organization_path(:id => @org_subfield.organization_id, :org_subfield_id => @org_subfield.id)
end end
end end
end end
@ -301,6 +333,41 @@ class MessagesController < ApplicationController
render :partial => 'common/preview' render :partial => 'common/preview'
end end
def join_org_subfield
@message = Message.find(params[:message_id])
@organizations = User.current.organizations
end
def get_subfield_on_click_org
@org = Organization.find(params[:organization_id])
end
def join_org_subfields
org_subfield_ids = params[:org_subfields]
@message = Message.find(params[:id])
# @message.update_attribute(:updated_on, Time.now)
# type = @message.board.course_id.nil? ? "Project":"Course"
org_subfield_ids.each do |field_id|
@message.quotes = @message.quotes.nil? ? 1 : (@message.quotes + 1)
@message.save
board = OrgSubfield.find(field_id).boards.first
mes = Message.create(:board_id => board.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id,
:created_on => Time.now, :updated_on => Time.now, :locked => @message.locked, :sticky => @message.sticky)
@message.attachments.each do |attach|
mes.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
:downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
:is_public => attach.is_public, :quotes => 0)
end
# OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => mes.id, :message_type => type)
# org_acts = OrgActivity.where("container_type='OrgSubfield' and container_id=? and org_act_type='Message' and org_act_id=?", field_id.to_i, @message.id)
# if org_acts.all.size() > 0
# org_acts.first.update_attribute(:updated_at, Time.now)
# else
OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => mes.id, :user_id => User.current.id)
# end
end
end
private private
def find_message def find_message
return unless find_board return unless find_board
@ -317,6 +384,9 @@ class MessagesController < ApplicationController
@project = @board.project @project = @board.project
elsif @board.course_id elsif @board.course_id
@course = @board.course @course = @board.course
else
@org_subfield = @board.org_subfield
@organization = @org_subfield
end end
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound

@ -1,16 +1,18 @@
class OrgDocumentCommentsController < ApplicationController class OrgDocumentCommentsController < ApplicationController
before_filter :find_organization, :only => [:new, :create, :show, :index] before_filter :find_organization, :only => [:new, :create, :show, :index]
helper :attachments
layout 'base_org' layout 'base_org'
def new def new
@org_document_comment = OrgDocumentComment.new @org_document_comment = OrgDocumentComment.new
end end
def create def create
@org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id) @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.title = params[:org_document_comment][:title]
@org_document_comment.content = params[:org_document_comment][:content] @org_document_comment.content = params[:org_document_comment][:content]
@org_document_comment.save_attachments(params[:attachments])
if params[:field_id] if params[:field_id]
@org_document_comment.org_subfield_id = params[:field_id].to_i @org_document_comment.org_subfield_id = params[:field_id].to_i
end end
@ -26,6 +28,7 @@ class OrgDocumentCommentsController < ApplicationController
redirect_to new_org_document_comment_path(:organization_id => @organization.id) redirect_to new_org_document_comment_path(:organization_id => @organization.id)
end end
end end
def show def show
@document = OrgDocumentComment.find(params[:id]) @document = OrgDocumentComment.find(params[:id])
end end
@ -37,9 +40,12 @@ class OrgDocumentCommentsController < ApplicationController
render_403 render_403
end end
end end
def update def update
@org_document = OrgDocumentComment.find(params[:id]) @org_document = OrgDocumentComment.find(params[:id])
@org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content]) @org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content])
Attachment.attach_files(@org_document, params[:attachments])
# @org_document.save_attachments(params[:attachments])
if @org_document.parent.nil? if @org_document.parent.nil?
act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first
act.update_attributes(:updated_at => @org_document.updated_at) act.update_attributes(:updated_at => @org_document.updated_at)

@ -1,24 +1,32 @@
class OrgSubfieldsController < ApplicationController class OrgSubfieldsController < ApplicationController
def create def create
@subfield = OrgSubfield.create(:name => params[:name]) @subfield = OrgSubfield.create(:name => params[:name])
@organization = Organization.find(params[:organization_id]) @organization = Organization.find(params[:organization_id])
@organization.org_subfields << @subfield @organization.org_subfields << @subfield
@subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type])
end end
def destroy def show
@subfield = OrgSubfield.find(params[:id]) @org_subfield = OrgSubfield.find(params[:id])
@organization = Organization.find(@subfield.organization_id) @organization = @org_subfield.organization.id
@subfield.destroy @messages = []
end @messages << @org_subfield.org_document_comments
@messages << @org_subfield.messages
def update @messages.sort{|a, b| b.updated_at <=> a.updated_at}
@subfield = OrgSubfield.find(params[:id]) respond_to do |format|
@organization = Organization.find(@subfield.organization_id) format.html{render :layout => 'base_org'}
@subfield.update_attributes(:name => params[:name]) end
end end
def destroy
def show @subfield = OrgSubfield.find(params[:id])
@organization = Organization.find(@subfield.organization_id)
end @subfield.destroy
end end
def update
@subfield = OrgSubfield.find(params[:id])
@organization = Organization.find(@subfield.organization_id)
@subfield.update_attributes(:name => params[:name])
end
end

File diff suppressed because it is too large Load Diff

@ -5,39 +5,73 @@ class PraiseTreadController < ApplicationController
def praise_plus def praise_plus
@obj = nil @obj = nil
# @is_in_list = nil @activity = false
if request.get? if request.get?
@obj_id = params[:obj_id] @obj_id = params[:obj_id]
@obj_type = params[:obj_type] @obj_type = params[:obj_type]
@horizontal = params[:horizontal].downcase == "false" ? false:true if !params[:user_activity_id].nil? && !params[:type].nil?
@user_activity_id = params[:user_activity_id]
@type = params[:type]
@activity = true
end
# @is_in_list = nil
@obj = find_object_by_type_and_id(@obj_type,@obj_id) @obj = find_object_by_type_and_id(@obj_type,@obj_id)
unless @obj.author_id == User.current.id pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id)
unless pts.empty?
respond_to do |format|
format.js
end
return
end
#@horizontal = params[:horizontal].downcase == "false" ? false:true
if @obj.respond_to?("author_id")
author_id = @obj.author_id
elsif @obj.respond_to?("user_id")
author_id = @obj.user_id
end
unless author_id == User.current.id
praise_tread_plus(@obj_type,@obj_id,1) praise_tread_plus(@obj_type,@obj_id,1)
end end
respond_to do |format|
format.js
end
end end
end end
def praise_minus def praise_minus
@obj = nil @obj = nil
@activity = false
if request.get? if request.get?
@obj = params[:obj] # 传的是对象最后变成id了 #@obj = params[:obj] # 传的是对象最后变成id了
#首先更新praise_tread 表 删除关注记录 #首先更新praise_tread 表 删除关注记录
@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user") #@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user")
@pt.delete @obj_id = params[:obj_id]
@obj_type = params[:obj_type]
if !params[:user_activity_id].nil? && !params[:type].nil?
@user_activity_id = params[:user_activity_id]
@type = params[:type]
@activity = true
end
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
@pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first
if @pt.nil?
respond_to do |format|
format.js
end
return
end
@pt.delete if !@pt.nil?
#再更新praise_tread_cache表 使相应的记录减1 当为0时删除 #再更新praise_tread_cache表 使相应的记录减1 当为0时删除
@ptc = PraiseTreadCache.find_by_object_id(@obj) @ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first
@ptc.minus(1) @ptc.minus(1) if !@ptc.nil?
if @ptc.praise_num == 0 if @ptc.praise_num == 0
@ptc.delete @ptc.delete
end end
end end
@obj = User.find_by_id(@obj) #@obj = User.find_by_id(@obj)
respond_to do |format| respond_to do |format|
format.html
format.js format.js
end end
end end
@ -48,7 +82,7 @@ class PraiseTreadController < ApplicationController
if request.get? if request.get?
@obj_id = params[:obj_id] @obj_id = params[:obj_id]
@obj_type = params[:obj_type] @obj_type = params[:obj_type]
@horizontal = params[:horizontal].downcase == "false" ? false:true #@horizontal = params[:horizontal].downcase == "false" ? false:true
@obj = find_object_by_type_and_id(@obj_type,@obj_id) @obj = find_object_by_type_and_id(@obj_type,@obj_id)
unless @obj.author_id == User.current.id unless @obj.author_id == User.current.id
praise_tread_plus(@obj_type,@obj_id,0) praise_tread_plus(@obj_type,@obj_id,0)
@ -83,6 +117,16 @@ class PraiseTreadController < ApplicationController
@obj = Memo.find_by_id(id) @obj = Memo.find_by_id(id)
when 'Message' when 'Message'
@obj = Message.find_by_id(id) @obj = Message.find_by_id(id)
when 'HomeworkCommon'
@obj = HomeworkCommon.find_by_id(id)
when 'JournalsForMessage'
@obj = JournalsForMessage.find_by_id(id)
when 'News'
@obj = News.find_by_id(id)
when 'Comment'
@obj = Comment.find_by_id(id)
when 'Journal'
@obj = Journal.find_by_id(id)
end end
return @obj return @obj
end end
@ -106,10 +150,6 @@ class PraiseTreadController < ApplicationController
@ptc.save @ptc.save
@ptc.plus(flag,1) @ptc.plus(flag,1)
end end
respond_to do |format|
format.html
format.js
end
end end
end end

@ -76,16 +76,17 @@ class ProjectsController < ApplicationController
condition = "%#{params[:name].strip}%".gsub(" ","") condition = "%#{params[:name].strip}%".gsub(" ","")
end end
limit = 15 limit = 15
project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id) project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id) << 0
if project_org_ids.empty? @orgs_not_in_project = User.current.organizations.where("organizations.id not in (#{project_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit)
@orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit) @org_count = User.current.organizations.where("organizations.id not in (#{project_org_ids.join(',')}) and organizations.name like '#{condition}'").count
@org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count # if project_org_ids.empty?
else # @orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit)
project_org_ids = "(" + project_org_ids.join(',') + ")" # @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
@orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit) # else
@org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count # project_org_ids = "(" + project_org_ids.join(',') + ")"
end # @orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit)
# @project_count = Project.project_entities.visible.like(params[:name]).page(params[:page]).count # @org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
# end
@orgs_page = Paginator.new @org_count, limit,params[:page] @orgs_page = Paginator.new @org_count, limit,params[:page]
@no_roll_hint = params[:hint_flag] @no_roll_hint = params[:hint_flag]
#render :json => {:orgs => @orgs_not_in_project, :count => @org_count}.to_json #render :json => {:orgs => @orgs_not_in_project, :count => @org_count}.to_json

@ -31,8 +31,8 @@ class RepositoriesController < ApplicationController
default_search_scope :changesets default_search_scope :changesets
before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo] before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo]
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers, :forked] before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo,:to_gitlab] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked]
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked] before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked]
accept_rss_auth :revisions accept_rss_auth :revisions
@ -64,6 +64,8 @@ class RepositoriesController < ApplicationController
end end
def forked def forked
@project = Project.find(params[:id])
@repository = Repository.where("project_id =? and type =?", @project.id, "Repository::Gitlab")
# 如果当前用户已经fork过该项目不会新fork项目则跳至已fork的项 # 如果当前用户已经fork过该项目不会新fork项目则跳至已fork的项
unless has_forked?(@project, User.current) unless has_forked?(@project, User.current)
project = project_from_current_project(@project.id, User.current.id) project = project_from_current_project(@project.id, User.current.id)
@ -76,7 +78,11 @@ class RepositoriesController < ApplicationController
else else
g = Gitlab.client g = Gitlab.client
if User.current.gid.nil? if User.current.gid.nil?
g.sync_user(User.current) begin
g.sync_user(User.current)
ensure
logger.error "Synv user failed ==>#{User.current.id}"
end
end end
gproject = g.fork(@project.gpid, User.current.gid) gproject = g.fork(@project.gpid, User.current.gid)
if gproject if gproject

@ -0,0 +1,43 @@
class ShieldActivitiesController < ApplicationController
def create
if params[:org_id]
if params[:project_id]
ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
elsif params[:course_id]
ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i)
end
elsif params[:user_id]
if params[:project_id]
ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
elsif params[:course_id]
ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i)
end
end
end
def show_acts
if params[:org_id]
if params[:project_id]
ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act|
act.destroy
end
# ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
elsif params[:course_id]
ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act|
act.destroy
end
end
elsif params[:user_id]
if params[:project_id]
ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act|
act.destroy
end
# ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
elsif params[:course_id]
ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act|
act.destroy
end
end
end
end
end

@ -259,16 +259,10 @@ class StudentWorkController < ApplicationController
stu_project.save stu_project.save
end end
end end
course_activity = CourseActivity.where("course_act_type='HomeworkCommon' and course_act_id =#{@homework.id}").first update_course_activity(@homework.class,@homework.id)
if course_activity update_user_activity(@homework.class,@homework.id)
course_activity.updated_at = Time.now update_org_activity(@homework.class,@homework.id)
course_activity.save
end
user_activity = UserActivity.where("act_type='HomeworkCommon' and act_id =#{@homework.id}").first
if user_activity
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 = 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 course_message.save
@ -649,7 +643,8 @@ class StudentWorkController < ApplicationController
if revise_attachments.count == 2 if revise_attachments.count == 2
revise_attachments.last.destroy revise_attachments.last.destroy
end end
#@attachment = @work.attachments.where("attachtype = 7").order("created_on desc").first attachment = @work.attachments.where("attachtype = 7").first
attachment.update_attributes(:description => params[:description])
respond_to do |format| respond_to do |format|
format.js format.js
end end

@ -1,4 +1,5 @@
class SystemMessagesController < ApplicationController class SystemMessagesController < ApplicationController
# before_filter :message_author, :only => [:show] # before_filter :message_author, :only => [:show]
# #
# def message_author # def message_author
@ -41,6 +42,7 @@ class SystemMessagesController < ApplicationController
@system_messages.description = params[:system_message][:description] @system_messages.description = params[:system_message][:description]
@system_messages.subject = params[:system_message][:subject] @system_messages.subject = params[:system_message][:subject]
@system_messages.user_id = User.current.id @system_messages.user_id = User.current.id
# @system_messages.save_attachments(params[:attachments])
respond_to do |format| respond_to do |format|
if @system_messages.save if @system_messages.save
format.html {redirect_to user_system_messages_path(User.current)} format.html {redirect_to user_system_messages_path(User.current)}

@ -228,6 +228,12 @@ class TagsController < ApplicationController
@select_tag_name = params[:select_tag_name] @select_tag_name = params[:select_tag_name]
end end
if @obj && @object_flag == '6' && @obj.container.kind_of?(Project)
@project = @obj.container
@tag_list = get_course_tag_list @project
@select_tag_name = params[:select_tag_name]
end
if @obj && @object_flag == '6' && @obj.container.kind_of?(OrgSubfield) if @obj && @object_flag == '6' && @obj.container.kind_of?(OrgSubfield)
@org_subfield = @obj.container @org_subfield = @obj.container
@tag_list = get_org_subfield_tag_list @org_subfield @tag_list = get_org_subfield_tag_list @org_subfield
@ -320,6 +326,88 @@ class TagsController < ApplicationController
end end
end end
def update_project_tag_name
@tag_name = params[:tagName]
@rename_tag_name = params[:renameName]
@taggable_id = params[:taggableId]
@taggable_type = numbers_to_object_type(params[:taggableType])
@project_id = params[:projectId]
@rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag
@tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank?
@obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank?
if @taggable_id.blank? #如果没有传tag_id那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。
if @project_id
project = Project.find @project_id
if project
project.attachments.each do |attachment|
taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class)
if taggings
taggings.delete
attachment.tag_list.add(@rename_tag_name.split(","))
attachment.save
end
end
end
end
else
if(@rename_tag.nil?) #这次命名的是新的tag
# 是否还有其他记录 引用了 tag_id
@tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}")
# 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字
if @tagging.count == 1
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
@tag.update_attributes({:name=>@rename_tag_name})
else #如果tagging表中的记录大于1那么就要新增tag记录
unless @obj.nil?
@obj.tag_list.add(@rename_tag_name.split(","))
@obj.save
end
#删除原来的对应的taggings的记录
unless @taggings.nil?
@taggings.delete
end
end
else #这是已有的tag
# 更改taggings记录里的tag_id
unless @taggings.nil?
@taggings.update_attributes({:tag_id=>@rename_tag.id})
end
end
end
@obj_flag = params[:taggableType]
if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project)
@project = @obj.container
@tag_list = @tag_list = get_course_tag_list @project
elsif @project_id
@project = Project.find(@project_id)
@tag_list = get_project_tag_list @project
#这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。
@flag = params[:flag] || false
sort = ""
@sort = ""
@order = ""
@is_remote = false
@isproject = false
sort = "#{Attachment.table_name}.created_on desc"
@containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)]
show_attachments @containers
elsif @obj && @obj_flag == '5'
@forum = @obj
end
respond_to do |format|
format.js
end
end
def update_org_subfield_tag_name def update_org_subfield_tag_name
@tag_name = params[:tagName] @tag_name = params[:tagName]
@rename_tag_name = params[:renameName] @rename_tag_name = params[:renameName]
@ -458,6 +546,10 @@ class TagsController < ApplicationController
@course = @obj.container @course = @obj.container
@tag_list = @tag_list = get_course_tag_list @course @tag_list = @tag_list = get_course_tag_list @course
end end
if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project)
@project = @obj.container
@tag_list = @tag_list = get_project_tag_list @project
end
if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield) if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield)
@org_subfield = @obj.container @org_subfield = @obj.container
@tag_list = @tag_list = get_org_subfield_tag_list @org_subfield @tag_list = @tag_list = get_org_subfield_tag_list @org_subfield

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save