diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 16d516f82..c53dcbed5 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -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') diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index 29b728268..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) EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document_comment.id, :created_at => @org_document_comment.updated_at) - redirect_to organization_org_document_comments_path(@organization) + 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 @@ -46,7 +53,7 @@ class OrgDocumentCommentsController < ApplicationController 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) + redirect_to organization_path(@org_document.organization.id, :org_subfield_id => params[:org_subfield_id]) end end } diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 6fdf0ae40..00b88fdaa 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -3,7 +3,7 @@ class OrgSubfieldsController < ApplicationController @subfield = OrgSubfield.create(:name => params[:name]) @organization = Organization.find(params[:organization_id]) @organization.org_subfields << @subfield - @subfield.update_attributes(:priority => @subfield.id) + @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) end def destroy diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index d182640ed..38402f68e 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -68,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| diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 7c12ff8ab..f0b15e8f8 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -349,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 @@ -412,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/models/org_subfield.rb b/app/models/org_subfield.rb index 1660310f8..efe9699c3 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -1,3 +1,4 @@ class OrgSubfield < ActiveRecord::Base belongs_to :organization, :foreign_key => :organization_id + has_many :org_document_comments, :dependent => :destroy end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 9c437a186..b9d9de029 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -226,7 +226,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 diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 236dbc731..8b39c39ab 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -235,6 +235,15 @@ class UsersService 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/my/account.html.erb b/app/views/my/account.html.erb index be178607f..dc9ee10b6 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -170,7 +170,7 @@