Merge branch 'develop' into 'develop'

项目提交动态的方法优化,及多个样式调整风格一致



See merge request !38
This commit is contained in:
黄井泉 2016-12-02 14:47:25 +08:00
commit ef86b6da2a
7 changed files with 76 additions and 28 deletions

View File

@ -50,10 +50,10 @@ gem 'elasticsearch-model'
gem 'elasticsearch-rails' gem 'elasticsearch-rails'
#rails 3.2.22.2 bug #rails 3.2.22.2 bug
# gem "test-unit", "~>3.0" gem "test-unit", "~>3.0"
### profile ### profile
# gem 'oneapm_rpm' gem 'oneapm_rpm'
group :development do group :development do
gem 'grape-swagger' gem 'grape-swagger'

View File

@ -101,16 +101,16 @@ 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) 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_project_name = Project.find(params[:target_project_id]).try(:name)
@fork_pr_message = true if @fork_project_name @fork_pr_message = true if @fork_project_name
# 发送消息 # 向管理员发送消息
#send_message(User.current.id, target_project_id, title) send_message_to_manager(params[:target_project_id].to_i, request.id, 1)
# 创建Trustie数据 PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id, :title => title)
#PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id)
else 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) 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_to_manager(@project.id, request.id, 1)
# 创建Trustie数据 # 创建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| respond_to do |format|
format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)} format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)}
end end
@ -189,7 +189,9 @@ class PullRequestsController < ApplicationController
def accept_pull_request def accept_pull_request
begin begin
status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid) 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) # 接受后,给用户发消息
send_message_to_author(@project.id, status.author.try(:user_name), params[:id], 2)
respond_to do |format| respond_to do |format|
format.js{redirect_to project_pull_request_path(status.id, :project_id => @project.id)} format.js{redirect_to project_pull_request_path(status.id, :project_id => @project.id)}
end end
@ -214,7 +216,13 @@ class PullRequestsController < ApplicationController
# @return [Gitlab::ObjectifiedHash] Information about updated merge request. # @return [Gitlab::ObjectifiedHash] Information about updated merge request.
def update_pull_request def update_pull_request
begin begin
@g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state]) 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
respond_to do |format| respond_to do |format|
format.html{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)} format.html{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)}
end end
@ -320,8 +328,29 @@ class PullRequestsController < ApplicationController
end end
end end
def send_message user_id, project_id, title def send_message_to_manager project_id, pull_request_id, status
self.forge_acts << ForgeMessage.new(:user_id => user_id, :project_id => project_id, :title => title) 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 end
def authorize_logged def authorize_logged

View File

@ -90,6 +90,20 @@ module UsersHelper
end end
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 def allow_to_show applied_message
(User.current.id == applied_message.user_id && applied_message.status == 1) ? true : false (User.current.id == applied_message.user_id && applied_message.status == 1) ? true : false

View File

@ -1,6 +1,6 @@
class PullRequest < ActiveRecord::Base class PullRequest < ActiveRecord::Base
# status 1创建 2接受 3重新打开 4关闭 # 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 validates_uniqueness_of :pull_request_id
has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy

View File

@ -194,24 +194,29 @@
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li> <li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul> </ul>
<% end %> <% end %>
<!--
<%# if ma.forge_message_type == "PullRequest" %> <% if ma.forge_message_type == "PullRequest" %>
<ul class="homepageNewsList fl"> <ul class="homepageNewsList fl">
<li class="homepageNewsPortrait fl"> <li class="homepageNewsPortrait fl">
<a href="javascript:void(0);"> <a href="javascript:void(0);">
<%#=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' %>
</a> </a>
</li> </li>
<li class="homepageNewsPubType fl"> <li class="homepageNewsPubType fl">
<%#=link_to User.find(ma.forge_message.author).show_name, user_path(ma.forge_message.author), <%= 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' %> :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<span class="<%#= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">创建了PullRequest</span> <span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">
<%= pull_request_message_status(ma) %>
</span>
</li> </li>
<li class="homepageNewsContent fl"> <li class="homepageNewsContent fl">
<%#= link_to "#{ma.forge_message.commented.title}", <%= link_to "#{send_message_user[0].title}", project_pull_requests_path(ma.project_id),
{:controller => 'news', :action => 'show', :id => ma.forge_message.commented.id },:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :target => '_blank' %> :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :target => '_blank' %>
</li> </li>
<li class="homepageNewsTime fl"><%#= time_tag(ma.created_at).html_safe %> </li> <li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul> </ul>
<%# end %>--> <% end %>
<% end %> <% end %>

View File

@ -1,5 +0,0 @@
class AddStatusToPullRequests < ActiveRecord::Migration
def change
add_column :pull_requests, :status, :integer, :default => false
end
end

View File

@ -0,0 +1,5 @@
class AddTitilToPullRequsts < ActiveRecord::Migration
def change
add_column :pull_requests, :title, :string
end
end