Merge branch 'pre_trustie_server' into trustie_server
This commit is contained in:
commit
b7c009ae94
|
@ -7,6 +7,16 @@ class Admins::ProjectsController < Admins::BaseController
|
||||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
search = params[:search].to_s.strip
|
search = params[:search].to_s.strip
|
||||||
projects = Project.where("name like ? OR identifier LIKE ?", "%#{search}%", "%#{search}%").order("#{sort_by} #{sort_direction}")
|
projects = Project.where("name like ? OR identifier LIKE ?", "%#{search}%", "%#{search}%").order("#{sort_by} #{sort_direction}")
|
||||||
|
case params[:category]
|
||||||
|
when 'public'
|
||||||
|
projects = projects.where(is_public: true)
|
||||||
|
when 'private'
|
||||||
|
projects = projects.where(is_public: false)
|
||||||
|
when 'fork'
|
||||||
|
projects = projects.where.not(forked_from_project_id: nil)
|
||||||
|
when 'original'
|
||||||
|
projects = projects.where(forked_from_project_id: nil, project_type: 'common')
|
||||||
|
end
|
||||||
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,8 +43,12 @@ class Admins::ProjectsController < Admins::BaseController
|
||||||
def destroy
|
def destroy
|
||||||
project = Project.find_by!(id: params[:id])
|
project = Project.find_by!(id: params[:id])
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
|
close_fork_pull_requests_by(project)
|
||||||
Gitea::Repository::DeleteService.new(project.owner, project.identifier, current_user.gitea_token).call
|
Gitea::Repository::DeleteService.new(project.owner, project.identifier, current_user.gitea_token).call
|
||||||
project.destroy!
|
project.destroy!
|
||||||
|
project.forked_projects.update_all(forked_from_project_id: nil)
|
||||||
|
# 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量
|
||||||
|
project.project_category.decrement!(:private_projects_count, 1) if project.project_category.present? && !project.is_public
|
||||||
# render_delete_success
|
# render_delete_success
|
||||||
UserAction.create(action_id: project.id, action_type: "DestroyProject", user_id: current_user.id, :ip => request.remote_ip, data_bank: project.attributes.to_json)
|
UserAction.create(action_id: project.id, action_type: "DestroyProject", user_id: current_user.id, :ip => request.remote_ip, data_bank: project.attributes.to_json)
|
||||||
redirect_to admins_projects_path
|
redirect_to admins_projects_path
|
||||||
|
@ -53,4 +67,19 @@ class Admins::ProjectsController < Admins::BaseController
|
||||||
def project_update_params
|
def project_update_params
|
||||||
params.require(:project).permit(:is_pinned, :recommend, :recommend_index)
|
params.require(:project).permit(:is_pinned, :recommend, :recommend_index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close_fork_pull_requests_by(project)
|
||||||
|
open_pull_requests = PullRequest.where(fork_project_id: project.id)
|
||||||
|
if open_pull_requests.present?
|
||||||
|
open_pull_requests.each do |pull_request|
|
||||||
|
closed = PullRequests::CloseService.call(pull_request&.project.owner, pull_request&.project.repository, pull_request, current_user)
|
||||||
|
if closed === true
|
||||||
|
pull_request.project_trends.create!(user: current_user, project: pull_request&.project,action_type: ProjectTrend::CLOSE)
|
||||||
|
# 合并请求下issue处理为关闭
|
||||||
|
pull_request.issue&.update_attributes!({status_id:5})
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, pull_request.id) if Site.has_notice_menu?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -0,0 +1,23 @@
|
||||||
|
class Api::V1::Users::HomeTopSettingsController < Api::V1::BaseController
|
||||||
|
|
||||||
|
before_action :load_observe_user
|
||||||
|
before_action :check_auth_for_observe_user
|
||||||
|
|
||||||
|
def create
|
||||||
|
@result = Api::V1::Users::HomeTopSettings::CreateService.call(@observe_user, home_top_setting_params)
|
||||||
|
return render_error("置顶失败.") if @result.nil?
|
||||||
|
return render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def cancel
|
||||||
|
@result = Api::V1::Users::HomeTopSettings::DeleteService.call(@observe_user, home_top_setting_params)
|
||||||
|
return render_error("取消置顶失败.") if @result.nil?
|
||||||
|
return render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def home_top_setting_params
|
||||||
|
params.permit(:top_type, :top_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -217,6 +217,10 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
new_project_params = project_params.except(:private).merge(is_public: !private)
|
new_project_params = project_params.except(:private).merge(is_public: !private)
|
||||||
@project.update_attributes!(new_project_params)
|
@project.update_attributes!(new_project_params)
|
||||||
|
fork_pull_requests = PullRequest.where(fork_project_id: @project.id)
|
||||||
|
if fork_pull_requests.present?
|
||||||
|
fork_pull_requests.update_all(fork_project_identifier: @project.identifier)
|
||||||
|
end
|
||||||
@project.forked_projects.map{|p| p.update!(is_public: @project.is_public)}
|
@project.forked_projects.map{|p| p.update!(is_public: @project.is_public)}
|
||||||
gitea_params = {
|
gitea_params = {
|
||||||
private: private,
|
private: private,
|
||||||
|
@ -258,6 +262,7 @@ class ProjectsController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
if current_user.admin? || @project.manager?(current_user)
|
if current_user.admin? || @project.manager?(current_user)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
|
close_fork_pull_requests_by(@project)
|
||||||
Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call
|
Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call
|
||||||
@project.destroy!
|
@project.destroy!
|
||||||
@project.forked_projects.update_all(forked_from_project_id: nil)
|
@project.forked_projects.update_all(forked_from_project_id: nil)
|
||||||
|
@ -408,4 +413,19 @@ class ProjectsController < ApplicationController
|
||||||
render_unauthorized('你还未登录.')
|
render_unauthorized('你还未登录.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close_fork_pull_requests_by(project)
|
||||||
|
open_pull_requests = PullRequest.where(fork_project_id: project.id)
|
||||||
|
if open_pull_requests.present?
|
||||||
|
open_pull_requests.each do |pull_request|
|
||||||
|
closed = PullRequests::CloseService.call(pull_request&.project.owner, pull_request&.project.repository, pull_request, current_user)
|
||||||
|
if closed === true
|
||||||
|
pull_request.project_trends.create!(user: current_user, project: pull_request&.project,action_type: ProjectTrend::CLOSE)
|
||||||
|
# 合并请求下issue处理为关闭
|
||||||
|
pull_request.issue&.update_attributes!({status_id:5})
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, pull_request.id) if Site.has_notice_menu?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,15 @@ class Users::OrganizationsController < Users::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
@organizations = @organizations.ransack(login_cont: params[:search]).result if params[:search].present?
|
@organizations = @organizations.ransack(login_cont: params[:search]).result if params[:search].present?
|
||||||
@organizations = @organizations.includes(:organization_extension).order("organization_extensions.#{sort_by} #{sort_direction}")
|
|
||||||
|
@home_top_ids = @organizations.joins(:home_top_settings).where(home_top_settings: {user_id: observed_user.id}).order("home_top_settings.created_at asc").pluck(:id)
|
||||||
|
|
||||||
|
if @home_top_ids.present?
|
||||||
|
@organizations = @organizations.joins(:organization_extension).order("FIELD(users.id, #{@home_top_ids.join(",")}) desc, organization_extensions.#{sort_by} #{sort_direction}")
|
||||||
|
else
|
||||||
|
@organizations = @organizations.joins(:organization_extension).order("organization_extensions.#{sort_by} #{sort_direction}")
|
||||||
|
end
|
||||||
|
|
||||||
@organizations = kaminari_paginate(@organizations)
|
@organizations = kaminari_paginate(@organizations)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -408,7 +408,7 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
def projects
|
def projects
|
||||||
is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
|
is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
|
||||||
scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user)
|
scope, @home_top_ids = Projects::ListMyQuery.call(params, @user,is_current_admin_user)
|
||||||
@total_count = scope.size
|
@total_count = scope.size
|
||||||
@projects = kaminari_unlimit_paginate(scope)
|
@projects = kaminari_unlimit_paginate(scope)
|
||||||
end
|
end
|
||||||
|
|
|
@ -479,7 +479,7 @@ module ApplicationHelper
|
||||||
|
|
||||||
return if url.blank?
|
return if url.blank?
|
||||||
content_tag(:li) do
|
content_tag(:li) do
|
||||||
sidebar_item(url, "数据统计", icon: 'bar-chart', controller: 'root')
|
sidebar_item(url, "数据统计", icon: 'bar-chart', controller: 'root', has_permission: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: home_top_settings
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# user_id :integer
|
||||||
|
# top_type :string(255)
|
||||||
|
# top_id :integer
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
#
|
||||||
|
# Indexes
|
||||||
|
#
|
||||||
|
# index_home_top_settings_on_top_type_and_top_id (top_type,top_id)
|
||||||
|
# index_home_top_settings_on_user_id (user_id)
|
||||||
|
#
|
||||||
|
|
||||||
|
class HomeTopSetting < ApplicationRecord
|
||||||
|
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
belongs_to :top, polymorphic: true
|
||||||
|
end
|
|
@ -76,6 +76,7 @@ class Organization < Owner
|
||||||
has_many :team_users, dependent: :destroy
|
has_many :team_users, dependent: :destroy
|
||||||
has_many :pinned_projects, class_name: 'PinnedProject', foreign_key: :user_id, dependent: :destroy
|
has_many :pinned_projects, class_name: 'PinnedProject', foreign_key: :user_id, dependent: :destroy
|
||||||
has_many :is_pinned_projects, through: :pinned_projects, source: :project, validate: false
|
has_many :is_pinned_projects, through: :pinned_projects, source: :project, validate: false
|
||||||
|
has_many :home_top_settings, as: :top, dependent: :destroy
|
||||||
|
|
||||||
validates :login, presence: true
|
validates :login, presence: true
|
||||||
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
|
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
|
||||||
|
|
|
@ -138,6 +138,7 @@ class Project < ApplicationRecord
|
||||||
has_many :daily_project_statistics, dependent: :destroy
|
has_many :daily_project_statistics, dependent: :destroy
|
||||||
has_one :project_dataset, dependent: :destroy
|
has_one :project_dataset, dependent: :destroy
|
||||||
has_many :sync_repositories, dependent: :destroy
|
has_many :sync_repositories, dependent: :destroy
|
||||||
|
has_many :home_top_settings, as: :top, dependent: :destroy
|
||||||
after_create :incre_user_statistic, :incre_platform_statistic
|
after_create :incre_user_statistic, :incre_platform_statistic
|
||||||
after_save :check_project_members
|
after_save :check_project_members
|
||||||
before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data
|
before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data
|
||||||
|
@ -461,6 +462,15 @@ class Project < ApplicationRecord
|
||||||
EduSetting.get("open_portrait_projects").present? ? EduSetting.get("open_portrait_projects").split(",").include?(self.id.to_s) : false
|
EduSetting.get("open_portrait_projects").present? ? EduSetting.get("open_portrait_projects").split(",").include?(self.id.to_s) : false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_pull_request(branch_name)
|
||||||
|
return true if self.pull_requests.opening.where(head: branch_name).present? || self.pull_requests.opening.where(base: branch_name).present?
|
||||||
|
if self.forked_from_project_id.present?
|
||||||
|
return true if self.fork_project.pull_requests.opening.where(head: branch_name).present? || self.fork_project.pull_requests.opening.where(base: branch_name).present?
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
def self.mindspore_contributors
|
def self.mindspore_contributors
|
||||||
cache_result = $redis_cache.get("ProjectMindsporeContributors")
|
cache_result = $redis_cache.get("ProjectMindsporeContributors")
|
||||||
if cache_result.nil?
|
if cache_result.nil?
|
||||||
|
|
|
@ -2,25 +2,27 @@
|
||||||
#
|
#
|
||||||
# Table name: pull_requests
|
# Table name: pull_requests
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
# gitea_id :integer
|
# gitea_id :integer
|
||||||
# gitea_number :integer
|
# gitea_number :integer
|
||||||
# user_id :integer
|
# user_id :integer
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
# status :integer default("0")
|
# status :integer default("0")
|
||||||
# project_id :integer
|
# project_id :integer
|
||||||
# title :string(255)
|
# title :string(255)
|
||||||
# milestone :integer
|
# milestone :integer
|
||||||
# body :text(4294967295)
|
# body :text(4294967295)
|
||||||
# head :string(255)
|
# head :string(255)
|
||||||
# base :string(255)
|
# base :string(255)
|
||||||
# issue_id :integer
|
# issue_id :integer
|
||||||
# fork_project_id :integer
|
# fork_project_id :integer
|
||||||
# is_original :boolean default("0")
|
# is_original :boolean default("0")
|
||||||
# comments_count :integer default("0")
|
# comments_count :integer default("0")
|
||||||
# commits_count :integer default("0")
|
# commits_count :integer default("0")
|
||||||
# files_count :integer default("0")
|
# files_count :integer default("0")
|
||||||
|
# fork_project_owner :string(255)
|
||||||
|
# fork_project_identifier :string(255)
|
||||||
#
|
#
|
||||||
|
|
||||||
class PullRequest < ApplicationRecord
|
class PullRequest < ApplicationRecord
|
||||||
|
|
|
@ -190,6 +190,7 @@ class User < Owner
|
||||||
has_many :clas, through: :user_clas
|
has_many :clas, through: :user_clas
|
||||||
|
|
||||||
has_one :page, :dependent => :destroy
|
has_one :page, :dependent => :destroy
|
||||||
|
has_many :home_top_settings, dependent: :destroy
|
||||||
|
|
||||||
# Groups and active users
|
# Groups and active users
|
||||||
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) }
|
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) }
|
||||||
|
|
|
@ -20,11 +20,11 @@ class Projects::ListMyQuery < ApplicationQuery
|
||||||
if params[:category].blank?
|
if params[:category].blank?
|
||||||
normal_projects = projects.members_projects(user.id).to_sql
|
normal_projects = projects.members_projects(user.id).to_sql
|
||||||
org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: user.id}).to_sql
|
org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: user.id}).to_sql
|
||||||
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects")#.distinct
|
||||||
elsif params[:category].to_s == "join"
|
elsif params[:category].to_s == "join"
|
||||||
normal_projects = projects.where.not(user_id: user.id).members_projects(user.id).to_sql
|
normal_projects = projects.where.not(user_id: user.id).members_projects(user.id).to_sql
|
||||||
org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: user.id}).to_sql
|
org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: user.id}).to_sql
|
||||||
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects")#.distinct
|
||||||
elsif params[:category].to_s == "manage"
|
elsif params[:category].to_s == "manage"
|
||||||
projects = projects.where(user_id: user.id)
|
projects = projects.where(user_id: user.id)
|
||||||
elsif params[:category].to_s == "watched" #我关注的
|
elsif params[:category].to_s == "watched" #我关注的
|
||||||
|
@ -37,7 +37,7 @@ class Projects::ListMyQuery < ApplicationQuery
|
||||||
elsif params[:category].to_s == "admin"
|
elsif params[:category].to_s == "admin"
|
||||||
normal_projects = projects.joins(members: :roles).where(members: {user_id: user.id}, roles: {name: %w(Manager)}).to_sql
|
normal_projects = projects.joins(members: :roles).where(members: {user_id: user.id}, roles: {name: %w(Manager)}).to_sql
|
||||||
org_projects = projects.joins(team_projects: [team: :team_users]).where(teams: {authorize: %w(owner admin)},team_users: {user_id: user.id}).to_sql
|
org_projects = projects.joins(team_projects: [team: :team_users]).where(teams: {authorize: %w(owner admin)},team_users: {user_id: user.id}).to_sql
|
||||||
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects")#.distinct
|
||||||
# elsif params[:category].to_s == "public"
|
# elsif params[:category].to_s == "public"
|
||||||
# projects = projects.visible.joins(:members).where(members: { user_id: user.id })
|
# projects = projects.visible.joins(:members).where(members: { user_id: user.id })
|
||||||
# elsif params[:category].to_s == "private"
|
# elsif params[:category].to_s == "private"
|
||||||
|
@ -71,11 +71,19 @@ class Projects::ListMyQuery < ApplicationQuery
|
||||||
|
|
||||||
sort = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : "updated_on"
|
sort = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : "updated_on"
|
||||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : "desc"
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : "desc"
|
||||||
|
|
||||||
|
@home_top_ids = scope.joins(:home_top_settings).where(home_top_settings: {user_id: user.id}).order("home_top_settings.created_at asc").pluck(:id)
|
||||||
|
|
||||||
if params[:choosed].present? && params[:choosed].is_a?(Array)
|
if params[:choosed].present? && params[:choosed].is_a?(Array)
|
||||||
scope.order("FIELD(id, #{params[:choosed].reverse.join(",")}) desc")
|
scope = scope.distinct.order("FIELD(projects.id, #{params[:choosed].reverse.join(",")}) desc")
|
||||||
else
|
else
|
||||||
scope.order("projects.#{sort} #{sort_direction}")
|
if @home_top_ids.present?
|
||||||
|
scope = scope.distinct.order("FIELD(projects.id, #{@home_top_ids.join(",")}) desc, projects.#{sort} #{sort_direction}")
|
||||||
|
else
|
||||||
|
scope = scope.distinct.order("projects.#{sort} #{sort_direction}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return scope, @home_top_ids
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
class Api::V1::Users::HomeTopSettings::CreateService < ApplicationService
|
||||||
|
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_reader :user, :top_type, :top_id
|
||||||
|
attr_accessor :home_top_setting, :home_top
|
||||||
|
|
||||||
|
validates :user, :top_type, :top_id, presence: true
|
||||||
|
validates :top_type, inclusion: {in: %w(Organization Project), message: '请输入正确的TopType'}
|
||||||
|
|
||||||
|
def initialize(user, params)
|
||||||
|
@user = user
|
||||||
|
@top_type = params[:top_type]
|
||||||
|
@top_id = params[:top_id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
raise Error, errors.full_messages.join(",") unless valid?
|
||||||
|
raise Error, "置顶对象不存在!" unless find_home_top
|
||||||
|
raise Error, "置顶对象已置顶!" if check_home_top_setting
|
||||||
|
|
||||||
|
begin
|
||||||
|
@home_top_setting = HomeTopSetting.new(user:user, top: @home_top)
|
||||||
|
@home_top_setting.save!
|
||||||
|
|
||||||
|
return @home_top_setting.valid? ? @home_top_setting : nil
|
||||||
|
rescue
|
||||||
|
raise Error, "服务器错误,请联系系统管理员!"
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_home_top
|
||||||
|
@home_top = @top_type.constantize.find_by_id(@top_id).presence
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_home_top_setting
|
||||||
|
HomeTopSetting.exists?(user: @user, top: @home_top)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,40 @@
|
||||||
|
class Api::V1::Users::HomeTopSettings::DeleteService < ApplicationService
|
||||||
|
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_reader :user, :top_type, :top_id
|
||||||
|
attr_accessor :home_top_setting, :home_top
|
||||||
|
|
||||||
|
validates :user, :top_type, :top_id, presence: true
|
||||||
|
validates :top_type, inclusion: {in: %w(Organization Project), message: '请输入正确的TopType'}
|
||||||
|
|
||||||
|
def initialize(user, params)
|
||||||
|
@user = user
|
||||||
|
@top_type = params[:top_type]
|
||||||
|
@top_id = params[:top_id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
raise Error, errors.full_messages.join(",") unless valid?
|
||||||
|
raise Error, "置顶对象不存在!" unless find_home_top
|
||||||
|
raise Error, "置顶对象未置顶!" unless check_home_top_setting
|
||||||
|
|
||||||
|
begin
|
||||||
|
@home_top_setting = HomeTopSetting.find_by(user:user, top: @home_top)
|
||||||
|
@home_top_setting.destroy!
|
||||||
|
|
||||||
|
return true
|
||||||
|
rescue
|
||||||
|
raise Error, "服务器错误,请联系系统管理员!"
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_home_top
|
||||||
|
@home_top = @top_type.constantize.find_by_id(@top_id).presence
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_home_top_setting
|
||||||
|
HomeTopSetting.exists?(user: @user, top: @home_top)
|
||||||
|
end
|
||||||
|
end
|
|
@ -15,6 +15,7 @@ class Projects::TransferService < ApplicationService
|
||||||
update_repo_url
|
update_repo_url
|
||||||
update_visit_teams
|
update_visit_teams
|
||||||
update_fork_info
|
update_fork_info
|
||||||
|
update_fork_pull_request_info
|
||||||
end
|
end
|
||||||
|
|
||||||
Rails.logger.info("##### Project transfer_service end ######")
|
Rails.logger.info("##### Project transfer_service end ######")
|
||||||
|
@ -49,6 +50,11 @@ class Projects::TransferService < ApplicationService
|
||||||
fork_user.update(user_id: @new_owner.id) if fork_user.present?
|
fork_user.update(user_id: @new_owner.id) if fork_user.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_fork_pull_request_info
|
||||||
|
fork_pull_requests = PullRequest.where(fork_project_id: @project.id)
|
||||||
|
fork_pull_requests.update_all(fork_project_owner: @new_owner&.login) if fork_pull_requests.present?
|
||||||
|
end
|
||||||
|
|
||||||
def gitea_update_owner
|
def gitea_update_owner
|
||||||
begin
|
begin
|
||||||
@gitea_repo = $gitea_hat_client.post_repos_transfer_by_owner_repo(owner&.login, project.identifier, {body: {new_owner: new_owner&.login}.to_json})
|
@gitea_repo = $gitea_hat_client.post_repos_transfer_by_owner_repo(owner&.login, project.identifier, {body: {new_owner: new_owner&.login}.to_json})
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class PullRequests::CreateService < ApplicationService
|
class PullRequests::CreateService < ApplicationService
|
||||||
|
|
||||||
attr_reader :current_user, :owner, :project, :params
|
attr_reader :current_user, :owner, :project, :params, :fork_project
|
||||||
attr_accessor :pull_issue, :pull_request
|
attr_accessor :pull_issue, :pull_request
|
||||||
|
|
||||||
def initialize(current_user, owner, project, params)
|
def initialize(current_user, owner, project, params)
|
||||||
|
@ -8,6 +8,7 @@ class PullRequests::CreateService < ApplicationService
|
||||||
@project = project
|
@project = project
|
||||||
@params = params
|
@params = params
|
||||||
@current_user = current_user
|
@current_user = current_user
|
||||||
|
@fork_project = Project.find_by_id(params[:fork_project_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
@ -102,7 +103,9 @@ class PullRequests::CreateService < ApplicationService
|
||||||
fork_project_id: @params[:fork_project_id],
|
fork_project_id: @params[:fork_project_id],
|
||||||
is_original: is_original,
|
is_original: is_original,
|
||||||
files_count: @params[:files_count] || 0,
|
files_count: @params[:files_count] || 0,
|
||||||
commits_count: @params[:commits_count] || 0
|
commits_count: @params[:commits_count] || 0,
|
||||||
|
fork_project_owner: @fork_project&.owner&.login,
|
||||||
|
fork_project_identifier: @fork_project&.identifier
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,15 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="box search-form-container project-list-form">
|
<div class="box search-form-container project-list-form">
|
||||||
<%= form_tag(admins_projects_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
<%= form_tag(admins_projects_path, method: :get, class: 'form-inline search-form flex-1', id: 'project-list-form', remote: true) do %>
|
||||||
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '项目名称/标识检索') %>
|
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '项目名称/标识检索') %>
|
||||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||||
|
<div class="form-group mr-2 pull-right" style='margin-left:auto'>
|
||||||
|
<label for="status">项目类别:</label>
|
||||||
|
<% type_options = [['全部项目', ''], ['公开项目', 'public'], ['私有项目', 'private'], ['Fork项目', 'fork'], ['原创项目', 'original']] %>
|
||||||
|
<%= select_tag(:category, options_for_select(type_options, params[:category]), class: 'form-control', id: 'project-category') %>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -16,3 +21,9 @@
|
||||||
|
|
||||||
<div id="projects-modals">
|
<div id="projects-modals">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$("#project-category").on('change', function() {
|
||||||
|
$("#project-list-form").submit()
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -1,5 +1,5 @@
|
||||||
json.total_count @result_object[:total_data].to_i
|
json.total_count @result_object[:total_data].to_i
|
||||||
json.branches @result_object[:data].each do |branch|
|
json.branches @result_object[:data].each do |branch|
|
||||||
json.partial! "api/v1/projects/branches/simple_gitea_detail", branch: branch, default_branch: @result_object[:default_branch]
|
json.partial! "api/v1/projects/branches/simple_gitea_detail", branch: branch, default_branch: @result_object[:default_branch]
|
||||||
|
json.has_pull_request @project.has_pull_request(branch['name'])
|
||||||
end
|
end
|
|
@ -23,10 +23,10 @@ json.issues do
|
||||||
json.pull_request_base pr.base
|
json.pull_request_base pr.base
|
||||||
json.pull_request_staus pr.status == 1 ? "merged" : (pr.status == 2 ? "closed" : "open")
|
json.pull_request_staus pr.status == 1 ? "merged" : (pr.status == 2 ? "closed" : "open")
|
||||||
json.is_original pr.is_original
|
json.is_original pr.is_original
|
||||||
json.fork_project_id pr.fork_project_id.present? ? pr.fork_project_id : pr.project_id
|
json.fork_project_id pr.fork_project_id
|
||||||
json.fork_project_identifier pr.fork_project_id.present? ? pr&.fork_project&.identifier : pr.project&.identifier
|
json.fork_project_identifier pr.fork_project.present? ? pr&.fork_project&.identifier : pr.fork_project_identifier
|
||||||
json.fork_project_user pr.fork_project_id.present? ? pr&.fork_project&.owner.try(:login) : pr.project&.owner.try(:login)
|
json.fork_project_user pr.fork_project.present? ? pr&.fork_project&.owner.try(:login) : pr.fork_project_owner
|
||||||
json.fork_project_user_name pr.fork_project_id.present? ? pr&.fork_project&.owner.try(:show_real_name) : pr.project&.owner.try(:show_real_name)
|
json.fork_project_user_name pr.fork_project.present? ? pr&.fork_project&.owner.try(:show_real_name) : User.find_by(login: pr.fork_project_owner).try(:show_real_name)
|
||||||
json.reviewers pr.reviewers.pluck(:login)
|
json.reviewers pr.reviewers.pluck(:login)
|
||||||
|
|
||||||
json.id issue.id
|
json.id issue.id
|
||||||
|
|
|
@ -25,9 +25,10 @@ end
|
||||||
json.pull_request do
|
json.pull_request do
|
||||||
json.extract! @pull_request, :id,:base, :head, :status, :is_original
|
json.extract! @pull_request, :id,:base, :head, :status, :is_original
|
||||||
json.pull_request_staus @pull_request.status == 1 ? "merged" : (@pull_request.status == 2 ? "closed" : "open")
|
json.pull_request_staus @pull_request.status == 1 ? "merged" : (@pull_request.status == 2 ? "closed" : "open")
|
||||||
json.fork_project_id @pull_request.fork_project_id.present? ? @pull_request.fork_project_id : @pull_request.project_id
|
json.fork_project_id @pull_request.fork_project_id
|
||||||
json.fork_project_user @pull_request.fork_project_id.present? ? @pull_request&.fork_project&.owner.try(:login) : @pull_request.project&.owner.try(:login)
|
json.fork_project_identifier @pull_request.fork_project.present? ? @pull_request&.fork_project&.identifier : @pull_request.fork_project_identifier
|
||||||
json.fork_project_user_name @pull_request.fork_project_id.present? ? @pull_request&.fork_project&.owner.try(:show_real_name) : @pull_request.project&.owner.try(:show_real_name)
|
json.fork_project_user @pull_request.fork_project.present? ? @pull_request&.fork_project&.owner.try(:login) : @pull_request.fork_project_owner
|
||||||
|
json.fork_project_user_name @pull_request.fork_project.present? ? @pull_request&.fork_project&.owner.try(:show_real_name) : User.find_by(login: @pull_request.fork_project_owner).try(:show_real_name)
|
||||||
json.create_user @pull_request&.user&.login
|
json.create_user @pull_request&.user&.login
|
||||||
json.mergeable @gitea_pull["mergeable"]
|
json.mergeable @gitea_pull["mergeable"]
|
||||||
json.state @gitea_pull["state"]
|
json.state @gitea_pull["state"]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
json.total_count @organizations.total_count
|
json.total_count @organizations.total_count
|
||||||
json.organizations @organizations do |organization|
|
json.organizations @organizations do |organization|
|
||||||
json.partial! "/organizations/organizations/detail", organization: organization
|
json.partial! "/organizations/organizations/detail", organization: organization
|
||||||
|
json.is_home_top @home_top_ids.include?(organization.id)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
json.count @total_count
|
json.count @total_count
|
||||||
json.projects do
|
json.projects @projects do |project|
|
||||||
json.partial! '/projects/project_detail', collection: @projects, as: :project
|
json.partial! '/projects/project_detail', project: project
|
||||||
|
json.is_home_top @home_top_ids.include?(project.id)
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,6 +24,11 @@ defaults format: :json do
|
||||||
scope module: :users do
|
scope module: :users do
|
||||||
resources :projects, only: [:index]
|
resources :projects, only: [:index]
|
||||||
resources :feedbacks, only: [:create]
|
resources :feedbacks, only: [:create]
|
||||||
|
resources :home_top_settings, only: [:create] do
|
||||||
|
collection do
|
||||||
|
delete :cancel
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :openkylin_sign, only: [:create] do
|
resources :openkylin_sign, only: [:create] do
|
||||||
collection do
|
collection do
|
||||||
get :competitions
|
get :competitions
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
class CreateHomeTopSettings < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :home_top_settings do |t|
|
||||||
|
t.references :user
|
||||||
|
t.references :top, polymorphic: true, index: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddForkProjectOwnerIdentifierToPullRequests < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :pull_requests, :fork_project_owner, :string
|
||||||
|
add_column :pull_requests, :fork_project_identifier, :string
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue