From ea308736657c38b7a048a26eb22f369d2e37bad7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 29 Nov 2016 17:02:36 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=88=9B=E5=BB=BA=EF=BC=8C=E6=88=96?= =?UTF-8?q?=E5=85=B3=E9=97=ADPullRequest=E6=97=B6=EF=BC=8C=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=B6=88=E6=81=AF=EF=BC=88=E6=9C=AA=E5=AE=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 13 +++++----- app/views/users/_user_message_forge.html.erb | 25 +++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 0b6a73440..d3d60bf5a 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -98,15 +98,15 @@ class PullRequestsController < ApplicationController @fork_project_name = Project.find(params[:target_project_id]).try(:name) @fork_pr_message = true if @fork_project_name # 发送消息 - #send_message(User.current.id, target_project_id, title) + send_message(User.current.id, target_project_id, request.id) # 创建Trustie数据 - #PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id) + PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id) else request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch) # 发送消息 - #send_message(User.current.id, @project.id, title) + send_message(User.current.id, @project.id, request.id) # 创建Trustie数据 - #PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => @project.id) + PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => @project.id) respond_to do |format| format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)} end @@ -295,8 +295,9 @@ class PullRequestsController < ApplicationController end private - def send_message user_id, project_id, title - self.forge_acts << ForgeMessage.new(:user_id => user_id, :project_id => project_id, :title => title) + def send_message user_id, project_id, pull_request_id + self.forge_acts << ForgeMessage.new(:user_id => user_id, :project_id => project_id, + :forge_message_id => pull_request_id, :forge_message_type => "PullRequest", :viewed => true) end def authorize_logged diff --git a/app/views/users/_user_message_forge.html.erb b/app/views/users/_user_message_forge.html.erb index 54eea89c0..95a079714 100644 --- a/app/views/users/_user_message_forge.html.erb +++ b/app/views/users/_user_message_forge.html.erb @@ -194,24 +194,31 @@
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> - + <% end %> <% end %> \ No newline at end of file From 2cee4448ea30f129e09d632864b680f92cf78b93 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 29 Nov 2016 18:19:29 +0800 Subject: [PATCH 2/7] =?UTF-8?q?pullrequest=E6=B6=88=E6=81=AF=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=EF=BC=88=E6=9C=AA=E5=AE=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/users_helper.rb | 14 ++++++++++++++ app/views/users/_user_message_forge.html.erb | 10 +++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 4dd3399a3..14064c11f 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -90,6 +90,20 @@ module UsersHelper end end + # 获取pullrequest消息状态 + def pull_request_message_status ma + case ma.status + when 1 + "创建了PullRequest:" + when 2 + "接受了您的PullRequest:" + when 3 + "重新打开了PullRequest:" + when 4 + "关闭了您的PullRequest:" + end + + end # 判断当前用户能否对消息进行操作 def allow_to_show applied_message (User.current.id == applied_message.user_id && applied_message.status == 1) ? true : false diff --git a/app/views/users/_user_message_forge.html.erb b/app/views/users/_user_message_forge.html.erb index 95a079714..c28c40065 100644 --- a/app/views/users/_user_message_forge.html.erb +++ b/app/views/users/_user_message_forge.html.erb @@ -206,16 +206,12 @@ <%=link_to User.find(ma.forge_message.author).show_name, user_path(ma.forge_message.author), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> "> - <% if ma.status == 1 %> - 创建了PullRequest: - <% elsif ma.status == 3 %> - 重新打开了PullRequest: - <% end %> + <%= pull_request_message_status(ma) %>
  • - <%= link_to "#{ma.forge_message.forge_message_id.title}", - {:controller => 'pull_requests', :action => 'show', :id => ma.forge_message.project_id },:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :target => '_blank' %> + <%= link_to "#{ma.forge_message.forge_message_id.title}", {:controller => 'pull_requests', :action => 'show', :id => ma.forge_message.project_id }, + :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :target => '_blank' %>
  • <%= time_tag(ma.created_at).html_safe %>
  • From 9fa4b5613a7053b1ae7b01949c6832e6946e39d2 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 30 Nov 2016 08:37:56 +0800 Subject: [PATCH 3/7] =?UTF-8?q?pullrequest=E5=8F=91=E9=80=81=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index d3d60bf5a..9cb2d2c02 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -296,7 +296,7 @@ class PullRequestsController < ApplicationController private def send_message user_id, project_id, pull_request_id - self.forge_acts << ForgeMessage.new(:user_id => user_id, :project_id => project_id, + ForgeMessage.create(:user_id => user_id, :project_id => project_id, :forge_message_id => pull_request_id, :forge_message_type => "PullRequest", :viewed => true) end From 2e5cd96bb9b85046aec8dc44cf993d6979c932dd Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 1 Dec 2016 11:31:48 +0800 Subject: [PATCH 4/7] =?UTF-8?q?pullrequest=E5=8F=91=E9=80=81=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 56 ++++++++++++++++--- app/helpers/users_helper.rb | 4 +- app/models/pull_request.rb | 2 +- app/views/repositories/show.html.erb | 20 +++---- app/views/users/_user_message_course.html.erb | 8 +-- app/views/users/_user_message_forge.html.erb | 16 +++--- ...61129032534_add_status_to_pull_requests.rb | 5 -- ...0161130031415_add_titil_to_pull_requsts.rb | 5 ++ 8 files changed, 80 insertions(+), 36 deletions(-) delete mode 100644 db/migrate/20161129032534_add_status_to_pull_requests.rb create mode 100644 db/migrate/20161130031415_add_titil_to_pull_requsts.rb diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 9cb2d2c02..7da5a0dc1 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -97,16 +97,31 @@ class PullRequestsController < ApplicationController request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch, :target_project_id => target_project_id) @fork_project_name = Project.find(params[:target_project_id]).try(:name) @fork_pr_message = true if @fork_project_name - # 发送消息 - send_message(User.current.id, target_project_id, request.id) + # fork项目的pullrequest发送消息 + # 向管理员发送消息 + @project_member = Member.where(:project_id => params[:target_project_id].to_i) + unless @project_member.nil? + @project_member.each do |mem| + if is_project_manager?(mem.user_id, params[:target_project_id].to_i) && mem.user_id != User.current.id + send_message(mem.user_id, params[:target_project_id].to_i, request.id, 1) + end + end + end # 创建Trustie数据 - PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id) + PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id, :title => title) else + @project_member = Member.where(:project_id => @project.id) request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch) # 发送消息 - send_message(User.current.id, @project.id, request.id) + unless @project_member.nil? + @project_member.each do |mem| + if is_project_manager?(mem.user_id, @project.id) && mem.user_id != User.current.id + send_message(mem.user_id, @project.id, request.id, 1) + end + end + end # 创建Trustie数据 - PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => @project.id) + PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => @project.id, :title => title) respond_to do |format| format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)} end @@ -180,6 +195,14 @@ class PullRequestsController < ApplicationController begin status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid) PullRequest.create(:pull_request_id => status.id, :user_id => User.current.id, :gpid => status.project_id) + + # 接受后,给用户发消息 + request = @g.merge_request(@project.gpid, params[:id]) + if User.current.login != request.author.try(:username) + message_user = User.where( :login => request.author.try(:username) ).first + send_message(message_user.id, @project.id, request.id, 2) + end + respond_to do |format| format.js{redirect_to project_pull_request_path(status.id, :project_id => @project.id)} end @@ -205,6 +228,25 @@ class PullRequestsController < ApplicationController def update_pull_request begin @g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state]) + + # 自己关闭/重新打开 就给每个管理员发送消息,如果是管理员关闭/重新打开,就给用户发消息 + request = @g.merge_request(@project.gpid, params[:id]) + @project_member = Member.where(:project_id => @project.id) + # 发送消息 + if ( params[:state] == "close" || params[:state] == "reopen" ) && User.current.login == request.author.try(:username) + unless @project_member.nil? + @project_member.each do |mem| + if is_project_manager?(mem.user_id, @project.id) && mem.user_id != User.current.id + send_message(mem.user_id, @project.id, request.id, params[:state] == "close" ? 4 : 3) + end + end + end + end + if ( params[:state] == "close" || params[:state] == "reopen" ) && User.current.login != request.author.try(:username) + message_user = User.where( :login => request.author.try(:username) ).first + send_message(message_user.id, @project.id, request.id, params[:state] == "close" ? 4 : 3) + end + respond_to do |format| format.html{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)} end @@ -295,9 +337,9 @@ class PullRequestsController < ApplicationController end private - def send_message user_id, project_id, pull_request_id + def send_message user_id, project_id, pull_request_id, status ForgeMessage.create(:user_id => user_id, :project_id => project_id, - :forge_message_id => pull_request_id, :forge_message_type => "PullRequest", :viewed => true) + :forge_message_id => pull_request_id, :forge_message_type => "PullRequest", :viewed => true, :status => status) end def authorize_logged diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 14064c11f..98024954d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -96,11 +96,11 @@ module UsersHelper when 1 "创建了PullRequest:" when 2 - "接受了您的PullRequest:" + "接受了PullRequest:" when 3 "重新打开了PullRequest:" when 4 - "关闭了您的PullRequest:" + "关闭了PullRequest:" end end diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index ec13ff16b..92f9b56a6 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -1,6 +1,6 @@ class PullRequest < ActiveRecord::Base # status 1:创建 2:接受 3:重新打开 4:关闭 - attr_accessible :gpid, :pull_request_id, :user_id, :status + attr_accessible :gpid, :pull_request_id, :user_id, :project_id, :title validates_uniqueness_of :pull_request_id has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 282df48c3..05b8d40d0 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -27,17 +27,17 @@ <% unless @entries.nil? %> ZIP下载 - <% if User.current.member_of?(@project) && @project.is_public? %> - <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> - <%= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "1"), :remote => true, :class => "btn_zipdown fr" %> - <% else %> - <%= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fr" %> - <% end %> - <% end %> - <% end %> - <% unless QualityAnalysis.where(:project_id => @project.id).first.nil? %> - <%= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fr" %> + <%# if User.current.member_of?(@project) && @project.is_public? %> + <%# if quality_analysis(User.current.try(:login), @repository.id).nil? %> + <%#= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "1"), :remote => true, :class => "btn_zipdown fr" %> + <%# else %> + <%#= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fr" %> + <%# end %> + <%# end %> <% end %> + <%# unless QualityAnalysis.where(:project_id => @project.id).first.nil? %> + <%#= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fr" %> + <%# end %>
    <%=link_to "代码统计", stats_repository_project_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :creator => @creator, :default_branch => @g_default_branch ), :class => "fl vl_zip" %> diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index b1936e19b..f43b87360 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -304,7 +304,7 @@
  • - <%=link_to User.find(ma.course_message.user).show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> + <%=link_to ma.course_message.user.show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> ">发布了问卷:
  • @@ -327,7 +327,7 @@
  • - <%=link_to User.find(ma.course_message.author).show_name, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> + <%=link_to User.find(ma.course_message.author_id).show_name, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> "> <%= ma.course_message.parent_id.nil? ? "发布了班级帖子:" : "评论了班级帖子:" %>
  • <% if ma.course_message.parent_id.nil? %> @@ -423,7 +423,7 @@
  • - <%= link_to User.find(ma.course_message.user).show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> + <%= link_to ma.course_message.user.show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> ">在班级中留言了:
  • @@ -447,7 +447,7 @@
  • - <%= link_to User.find(ma.course_message.user).show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> + <%= link_to ma.course_message.user.show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> "> <% if ma.course_message.m_parent_id.nil? %> 回复了您的作业: diff --git a/app/views/users/_user_message_forge.html.erb b/app/views/users/_user_message_forge.html.erb index c28c40065..b32e7bcb4 100644 --- a/app/views/users/_user_message_forge.html.erb +++ b/app/views/users/_user_message_forge.html.erb @@ -162,7 +162,7 @@ <% if ma.forge_message_type == "Message" %> <% end %> - <% if ma.forge_message_type == "PullRequest" && is_project_manager?( User.current.id, ma.forge_message.project_id) %> + <% if ma.forge_message_type == "PullRequest" %>
    • - <%=link_to image_tag(url_to_avatar(ma.forge_message.author), :width => "30", :height => "30"), user_path(ma.forge_message.author), :target => '_blank' %> + <% send_message_user = PullRequest.where(:pull_request_id => ma.forge_message_id) %> + <% author = User.find(send_message_user[0].user_id) %> + <%= link_to image_tag(url_to_avatar(author), :width => "30", :height => "30"), user_path(author), :target => '_blank' %>
    • - <%=link_to User.find(ma.forge_message.author).show_name, user_path(ma.forge_message.author), - :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> + <%= link_to User.find(send_message_user[0].user_id).show_name, user_path(send_message_user[0].user_id), + :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> "> <%= pull_request_message_status(ma) %>
    • - <%= link_to "#{ma.forge_message.forge_message_id.title}", {:controller => 'pull_requests', :action => 'show', :id => ma.forge_message.project_id }, + <%= link_to "#{send_message_user[0].title}", project_pull_requests_path(ma.project_id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :target => '_blank' %>
    • diff --git a/db/migrate/20161129032534_add_status_to_pull_requests.rb b/db/migrate/20161129032534_add_status_to_pull_requests.rb deleted file mode 100644 index a8ad71125..000000000 --- a/db/migrate/20161129032534_add_status_to_pull_requests.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddStatusToPullRequests < ActiveRecord::Migration - def change - add_column :pull_requests, :status, :integer, :default => false - end -end diff --git a/db/migrate/20161130031415_add_titil_to_pull_requsts.rb b/db/migrate/20161130031415_add_titil_to_pull_requsts.rb new file mode 100644 index 000000000..cc3ce3fef --- /dev/null +++ b/db/migrate/20161130031415_add_titil_to_pull_requsts.rb @@ -0,0 +1,5 @@ +class AddTitilToPullRequsts < ActiveRecord::Migration + def change + add_column :pull_requests, :title, :string + end +end From 233ce0428b33d9085139d9cb83e7b225bfa92062 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 1 Dec 2016 13:55:15 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E7=94=A8=E6=88=B7=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user_message_course.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index f43b87360..49e78521c 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -7,7 +7,7 @@
    • - <%=link_to ma.course_message.author, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> + <%=link_to ma.course_message.author.show_name, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> ">发布了通知:
    • From 51b630666fcccc146c5390fc0f64c88195228bfa Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 2 Dec 2016 13:20:46 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E8=BF=98=E5=8E=9Fpullrequest=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 5 ++--- app/views/repositories/show.html.erb | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 7da5a0dc1..a1a085895 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -228,11 +228,9 @@ class PullRequestsController < ApplicationController def update_pull_request begin @g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state]) - - # 自己关闭/重新打开 就给每个管理员发送消息,如果是管理员关闭/重新打开,就给用户发消息 request = @g.merge_request(@project.gpid, params[:id]) @project_member = Member.where(:project_id => @project.id) - # 发送消息 + # 自己关闭/重新打开 就给每个管理员发送消息 if ( params[:state] == "close" || params[:state] == "reopen" ) && User.current.login == request.author.try(:username) unless @project_member.nil? @project_member.each do |mem| @@ -242,6 +240,7 @@ class PullRequestsController < ApplicationController end end end + # 如果是管理员关闭/重新打开,就给用户发消息 if ( params[:state] == "close" || params[:state] == "reopen" ) && User.current.login != request.author.try(:username) message_user = User.where( :login => request.author.try(:username) ).first send_message(message_user.id, @project.id, request.id, params[:state] == "close" ? 4 : 3) diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 05b8d40d0..282df48c3 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -27,17 +27,17 @@ <% unless @entries.nil? %> ZIP下载 - <%# if User.current.member_of?(@project) && @project.is_public? %> - <%# if quality_analysis(User.current.try(:login), @repository.id).nil? %> - <%#= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "1"), :remote => true, :class => "btn_zipdown fr" %> - <%# else %> - <%#= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fr" %> - <%# end %> - <%# end %> + <% if User.current.member_of?(@project) && @project.is_public? %> + <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> + <%= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "1"), :remote => true, :class => "btn_zipdown fr" %> + <% else %> + <%= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fr" %> + <% end %> + <% end %> + <% end %> + <% unless QualityAnalysis.where(:project_id => @project.id).first.nil? %> + <%= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fr" %> <% end %> - <%# unless QualityAnalysis.where(:project_id => @project.id).first.nil? %> - <%#= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fr" %> - <%# end %>
      <%=link_to "代码统计", stats_repository_project_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :creator => @creator, :default_branch => @g_default_branch ), :class => "fl vl_zip" %> From 4acb674d43fb1baa99dd45097d3df59cffcdf259 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 2 Dec 2016 14:42:52 +0800 Subject: [PATCH 7/7] =?UTF-8?q?pull=20request=20=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=BB=A3=E7=A0=81=E9=87=8D=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 77 +++++++++------------ 1 file changed, 32 insertions(+), 45 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 0a0a422a6..b68db3563 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -101,29 +101,14 @@ class PullRequestsController < ApplicationController request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch, :target_project_id => target_project_id) @fork_project_name = Project.find(params[:target_project_id]).try(:name) @fork_pr_message = true if @fork_project_name - # fork项目的pullrequest发送消息 # 向管理员发送消息 - @project_member = Member.where(:project_id => params[:target_project_id].to_i) - unless @project_member.nil? - @project_member.each do |mem| - if is_project_manager?(mem.user_id, params[:target_project_id].to_i) && mem.user_id != User.current.id - send_message(mem.user_id, params[:target_project_id].to_i, request.id, 1) - end - end - end - # 创建Trustie数据 + send_message_to_manager(params[:target_project_id].to_i, request.id, 1) PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id, :title => title) else @project_member = Member.where(:project_id => @project.id) request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch) # 发送消息 - unless @project_member.nil? - @project_member.each do |mem| - if is_project_manager?(mem.user_id, @project.id) && mem.user_id != User.current.id - send_message(mem.user_id, @project.id, request.id, 1) - end - end - end + send_message_to_manager(@project.id, request.id, 1) # 创建Trustie数据 PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => @project.id, :title => title) respond_to do |format| @@ -204,14 +189,8 @@ class PullRequestsController < ApplicationController def accept_pull_request begin status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid) - PullRequest.create(:pull_request_id => status.id, :user_id => User.current.id, :gpid => status.project_id) - # 接受后,给用户发消息 - request = @g.merge_request(@project.gpid, params[:id]) - if User.current.login != request.author.try(:username) - message_user = User.where( :login => request.author.try(:username) ).first - send_message(message_user.id, @project.id, request.id, 2) - end + send_message_to_author(@project.id, status.author.try(:user_name), params[:id], 2) respond_to do |format| format.js{redirect_to project_pull_request_path(status.id, :project_id => @project.id)} @@ -237,25 +216,13 @@ class PullRequestsController < ApplicationController # @return [Gitlab::ObjectifiedHash] Information about updated merge request. def update_pull_request begin - @g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state]) - request = @g.merge_request(@project.gpid, params[:id]) - @project_member = Member.where(:project_id => @project.id) - # 自己关闭/重新打开 就给每个管理员发送消息 - if ( params[:state] == "close" || params[:state] == "reopen" ) && User.current.login == request.author.try(:username) - unless @project_member.nil? - @project_member.each do |mem| - if is_project_manager?(mem.user_id, @project.id) && mem.user_id != User.current.id - send_message(mem.user_id, @project.id, request.id, params[:state] == "close" ? 4 : 3) - end - end - end + request = @g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state]) + user = User.find_by_login(request.author.try(:username)) + status = params[:state] == "close" ? 4 : 3 + send_message_to_manager(@project.id, params[:id], status) + if !is_project_manager?(user.id, @project.id) + send_message_to_author(@project, user.login, request.id, status) end - # 如果是管理员关闭/重新打开,就给用户发消息 - if ( params[:state] == "close" || params[:state] == "reopen" ) && User.current.login != request.author.try(:username) - message_user = User.where( :login => request.author.try(:username) ).first - send_message(message_user.id, @project.id, request.id, params[:state] == "close" ? 4 : 3) - end - respond_to do |format| format.html{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)} end @@ -361,9 +328,29 @@ class PullRequestsController < ApplicationController end end - def send_message user_id, project_id, pull_request_id, status - ForgeMessage.create(:user_id => user_id, :project_id => project_id, - :forge_message_id => pull_request_id, :forge_message_type => "PullRequest", :viewed => true, :status => status) + def send_message_to_manager project_id, pull_request_id, status + project = Project.find(project_id) + project.members.each do |member| + if is_project_manager?(member.user_id, project_id) && User.current.id != member.user_id + add_message(member.user_id, project_id, pull_request_id, status) + end + end + end + + def send_message_to_author(project_id, user_login, request_id, status) + user = get_user_by_login_and(user_login) + if user.id != User.current.id + add_message(user.id, project_id, request_id, status) + end + end + + def add_message(user_id, project_id, pull_request_id, status) + ForgeMessage.create(:user_id => user_id, + :project_id => project_id, + :forge_message_id => pull_request_id, + :forge_message_type => "PullRequest", + :viewed => true, + :status => status) end def authorize_logged