diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 8719d767e..7b0ee0300 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -40,6 +40,13 @@ body { } } } +.editormd .CodeMirror{ + margin-top: 35px!important; +} + +.CodeMirror-gutter .CodeMirror-linenumbers { + width: 28px!important; +} input.form-control { font-size: 14px; diff --git a/app/controllers/admins/project_licenses_controller.rb b/app/controllers/admins/project_licenses_controller.rb index d573d3c23..8573b0a37 100644 --- a/app/controllers/admins/project_licenses_controller.rb +++ b/app/controllers/admins/project_licenses_controller.rb @@ -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 diff --git a/app/controllers/admins/projects_controller.rb b/app/controllers/admins/projects_controller.rb index fd576b8c8..f5f210a0d 100644 --- a/app/controllers/admins/projects_controller.rb +++ b/app/controllers/admins/projects_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/api/v1/users/home_top_settings_controller.rb b/app/controllers/api/v1/users/home_top_settings_controller.rb new file mode 100644 index 000000000..d329c7e69 --- /dev/null +++ b/app/controllers/api/v1/users/home_top_settings_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/oauth/acge_controller.rb b/app/controllers/oauth/acge_controller.rb index 6f7c82039..d680a26d4 100644 --- a/app/controllers/oauth/acge_controller.rb +++ b/app/controllers/oauth/acge_controller.rb @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2db6af016..202bae458 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/app/controllers/users/organizations_controller.rb b/app/controllers/users/organizations_controller.rb index 2d949da7d..2d80adb9b 100644 --- a/app/controllers/users/organizations_controller.rb +++ b/app/controllers/users/organizations_controller.rb @@ -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 diff --git a/app/controllers/users/projects_controller.rb b/app/controllers/users/projects_controller.rb index 8ffa8fa85..55ff17192 100644 --- a/app/controllers/users/projects_controller.rb +++ b/app/controllers/users/projects_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b976ee8fa..27895a758 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/forms/projects/migrate_form.rb b/app/forms/projects/migrate_form.rb index 8c1d04968..1a1c5c389 100644 --- a/app/forms/projects/migrate_form.rb +++ b/app/forms/projects/migrate_form.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5d5582428..d670e9a0d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/concerns/matchable.rb b/app/models/concerns/matchable.rb index 0640e7c74..27e5a0dda 100644 --- a/app/models/concerns/matchable.rb +++ b/app/models/concerns/matchable.rb @@ -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 diff --git a/app/models/home_top_setting.rb b/app/models/home_top_setting.rb new file mode 100644 index 000000000..78486620f --- /dev/null +++ b/app/models/home_top_setting.rb @@ -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 diff --git a/app/models/license.rb b/app/models/license.rb index d14a9db14..342bda029 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -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 diff --git a/app/models/organization.rb b/app/models/organization.rb index faa6396df..8ac1b80e6 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 8f23fdb23..5db75ce25 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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? diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 0142f27f6..26b4ce2c6 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 933300c70..988f6d8c2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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]) } diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index 27415543d..32a9ee787 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -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 diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 09a02010c..737cd7c2d 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -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 # 优化排序 diff --git a/app/services/api/v1/users/home_top_settings/create_service.rb b/app/services/api/v1/users/home_top_settings/create_service.rb new file mode 100644 index 000000000..0c4cea59e --- /dev/null +++ b/app/services/api/v1/users/home_top_settings/create_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/api/v1/users/home_top_settings/delete_service.rb b/app/services/api/v1/users/home_top_settings/delete_service.rb new file mode 100644 index 000000000..e3ce9fe1f --- /dev/null +++ b/app/services/api/v1/users/home_top_settings/delete_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/api/v1/users/projects/list_service.rb b/app/services/api/v1/users/projects/list_service.rb index 47457c58c..079d9d796 100644 --- a/app/services/api/v1/users/projects/list_service.rb +++ b/app/services/api/v1/users/projects/list_service.rb @@ -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 diff --git a/app/services/gitea/accelerator/migrate_service.rb b/app/services/gitea/accelerator/migrate_service.rb index 86b8b3db1..5de97fe70 100644 --- a/app/services/gitea/accelerator/migrate_service.rb +++ b/app/services/gitea/accelerator/migrate_service.rb @@ -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 diff --git a/app/services/gitea/repository/delete_service.rb b/app/services/gitea/repository/delete_service.rb index c5d5c1b50..c9aae3295 100644 --- a/app/services/gitea/repository/delete_service.rb +++ b/app/services/gitea/repository/delete_service.rb @@ -8,7 +8,7 @@ class Gitea::Repository::DeleteService < Gitea::ClientService end def call - delete(url, params) + delete(url, params, true) end private diff --git a/app/services/projects/migrate_service.rb b/app/services/projects/migrate_service.rb index f157ada1d..d81e24189 100644 --- a/app/services/projects/migrate_service.rb +++ b/app/services/projects/migrate_service.rb @@ -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] } diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 2060feeea..43ae135dc 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -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}) diff --git a/app/services/projects/verify_auth_token_service.rb b/app/services/projects/verify_auth_token_service.rb index 36dcb106f..1f6b7a076 100644 --- a/app/services/projects/verify_auth_token_service.rb +++ b/app/services/projects/verify_auth_token_service.rb @@ -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 } diff --git a/app/services/pull_requests/create_service.rb b/app/services/pull_requests/create_service.rb index 070b564d9..0010f8755 100644 --- a/app/services/pull_requests/create_service.rb +++ b/app/services/pull_requests/create_service.rb @@ -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 diff --git a/app/services/repositories/migrate_service.rb b/app/services/repositories/migrate_service.rb index deb0e30d3..4c3d4668d 100644 --- a/app/services/repositories/migrate_service.rb +++ b/app/services/repositories/migrate_service.rb @@ -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 diff --git a/app/services/users/project_service.rb b/app/services/users/project_service.rb index f08b96009..86b2e9bb2 100644 --- a/app/services/users/project_service.rb +++ b/app/services/users/project_service.rb @@ -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 diff --git a/app/views/admins/feedbacks/_history_form_modal.html.erb b/app/views/admins/feedbacks/_history_form_modal.html.erb index df12a73d3..c5304bfc4 100644 --- a/app/views/admins/feedbacks/_history_form_modal.html.erb +++ b/app/views/admins/feedbacks/_history_form_modal.html.erb @@ -2,7 +2,12 @@