Merge pull request '@我功能' (#239) from yystopf/forgeplus:hh_notification_v2_2 into develop
This commit is contained in:
commit
6b0f9a689a
|
@ -855,4 +855,8 @@ class ApplicationController < ActionController::Base
|
|||
HotSearchKeyword.add(keyword)
|
||||
end
|
||||
|
||||
def find_atme_receivers
|
||||
@atme_receivers = User.where(login: params[:receivers_login])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ class IssuesController < ApplicationController
|
|||
before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue]
|
||||
|
||||
before_action :set_issue, only: [:edit, :update, :destroy, :show, :copy, :close_issue, :lock_issue]
|
||||
before_action :check_token_enough, only: [:create, :update]
|
||||
before_action :check_token_enough, :find_atme_receivers, only: [:create, :update]
|
||||
|
||||
include ApplicationHelper
|
||||
include TagChosenHelper
|
||||
|
@ -142,6 +142,10 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
|
||||
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||
|
||||
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||
AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0
|
||||
|
||||
render json: {status: 0, message: "创建成", id: @issue.id}
|
||||
else
|
||||
normal_status(-1, "创建失败")
|
||||
|
@ -244,6 +248,10 @@ class IssuesController < ApplicationController
|
|||
post_to_chain(change_type, change_token.abs, current_user.try(:login))
|
||||
end
|
||||
@issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id) if @issue.previous_changes.present?
|
||||
|
||||
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||
AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0
|
||||
|
||||
normal_status(0, "更新成功")
|
||||
else
|
||||
normal_status(-1, "更新失败")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class JournalsController < ApplicationController
|
||||
before_action :require_login, except: [:index, :get_children_journals]
|
||||
before_action :require_profile_completed, only: [:create]
|
||||
before_action :require_profile_completed, :find_atme_receivers, only: [:create]
|
||||
before_action :set_issue
|
||||
before_action :check_issue_permission
|
||||
before_action :set_journal, only: [:destroy, :edit, :update]
|
||||
|
@ -22,32 +22,35 @@ class JournalsController < ApplicationController
|
|||
if notes.blank?
|
||||
normal_status(-1, "评论内容不能为空")
|
||||
else
|
||||
journal_params = {
|
||||
journalized_id: @issue.id ,
|
||||
journalized_type: "Issue",
|
||||
user_id: current_user.id ,
|
||||
notes: notes.to_s.strip,
|
||||
parent_id: params[:parent_id]
|
||||
}
|
||||
journal = Journal.new journal_params
|
||||
if journal.save
|
||||
if params[:attachment_ids].present?
|
||||
params[:attachment_ids].each do |id|
|
||||
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
||||
unless attachment.blank?
|
||||
attachment.container = journal
|
||||
attachment.author_id = current_user.id
|
||||
attachment.description = ""
|
||||
attachment.save
|
||||
ActiveRecord::Base.transaction do
|
||||
journal_params = {
|
||||
journalized_id: @issue.id ,
|
||||
journalized_type: "Issue",
|
||||
user_id: current_user.id ,
|
||||
notes: notes.to_s.strip,
|
||||
parent_id: params[:parent_id]
|
||||
}
|
||||
journal = Journal.new journal_params
|
||||
if journal.save
|
||||
if params[:attachment_ids].present?
|
||||
params[:attachment_ids].each do |id|
|
||||
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
||||
unless attachment.blank?
|
||||
attachment.container = journal
|
||||
attachment.author_id = current_user.id
|
||||
attachment.description = ""
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||
AtmeService.call(current_user, @atme_receivers, journal) if @atme_receivers.size > 0
|
||||
# @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal")
|
||||
render :json => { status: 0, message: "评论成功", id: journal.id}
|
||||
# normal_status(0, "评论成功")
|
||||
else
|
||||
normal_status(-1, "评论失败")
|
||||
end
|
||||
|
||||
# @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal")
|
||||
render :json => { status: 0, message: "评论成功", id: journal.id}
|
||||
# normal_status(0, "评论成功")
|
||||
else
|
||||
normal_status(-1, "评论失败")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class Projects::MembersController < Projects::BaseController
|
||||
def index
|
||||
users = @project.all_collaborators.like(params[:search]).includes(:user_extension)
|
||||
@users = kaminari_paginate(users)
|
||||
end
|
||||
end
|
|
@ -5,6 +5,7 @@ class PullRequestsController < ApplicationController
|
|||
before_action :check_menu_authorize
|
||||
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos, :files, :commits]
|
||||
before_action :load_pull_request, only: [:files, :commits]
|
||||
before_action :find_atme_receivers, only: [:create, :update]
|
||||
include TagChosenHelper
|
||||
include ApplicationHelper
|
||||
|
||||
|
@ -61,6 +62,8 @@ class PullRequestsController < ApplicationController
|
|||
@pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"])
|
||||
SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id) if Site.has_notice_menu?
|
||||
SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) if Site.has_notice_menu?
|
||||
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||
AtmeService.call(current_user, @atme_receivers, @pull_request) if @atme_receivers.size > 0
|
||||
else
|
||||
render_error("create pull request error: #{@gitea_pull_request[:status]}")
|
||||
raise ActiveRecord::Rollback
|
||||
|
@ -106,6 +109,8 @@ class PullRequestsController < ApplicationController
|
|||
if params[:status_id].to_i == 5
|
||||
@issue.issue_times.update_all(end_time: Time.now)
|
||||
end
|
||||
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||
AtmeService.call(current_user, @atme_receivers, @pull_request) if @atme_receivers.size > 0
|
||||
normal_status(0, "PullRequest更新成功")
|
||||
else
|
||||
normal_status(-1, "PullRequest更新失败")
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
class AtmeService < ApplicationService
|
||||
Error = Class.new(StandardError)
|
||||
|
||||
attr_reader :user, :receivers, :atmeable
|
||||
|
||||
def initialize(user, receivers, atmeable)
|
||||
@user = user
|
||||
@receivers = receivers
|
||||
@atmeable = atmeable
|
||||
end
|
||||
|
||||
def call
|
||||
Rails.logger.info "[ATME] service args: [user]=>#{user}, [receivers]=>#{receivers}, [atmeable]=>#{atmeable}"
|
||||
return if atmeable.nil?
|
||||
Rails.logger.info "[ATME] atmeable class name is: #{ atmeable.class.name}"
|
||||
case atmeable.class.name
|
||||
when 'Issue'
|
||||
message_source = 'IssueAtme'
|
||||
when 'PullRequest'
|
||||
message_source = 'PullRequestAtme'
|
||||
when 'Journal'
|
||||
journal = Journal.find_by_id(atmeable.id)
|
||||
if journal.present?
|
||||
if journal&.issue&.pull_request.present?
|
||||
@atmeable = journal&.issue&.pull_request
|
||||
message_source = 'PullRequestAtme'
|
||||
else
|
||||
@atmeable = journal&.issue
|
||||
message_source = 'IssueAtme'
|
||||
end
|
||||
end
|
||||
else
|
||||
return
|
||||
end
|
||||
SendTemplateMessageJob.perform_now(message_source, receivers, user.id, @atmeable.id) if Site.has_notice_menu?
|
||||
end
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
json.total_count @users.total_count
|
||||
json.users do
|
||||
json.partial! 'users/user_small', users: @users
|
||||
end
|
|
@ -429,7 +429,7 @@ Rails.application.routes.draw do
|
|||
get :simple
|
||||
get :watchers, to: 'projects#watch_users'
|
||||
get :stargazers, to: 'projects#praise_users'
|
||||
get :members, to: 'projects#fork_users'
|
||||
get :forks, to: 'projects#fork_users'
|
||||
match :about, :via => [:get, :put, :post]
|
||||
end
|
||||
end
|
||||
|
@ -585,6 +585,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
scope module: :projects do
|
||||
resources :members, only: [:index]
|
||||
resources :teams, only: [:index, :create, :destroy]
|
||||
resources :project_units, only: [:index, :create]
|
||||
resources :applied_transfer_projects, only: [:create] do
|
||||
|
|
Loading…
Reference in New Issue