Merge branch 'standalone_develop' into pm_project_develop
This commit is contained in:
commit
eaeb65443e
|
@ -40,6 +40,13 @@ body {
|
|||
}
|
||||
}
|
||||
}
|
||||
.editormd .CodeMirror{
|
||||
margin-top: 35px!important;
|
||||
}
|
||||
|
||||
.CodeMirror-gutter .CodeMirror-linenumbers {
|
||||
width: 28px!important;
|
||||
}
|
||||
|
||||
input.form-control {
|
||||
font-size: 14px;
|
||||
|
|
|
@ -7,7 +7,7 @@ class Admins::ProjectLicensesController < Admins::BaseController
|
|||
sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
q = License.ransack(name_cont: params[:search])
|
||||
project_licenses = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||
project_licenses = q.result(distinct: true).reorder("#{sort_by} #{sort_direction}")
|
||||
@project_licenses = paginate(project_licenses)
|
||||
end
|
||||
|
||||
|
@ -96,7 +96,7 @@ class Admins::ProjectLicensesController < Admins::BaseController
|
|||
end
|
||||
|
||||
def license_params
|
||||
params.require(:license).permit(:name,:content)
|
||||
params.require(:license).permit(:name,:content,:position)
|
||||
end
|
||||
|
||||
# def validate_params
|
||||
|
|
|
@ -7,6 +7,16 @@ class Admins::ProjectsController < Admins::BaseController
|
|||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
search = params[:search].to_s.strip
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -33,8 +43,12 @@ class Admins::ProjectsController < Admins::BaseController
|
|||
def destroy
|
||||
project = Project.find_by!(id: params[:id])
|
||||
ActiveRecord::Base.transaction do
|
||||
close_fork_pull_requests_by(project)
|
||||
Gitea::Repository::DeleteService.new(project.owner, project.identifier, current_user.gitea_token).call
|
||||
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
|
||||
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
|
||||
|
@ -53,4 +67,19 @@ class Admins::ProjectsController < Admins::BaseController
|
|||
def project_update_params
|
||||
params.require(:project).permit(:is_pinned, :recommend, :recommend_index)
|
||||
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
|
|
@ -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
|
|
@ -1,6 +1,18 @@
|
|||
class Oauth::AcgeController < Oauth::BaseController
|
||||
include RegisterHelper
|
||||
|
||||
def refer
|
||||
uid = params['uid'].to_s.strip
|
||||
tip_exception("uid不能为空") if uid.blank?
|
||||
|
||||
open_user = OpenUsers::Acge.find_by(uid: uid)
|
||||
if open_user.present? && open_user.user.present?
|
||||
render :json => {login: open_user.user.login}
|
||||
else
|
||||
render_not_found
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
begin
|
||||
uid = params['uid'].to_s.strip
|
||||
|
|
|
@ -43,11 +43,11 @@ class ProjectsController < ApplicationController
|
|||
|
||||
category_id = params[:category_id]
|
||||
@total_count =
|
||||
if category_id.blank? && params[:search].blank? && params[:topic_id].blank?
|
||||
if category_id.blank? && params[:search].blank? && params[:topic_id].blank? && params[:topic_name].blank?
|
||||
# 默认查询时count性能问题处理
|
||||
not_category_count = Project.where(project_category_id: nil).count
|
||||
ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count + not_category_count
|
||||
elsif params[:search].present? || params[:topic_id].present?
|
||||
elsif params[:search].present? || params[:topic_id].present? || params[:topic_name].present?
|
||||
@projects.total_count
|
||||
else
|
||||
cate = ProjectCategory.find_by(id: category_id)
|
||||
|
@ -217,6 +217,10 @@ class ProjectsController < ApplicationController
|
|||
|
||||
new_project_params = project_params.except(:private).merge(is_public: !private)
|
||||
@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)}
|
||||
gitea_params = {
|
||||
private: private,
|
||||
|
@ -249,6 +253,7 @@ class ProjectsController < ApplicationController
|
|||
def destroy
|
||||
if current_user.admin? || @project.manager?(current_user)
|
||||
ActiveRecord::Base.transaction do
|
||||
close_fork_pull_requests_by(@project)
|
||||
Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call
|
||||
@project.destroy!
|
||||
@project.forked_projects.update_all(forked_from_project_id: nil)
|
||||
|
@ -381,7 +386,7 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def mirror_params
|
||||
params.permit(:user_id, :name, :description, :repository_name, :is_mirror, :auth_username, :auth_token,
|
||||
params.permit(:user_id, :name, :description, :repository_name, :is_mirror, :auth_username, :auth_token, :service,
|
||||
:auth_password, :project_category_id, :project_language_id, :clone_addr, :private)
|
||||
end
|
||||
|
||||
|
@ -399,4 +404,19 @@ class ProjectsController < ApplicationController
|
|||
render_unauthorized('你还未登录.')
|
||||
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
|
||||
|
|
|
@ -10,7 +10,15 @@ class Users::OrganizationsController < Users::BaseController
|
|||
end
|
||||
|
||||
@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)
|
||||
end
|
||||
|
||||
|
|
|
@ -20,6 +20,6 @@ class Users::ProjectsController < Users::BaseController
|
|||
private
|
||||
|
||||
def query_params
|
||||
params.permit(:category, :status, :sort_direction)
|
||||
params.permit(:category, :status, :sort_direction, :topic_name)
|
||||
end
|
||||
end
|
|
@ -408,7 +408,7 @@ class UsersController < ApplicationController
|
|||
|
||||
def projects
|
||||
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
|
||||
@projects = kaminari_unlimit_paginate(scope)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Projects::MigrateForm < BaseForm
|
||||
attr_accessor :user_id, :name, :repository_name, :project_category_id, :description, :auth_token,
|
||||
attr_accessor :user_id, :name, :repository_name, :project_category_id, :description, :auth_token, :service,
|
||||
:project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner
|
||||
|
||||
validates :user_id, :name, :repository_name, :clone_addr, presence: true
|
||||
|
|
|
@ -479,7 +479,7 @@ module ApplicationHelper
|
|||
|
||||
return if url.blank?
|
||||
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
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ module Matchable
|
|||
scope :with_project_type, ->(project_type) { where(project_type: project_type) if Project.project_types.include?(project_type) }
|
||||
scope :by_name_or_identifier, ->(search) { where("name like :search or identifier LIKE :search", :search => "%#{search.split(" ").join('|')}%") unless search.blank? }
|
||||
scope :with_project_topic, ->(topic_id) {joins(:project_topics).where(project_topics: {id: topic_id}) unless topic_id.blank?}
|
||||
scope :with_project_topic_name, ->(topic_name) {joins(:project_topics).where(project_topics: {name: topic_name}) unless topic_name.blank?}
|
||||
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
|
|
@ -7,9 +7,12 @@
|
|||
# content :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# position :integer default("0")
|
||||
#
|
||||
|
||||
class License < ApplicationRecord
|
||||
default_scope { order(position: :desc) }
|
||||
|
||||
include Projectable
|
||||
|
||||
validates :name, :content, presence: true
|
||||
|
|
|
@ -76,6 +76,7 @@ class Organization < Owner
|
|||
has_many :team_users, 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 :home_top_settings, as: :top, dependent: :destroy
|
||||
|
||||
validates :login, presence: true
|
||||
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
|
||||
|
|
|
@ -139,6 +139,7 @@ class Project < ApplicationRecord
|
|||
has_many :daily_project_statistics, dependent: :destroy
|
||||
has_one :project_dataset, 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_save :check_project_members
|
||||
before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data
|
||||
|
@ -462,6 +463,15 @@ class Project < ApplicationRecord
|
|||
EduSetting.get("open_portrait_projects").present? ? EduSetting.get("open_portrait_projects").split(",").include?(self.id.to_s) : false
|
||||
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
|
||||
cache_result = $redis_cache.get("ProjectMindsporeContributors")
|
||||
if cache_result.nil?
|
||||
|
|
|
@ -2,25 +2,27 @@
|
|||
#
|
||||
# Table name: pull_requests
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# gitea_id :integer
|
||||
# gitea_number :integer
|
||||
# user_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# status :integer default("0")
|
||||
# project_id :integer
|
||||
# title :string(255)
|
||||
# milestone :integer
|
||||
# body :text(4294967295)
|
||||
# head :string(255)
|
||||
# base :string(255)
|
||||
# issue_id :integer
|
||||
# fork_project_id :integer
|
||||
# is_original :boolean default("0")
|
||||
# comments_count :integer default("0")
|
||||
# commits_count :integer default("0")
|
||||
# files_count :integer default("0")
|
||||
# id :integer not null, primary key
|
||||
# gitea_id :integer
|
||||
# gitea_number :integer
|
||||
# user_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# status :integer default("0")
|
||||
# project_id :integer
|
||||
# title :string(255)
|
||||
# milestone :integer
|
||||
# body :text(4294967295)
|
||||
# head :string(255)
|
||||
# base :string(255)
|
||||
# issue_id :integer
|
||||
# fork_project_id :integer
|
||||
# is_original :boolean default("0")
|
||||
# comments_count :integer default("0")
|
||||
# commits_count :integer default("0")
|
||||
# files_count :integer default("0")
|
||||
# fork_project_owner :string(255)
|
||||
# fork_project_identifier :string(255)
|
||||
#
|
||||
|
||||
class PullRequest < ApplicationRecord
|
||||
|
|
|
@ -190,6 +190,7 @@ class User < Owner
|
|||
has_many :clas, through: :user_clas
|
||||
|
||||
has_one :page, :dependent => :destroy
|
||||
has_many :home_top_settings, dependent: :destroy
|
||||
|
||||
# Groups and active users
|
||||
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) }
|
||||
|
|
|
@ -20,11 +20,11 @@ class Projects::ListMyQuery < ApplicationQuery
|
|||
if params[:category].blank?
|
||||
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
|
||||
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"
|
||||
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
|
||||
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"
|
||||
projects = projects.where(user_id: user.id)
|
||||
elsif params[:category].to_s == "watched" #我关注的
|
||||
|
@ -37,7 +37,7 @@ class Projects::ListMyQuery < ApplicationQuery
|
|||
elsif params[:category].to_s == "admin"
|
||||
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
|
||||
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"
|
||||
# projects = projects.visible.joins(:members).where(members: { user_id: user.id })
|
||||
# elsif params[:category].to_s == "private"
|
||||
|
@ -63,6 +63,15 @@ class Projects::ListMyQuery < ApplicationQuery
|
|||
projects = projects.sync_mirror
|
||||
end
|
||||
|
||||
if params[:topic_name].present?
|
||||
projects = projects.with_project_topic_name(params[:topic_name].to_s.split(","))
|
||||
end
|
||||
|
||||
if params[:topic_id].present?
|
||||
projects = projects.with_project_topic(params[:topic_id])
|
||||
end
|
||||
|
||||
|
||||
# 表情处理
|
||||
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
q = projects.ransack(name_or_identifier_cont: keywords)
|
||||
|
@ -71,11 +80,21 @@ class Projects::ListMyQuery < ApplicationQuery
|
|||
|
||||
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"
|
||||
|
||||
|
||||
@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)
|
||||
scope.order("FIELD(id, #{params[:choosed].reverse.join(",")}) desc")
|
||||
scope = scope.distinct.order("FIELD(projects.id, #{params[:choosed].reverse.join(",")}) desc")
|
||||
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}")
|
||||
elsif params[:topic_name].present?
|
||||
scope = scope.distinct.order("project_topics.id asc, projects.#{sort} #{sort_direction}")
|
||||
else
|
||||
scope = scope.distinct.order("projects.#{sort} #{sort_direction}")
|
||||
end
|
||||
end
|
||||
|
||||
return scope, @home_top_ids
|
||||
end
|
||||
end
|
||||
|
|
|
@ -77,7 +77,11 @@ class Projects::ListQuery < ApplicationQuery
|
|||
end
|
||||
|
||||
def by_project_topic(items)
|
||||
items.with_project_topic(params[:topic_id])
|
||||
if params[:topic_name].present?
|
||||
items.with_project_topic_name(params[:topic_name].to_s.split(","))
|
||||
else
|
||||
items.with_project_topic(params[:topic_id])
|
||||
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
|
|
@ -34,7 +34,7 @@ class Api::V1::Users::Projects::ListService < ApplicationService
|
|||
|
||||
private
|
||||
def project_query_data
|
||||
if current_user.admin?
|
||||
if current_user.admin? || @observe_user.id == current_user.id
|
||||
projects = Project
|
||||
else
|
||||
projects = Project.visible
|
||||
|
|
|
@ -45,6 +45,7 @@ class Gitea::Accelerator::MigrateService < Gitea::Accelerator::BaseService
|
|||
repo_name: params[:repository_name],
|
||||
auth_username: params[:auth_username],
|
||||
auth_password: Base64.decode64(params[:auth_password]),
|
||||
auth_token: params[:auth_token],
|
||||
mirror: ActiveModel::Type::Boolean.new.cast(params[:is_mirror])
|
||||
}
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ class Gitea::Repository::DeleteService < Gitea::ClientService
|
|||
end
|
||||
|
||||
def call
|
||||
delete(url, params)
|
||||
delete(url, params, true)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -55,6 +55,7 @@ class Projects::MigrateService < ApplicationService
|
|||
login: params[:auth_username],
|
||||
password: params[:auth_password],
|
||||
auth_token: params[:auth_token],
|
||||
service: params[:service],
|
||||
is_mirror: params[:is_mirror],
|
||||
source_clone_url: params[:source_clone_url]
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ class Projects::TransferService < ApplicationService
|
|||
update_repo_url
|
||||
update_visit_teams
|
||||
update_fork_info
|
||||
update_fork_pull_request_info
|
||||
end
|
||||
|
||||
Rails.logger.info("##### Project transfer_service end ######")
|
||||
|
@ -60,6 +61,11 @@ class Projects::TransferService < ApplicationService
|
|||
fork_user.update(user_id: @new_owner.id) if fork_user.present?
|
||||
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
|
||||
begin
|
||||
@gitea_repo = $gitea_hat_client.post_repos_transfer_by_owner_repo(owner&.login, project.identifier, {body: {new_owner: new_owner&.login}.to_json})
|
||||
|
|
|
@ -36,16 +36,66 @@ class Projects::VerifyAuthTokenService < ApplicationService
|
|||
gitlab_verify
|
||||
when "gitee.com"
|
||||
gitee_verify
|
||||
when "gitlink.org.cn"
|
||||
gitlink_verify
|
||||
when "gitea.com"
|
||||
gitea_verify
|
||||
when "gitcode.com"
|
||||
gitcode_verify
|
||||
else
|
||||
@success = nil
|
||||
end
|
||||
end
|
||||
|
||||
def gitcode_verify
|
||||
url = "/api/v5/user"
|
||||
api_url = "https://api.gitcode.com"
|
||||
client = Faraday.new(url: api_url)
|
||||
client.options["open_timeout"] = 100
|
||||
client.options["timeout"] = 100
|
||||
client.options["write_timeout"] = 100
|
||||
req_params={
|
||||
access_token: @token
|
||||
}
|
||||
response = client.public_send("get", url, req_params)
|
||||
@success = true if response.status == 200
|
||||
end
|
||||
|
||||
def gitea_verify
|
||||
url = "/api/v1/user"
|
||||
api_url = "https://gitea.com"
|
||||
client = Faraday.new(url: api_url)
|
||||
client.options["open_timeout"] = 100
|
||||
client.options["timeout"] = 100
|
||||
client.options["write_timeout"] = 100
|
||||
req_params={
|
||||
token: @token
|
||||
}
|
||||
response = client.public_send("get", url, req_params)
|
||||
@success = true if response.status == 200
|
||||
end
|
||||
|
||||
def gitlink_verify
|
||||
url = "/api/v1/user"
|
||||
api_url = "https://cdn05042023.gitlink.org.cn"
|
||||
client = Faraday.new(url: api_url)
|
||||
client.options["open_timeout"] = 100
|
||||
client.options["timeout"] = 100
|
||||
client.options["write_timeout"] = 100
|
||||
req_params={
|
||||
token: @token
|
||||
}
|
||||
response = client.public_send("get", url, req_params)
|
||||
@success = true if response.status == 200
|
||||
end
|
||||
|
||||
def gitee_verify
|
||||
url = "/api/v5/repos/#{@owner}/#{@repo}"
|
||||
api_url= "https://gitee.com"
|
||||
client = Faraday.new(url: api_url)
|
||||
client.options["open_timeout"] = 1
|
||||
client.options["timeout"] = 1
|
||||
client.options["write_timeout"] = 1
|
||||
client.options["open_timeout"] = 100
|
||||
client.options["timeout"] = 100
|
||||
client.options["write_timeout"] = 100
|
||||
req_params={
|
||||
access_token: @token,
|
||||
owner: @owner,
|
||||
|
@ -59,9 +109,9 @@ class Projects::VerifyAuthTokenService < ApplicationService
|
|||
url = "/octocat"
|
||||
api_url= "https://api.github.com"
|
||||
client = Faraday.new(url: api_url)
|
||||
client.options["open_timeout"] = 1
|
||||
client.options["timeout"] = 1
|
||||
client.options["write_timeout"] = 1
|
||||
client.options["open_timeout"] = 100
|
||||
client.options["timeout"] = 100
|
||||
client.options["write_timeout"] = 100
|
||||
client.headers["Authorization"] = "Bearer #{@token}"
|
||||
response = client.public_send("get", url)
|
||||
@success = true if response.status == 200
|
||||
|
@ -71,9 +121,9 @@ class Projects::VerifyAuthTokenService < ApplicationService
|
|||
url = "/api/v4/projects"
|
||||
api_url= "https://gitlab.com"
|
||||
client = Faraday.new(url: api_url)
|
||||
client.options["open_timeout"] = 1
|
||||
client.options["timeout"] = 1
|
||||
client.options["write_timeout"] = 1
|
||||
client.options["open_timeout"] = 100
|
||||
client.options["timeout"] = 100
|
||||
client.options["write_timeout"] = 100
|
||||
req_params={
|
||||
private_token: @token
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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
|
||||
|
||||
def initialize(current_user, owner, project, params)
|
||||
|
@ -8,6 +8,7 @@ class PullRequests::CreateService < ApplicationService
|
|||
@project = project
|
||||
@params = params
|
||||
@current_user = current_user
|
||||
@fork_project = Project.find_by_id(params[:fork_project_id])
|
||||
end
|
||||
|
||||
def call
|
||||
|
@ -102,7 +103,9 @@ class PullRequests::CreateService < ApplicationService
|
|||
fork_project_id: @params[:fork_project_id],
|
||||
is_original: is_original,
|
||||
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
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class Repositories::MigrateService < ApplicationService
|
|||
|
||||
private
|
||||
def repository_params
|
||||
params.merge(project_id: project.id)
|
||||
params.except(:service).merge(project_id: project.id)
|
||||
end
|
||||
|
||||
def gitea_repository_params
|
||||
|
@ -33,7 +33,8 @@ class Repositories::MigrateService < ApplicationService
|
|||
mirror: wrapper_mirror || false,
|
||||
auth_username: params[:login],
|
||||
auth_password: Base64.decode64(params[:password] || ""),
|
||||
auth_token: params[:auth_token]
|
||||
auth_token: params[:auth_token],
|
||||
service: params[:service] || 'git',
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ class Users::ProjectService
|
|||
|
||||
projects = category_filter(projects)
|
||||
projects = status_filter(projects)
|
||||
projects = by_project_topic(projects)
|
||||
|
||||
custom_sort(projects, params[:sort_by], params[:sort_direction])
|
||||
end
|
||||
|
@ -45,6 +46,14 @@ class Users::ProjectService
|
|||
end
|
||||
end
|
||||
|
||||
def by_project_topic(items)
|
||||
if params[:topic_name].present?
|
||||
items.with_project_topic_name(params[:topic_name].to_s.split(","))
|
||||
else
|
||||
items.with_project_topic(params[:topic_id])
|
||||
end
|
||||
end
|
||||
|
||||
def self_or_admin?
|
||||
User.current.id == user.id || User.current.admin?
|
||||
end
|
||||
|
|
|
@ -2,7 +2,12 @@
|
|||
<div class="modal-dialog modal-dialog-centered" role="document" style="max-width: 800px">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">发送邮件给<%= @feedback&.user&.mail%></h5>
|
||||
<h5 class="modal-title">
|
||||
发送邮件给<%= @feedback&.user&.mail%>
|
||||
<% if @feedback&.user&.mail.end_with?('@example.org') || @feedback&.user&.mail.end_with?('@gitlink.org.cn')%>
|
||||
<span style="color: red">(该邮箱不可用)</span>
|
||||
<% end %>
|
||||
</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
|
|
|
@ -30,6 +30,18 @@
|
|||
|
||||
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<span class="color-grey-6 pt10">
|
||||
排序等级
|
||||
<span class="ml10 color-orange mr20">*</span>
|
||||
</span>
|
||||
</label>
|
||||
<div class="mt-10">
|
||||
<%= f.number_field :position, class: "form-control",placeholder: ""%>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<%= f.submit "确认", class: "btn btn-primary submit-btn" %>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<th width="5%">序号</th>
|
||||
<th width="15%">名称</th>
|
||||
<th width="35%">简介</th>
|
||||
<th width="10%"><%= sort_tag('排序等级', name: 'position', path: admins_project_licenses_path) %></th>
|
||||
<%
|
||||
=begin%>
|
||||
<th width="10%"><%= sort_tag('项目数', name: 'projects_count', path: admins_project_licenses_path) %></th>
|
||||
|
@ -24,6 +25,7 @@
|
|||
<td>
|
||||
<%= project_license.content.to_s.truncate(200) %>
|
||||
</td>
|
||||
<td><%= project_license.position %></td>
|
||||
<%
|
||||
=begin%>
|
||||
<td><%= project_license.projects_count %></td>
|
||||
|
|
|
@ -3,10 +3,15 @@
|
|||
<% end %>
|
||||
|
||||
<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: '项目名称/标识检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<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 %>
|
||||
</div>
|
||||
|
||||
|
@ -16,3 +21,9 @@
|
|||
|
||||
<div id="projects-modals">
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$("#project-category").on('change', function() {
|
||||
$("#project-list-form").submit()
|
||||
});
|
||||
</script>
|
|
@ -50,7 +50,7 @@
|
|||
<li>
|
||||
<%= sidebar_item_group('#setting-index', '首页配置', icon: 'file', has_permission: current_user.admin? || current_user.business?) do %>
|
||||
<li><%= sidebar_item(admins_topic_banners_path, 'banner管理', icon: 'image', controller: 'admins-topic-banners', has_permission: current_user.admin? || current_user.business?) %></li>
|
||||
<li><%= sidebar_item(admins_topic_cards_path, '卡片管理', icon: 'archive', controller: 'admins-topic-cards', has_permission: current_user.admin? || current_user.business?) %></li>
|
||||
<!--<li><%#= sidebar_item(admins_topic_cards_path, '卡片管理', icon: 'archive', controller: 'admins-topic-cards', has_permission: current_user.admin? || current_user.business?) %></li>-->
|
||||
<li><%= sidebar_item(admins_topic_activity_forums_path, '平台动态管理', icon: 'bell', controller: 'admins-topic-activity_forums', has_permission: current_user.admin? || current_user.business?) %></li>
|
||||
<li><%= sidebar_item(admins_topic_excellent_projects_path, '优秀仓库管理', icon: 'git', controller: 'admins-topic-excellent_projects', has_permission: current_user.admin? || current_user.business?) %></li>
|
||||
<li><%= sidebar_item(admins_topic_pinned_forums_path, '精选文章管理', icon: 'edit', controller: 'admins-topic-pinned_forums', has_permission: current_user.admin? || current_user.business?) %></li>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
json.total_count @result_object[:total_data].to_i
|
||||
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.has_pull_request @project.has_pull_request(branch['name'])
|
||||
end
|
|
@ -5,6 +5,7 @@ json.projects @projects.each do |project|
|
|||
json.type project.numerical_for_project_type
|
||||
json.praised project.praised_by?(current_user)
|
||||
json.last_update_time render_unix_time(project.updated_on)
|
||||
json.full_last_update_time project.updated_on
|
||||
json.time_ago time_from_now(project.updated_on)
|
||||
json.language do
|
||||
if project.project_language.blank?
|
||||
|
|
|
@ -13,6 +13,7 @@ json.is_public project.is_public
|
|||
json.mirror_url project.repository&.mirror_url
|
||||
json.type project&.numerical_for_project_type
|
||||
json.last_update_time render_unix_time(project.updated_on)
|
||||
json.full_last_update_time project.updated_on
|
||||
json.time_ago time_from_now(project.updated_on)
|
||||
json.forked_from_project_id project.forked_from_project_id
|
||||
json.open_devops project.open_devops?
|
||||
|
|
|
@ -23,10 +23,10 @@ json.issues do
|
|||
json.pull_request_base pr.base
|
||||
json.pull_request_staus pr.status == 1 ? "merged" : (pr.status == 2 ? "closed" : "open")
|
||||
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_identifier pr.fork_project_id.present? ? pr&.fork_project&.identifier : pr.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_name pr.fork_project_id.present? ? pr&.fork_project&.owner.try(:show_real_name) : pr.project&.owner.try(:show_real_name)
|
||||
json.fork_project_id pr.fork_project_id
|
||||
json.fork_project_identifier pr.fork_project.present? ? pr&.fork_project&.identifier : pr.fork_project_identifier
|
||||
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.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.id issue.id
|
||||
|
|
|
@ -25,9 +25,10 @@ end
|
|||
json.pull_request do
|
||||
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.fork_project_id @pull_request.fork_project_id.present? ? @pull_request.fork_project_id : @pull_request.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_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_id @pull_request.fork_project_id
|
||||
json.fork_project_identifier @pull_request.fork_project.present? ? @pull_request&.fork_project&.identifier : @pull_request.fork_project_identifier
|
||||
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.mergeable @gitea_pull["mergeable"]
|
||||
json.state @gitea_pull["state"]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
json.total_count @organizations.total_count
|
||||
json.organizations @organizations do |organization|
|
||||
json.partial! "/organizations/organizations/detail", organization: organization
|
||||
json.is_home_top @home_top_ids.include?(organization.id)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
json.count @total_count
|
||||
json.projects do
|
||||
json.partial! '/projects/project_detail', collection: @projects, as: :project
|
||||
json.projects @projects do |project|
|
||||
json.partial! '/projects/project_detail', project: project
|
||||
json.is_home_top @home_top_ids.include?(project.id)
|
||||
end
|
||||
|
|
|
@ -26,6 +26,7 @@ Rails.application.routes.draw do
|
|||
get 'auth/failure', to: 'oauth/base#auth_failure'
|
||||
get 'auth/cas/callback', to: 'oauth/cas#create'
|
||||
get 'auth/acge/callback', to: "oauth/acge#create"
|
||||
get 'auth/acge/refer', to: "oauth/acge#refer"
|
||||
get 'auth/:provider/callback', to: 'oauth/callbacks#create'
|
||||
|
||||
get 'oauth/bind', to: 'oauth/educoder#bind'
|
||||
|
|
|
@ -65,6 +65,11 @@ defaults format: :json do
|
|||
scope module: :users do
|
||||
resources :projects, only: [:index]
|
||||
resources :feedbacks, only: [:create]
|
||||
resources :home_top_settings, only: [:create] do
|
||||
collection do
|
||||
delete :cancel
|
||||
end
|
||||
end
|
||||
resources :openkylin_sign, only: [:create] do
|
||||
collection do
|
||||
get :competitions
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class CreateHomeTopSettings < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :home_top_settings, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8' 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
|
|
@ -0,0 +1,5 @@
|
|||
class AddPositionToLicenses < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :licenses, :position, :integer, default: 0
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue