mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-02 19:30:48 +08:00
Merge branch 'standalone_develop' into pre_trustie_server
This commit is contained in:
@@ -34,7 +34,7 @@ class PullRequest < ApplicationRecord
|
||||
|
||||
belongs_to :issue
|
||||
belongs_to :user
|
||||
belongs_to :project, counter_cache: true, touch: true
|
||||
belongs_to :project, counter_cache: true, touch: true, optional: true
|
||||
belongs_to :fork_project, class_name: 'Project', foreign_key: :fork_project_id, optional: true
|
||||
has_many :pull_request_assigns, foreign_key: :pull_request_id
|
||||
has_many :pull_request_tags, foreign_key: :pull_request_id
|
||||
|
||||
@@ -137,7 +137,7 @@ class User < Owner
|
||||
has_many :tidings, :dependent => :destroy
|
||||
# has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
||||
|
||||
has_many :attachments,foreign_key: :author_id, :dependent => :destroy
|
||||
has_many :attachments,foreign_key: :author_id
|
||||
|
||||
has_one :ci_cloud_account, class_name: 'Ci::CloudAccount', dependent: :destroy
|
||||
|
||||
@@ -160,7 +160,7 @@ class User < Owner
|
||||
|
||||
# 教学案例
|
||||
# has_many :libraries, dependent: :destroy
|
||||
has_many :project_trends, dependent: :destroy
|
||||
has_many :project_trends
|
||||
has_many :oauths , dependent: :destroy
|
||||
|
||||
has_many :organization_users, dependent: :destroy
|
||||
@@ -168,8 +168,8 @@ class User < Owner
|
||||
has_many :pinned_projects, dependent: :destroy
|
||||
has_many :is_pinned_projects, through: :pinned_projects, source: :project
|
||||
accepts_nested_attributes_for :is_pinned_projects
|
||||
has_many :issues, dependent: :destroy, foreign_key: :author_id
|
||||
has_many :pull_requests, dependent: :destroy
|
||||
has_many :issues, foreign_key: :author_id
|
||||
has_many :pull_requests
|
||||
has_many :public_keys, class_name: "Gitea::PublicKey",primary_key: :gitea_uid, foreign_key: :owner_id, dependent: :destroy
|
||||
|
||||
has_one :user_template_message_setting, dependent: :destroy
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
# updated_at :datetime not null
|
||||
# ip :string(255)
|
||||
# data_bank :text(65535)
|
||||
# login :string(255)
|
||||
# phone :string(255)
|
||||
# email :string(255)
|
||||
# memo :text(65535)
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
@@ -19,5 +23,76 @@
|
||||
# index_user_actions_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class UserAction < ApplicationRecord
|
||||
end
|
||||
class UserAction < ApplicationRecord
|
||||
|
||||
after_save :add_user_info
|
||||
|
||||
serialize :data_bank, JSON
|
||||
|
||||
def action_name
|
||||
case action_type
|
||||
when "DestroyUser" then "用户注销"
|
||||
when "DestroyProject" then "删除项目"
|
||||
when "Login" then "登录"
|
||||
when "Logout" then "退出登录"
|
||||
else self.action_type
|
||||
end
|
||||
end
|
||||
|
||||
def opt_user_name
|
||||
user = User.find_by(id: self.user_id)
|
||||
if user.present?
|
||||
user&.login
|
||||
else
|
||||
del_user = UserAction.find_by(action_type: "DestroyUser", action_id: self.user_id)
|
||||
del_user.present? ? del_user.user.login : "不存在用户:#{user_id}"
|
||||
end
|
||||
end
|
||||
|
||||
def action_info
|
||||
case action_type
|
||||
when "DestroyUser" then "账号:#{user&.login}<br/>邮箱:#{user&.mail}<br/>手机号:#{user&.phone}<br/>昵称:#{user&.nickname}<br/>"
|
||||
when "DestroyProject" then "项目名称:#{project&.name}<br/>项目标识:#{project&.identifier}<br/>"
|
||||
else "--"
|
||||
end
|
||||
end
|
||||
|
||||
def user
|
||||
action_user = if action_type == "DestroyUser" && data_bank.present?
|
||||
build_mode("User")
|
||||
else
|
||||
User.find_by(id: self.user_id)
|
||||
end
|
||||
action_user
|
||||
end
|
||||
|
||||
def project
|
||||
action_project = if action_type == "DestroyProject" && data_bank.present?
|
||||
build_mode("Project")
|
||||
else
|
||||
Project.find_by(id: self.action_id)
|
||||
end
|
||||
action_project
|
||||
end
|
||||
def build_mode(model_name)
|
||||
model = model_name.constantize.new
|
||||
model_name.constantize.column_names.each do |col|
|
||||
data = self.data_bank.class == String ? JSON.parse(self.data_bank) : self.data_bank
|
||||
model[col] = data[col]
|
||||
end
|
||||
model
|
||||
rescue =>err
|
||||
return nil
|
||||
end
|
||||
|
||||
private
|
||||
def add_user_info
|
||||
if self.login.blank?
|
||||
if user.present?
|
||||
self.login = user.login
|
||||
self.email = user.mail
|
||||
self.phone = user.phone
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user