Merge branch 'standalone_develop' into pre_trustie_server
This commit is contained in:
commit
0f5b0b6b48
|
@ -1103,7 +1103,7 @@ class ApplicationController < ActionController::Base
|
||||||
"author_time": commit['commit']['author']['date'],
|
"author_time": commit['commit']['author']['date'],
|
||||||
"committer_time": commit['commit']['committer']['date'],
|
"committer_time": commit['commit']['committer']['date'],
|
||||||
"content": commit['commit']['message'],
|
"content": commit['commit']['message'],
|
||||||
"commit_diff": commit_diff['Files'].to_s
|
"commit_diff": commit_diff.present? ? commit_diff['Files'].to_s : ""
|
||||||
}.to_json
|
}.to_json
|
||||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||||
if resp_body['status'] == 7
|
if resp_body['status'] == 7
|
||||||
|
|
|
@ -2,18 +2,44 @@ class ForksController < ApplicationController
|
||||||
before_action :require_login
|
before_action :require_login
|
||||||
before_action :require_profile_completed, only: [:create]
|
before_action :require_profile_completed, only: [:create]
|
||||||
before_action :load_project
|
before_action :load_project
|
||||||
before_action :authenticate_project!, :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
before_action :authenticate_project!, only: [:create]
|
||||||
|
|
||||||
|
def fork_list
|
||||||
|
@user = current_user
|
||||||
|
@organizations = current_user.organizations
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@new_project = Projects::ForkService.new(current_user, @project, params[:organization], params[:new_name], params[:new_identifier]).call
|
target_owner = if params[:organization].present? && @organization
|
||||||
|
@organization
|
||||||
|
else
|
||||||
|
current_user
|
||||||
|
end
|
||||||
|
@new_project = Projects::ForkService.new(target_owner, @project, params[:organization], params[:new_name], params[:new_identifier]).call
|
||||||
|
if @new_project == false
|
||||||
|
render_result(-1, "已fork过一次该项目,无法再次进行fork")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def authenticate_project!
|
def authenticate_project!
|
||||||
if current_user&.id == @project.user_id && (params[:new_identifier].blank? || params[:new_identifier] == @project.identifier)
|
if params[:organization].present?
|
||||||
render_result(-1, "自己不能fork自己的项目")
|
return render_forbidden('参数错误,当organization存在时不允许fork重命名') if params[:new_identifier].present? || params[:new_name].present?
|
||||||
elsif Project.exists?(user_id: current_user.id, identifier: (params[:new_identifier] || @project.identifier))
|
@organization = Organization.find_by(login:params[:organization])
|
||||||
render_result(0, "fork失败,你已拥有了这个项目")
|
return render_forbidden('仓库不存在') unless @organization.present?
|
||||||
|
return render_forbidden('你没有权限操作') unless @organization.is_admin?(current_user.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
if params[:organization].blank? && Project.exists?(user_id: current_user.id, identifier: (params[:new_identifier] || @project.identifier))
|
||||||
|
render_result(-1, "fork失败,您已拥有了这个项目")
|
||||||
|
elsif @organization && Project.exists?(user_id: [@organization.id], identifier: (params[:new_identifier] || @project.identifier))
|
||||||
|
render_result(-1, "fork失败,组织已拥有了这个项目")
|
||||||
|
elsif gitea_check_exit(current_user)
|
||||||
|
render_result(-1, "fork失败,请联系系统管理员")
|
||||||
|
elsif @organization && gitea_check_exit(@organization)
|
||||||
|
render_result(-1, "fork失败,请联系系统管理员")
|
||||||
end
|
end
|
||||||
# return if current_user != @project.owner
|
# return if current_user != @project.owner
|
||||||
# render_result(-1, "自己不能fork自己的项目")
|
# render_result(-1, "自己不能fork自己的项目")
|
||||||
|
@ -24,4 +50,9 @@ class ForksController < ApplicationController
|
||||||
return if @project.member?(current_user) || current_user.admin?
|
return if @project.member?(current_user) || current_user.admin?
|
||||||
render_forbidden('你没有权限操作')
|
render_forbidden('你没有权限操作')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def gitea_check_exit(user)
|
||||||
|
data = Gitea::Repository::GetService.new(user, params[:new_identifier]|| @project.identifier).call
|
||||||
|
data.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -176,6 +176,9 @@ class RepositoriesController < ApplicationController
|
||||||
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]})
|
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]})
|
||||||
@total_count = result[:total_count]
|
@total_count = result[:total_count]
|
||||||
@contributors = result.is_a?(Hash) ? result[:body] : []
|
@contributors = result.is_a?(Hash) ? result[:body] : []
|
||||||
|
|
||||||
|
add_contributors_count = EduSetting.get("ProjectAddContributors-#{@project.id}")
|
||||||
|
@total_count = @total_count + add_contributors_count.to_i
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
@contributors = []
|
@contributors = []
|
||||||
|
|
|
@ -212,6 +212,8 @@ class UsersController < ApplicationController
|
||||||
def update
|
def update
|
||||||
return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id])
|
return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id])
|
||||||
return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
|
return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
|
||||||
|
keywords = user_params[:nickname].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||||
|
return normal_status(-1, "昵称中包含关键词:#{keywords},请重新命名") if ReversedKeyword.check_exists?(keywords)
|
||||||
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
|
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
|
||||||
@user.attributes = user_params.except(:image)
|
@user.attributes = user_params.except(:image)
|
||||||
unless @user.save
|
unless @user.save
|
||||||
|
|
|
@ -42,6 +42,9 @@ module Gitea
|
||||||
def render_result(response)
|
def render_result(response)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
@result = JSON.parse(response.body)
|
@result = JSON.parse(response.body)
|
||||||
|
else
|
||||||
|
Rails.logger.info("Gitea::Repository::Entries::UpdateService error======#{response.body}")
|
||||||
|
@error = "更新失败"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Api::V1::Projects::Contributors::StatService < ApplicationService
|
||||||
def initialize(project, params, token=nil)
|
def initialize(project, params, token=nil)
|
||||||
@project = project
|
@project = project
|
||||||
@branch = params[:branch]
|
@branch = params[:branch]
|
||||||
@pass_year = params[:pass_year]
|
@pass_year = params[:pass_year] || 3
|
||||||
@page = params[:page] || 1
|
@page = params[:page] || 1
|
||||||
@limit = params[:limit] || 15
|
@limit = params[:limit] || 15
|
||||||
@owner = project&.owner.login
|
@owner = project&.owner.login
|
||||||
|
@ -23,10 +23,10 @@ class Api::V1::Projects::Contributors::StatService < ApplicationService
|
||||||
private
|
private
|
||||||
def request_params
|
def request_params
|
||||||
param = {
|
param = {
|
||||||
access_token: token
|
access_token: token, page: page, limit: limit
|
||||||
}
|
}
|
||||||
param.merge!(branch: branch) if branch.present?
|
param.merge!(branch: branch) if branch.present?
|
||||||
param.merge!(pass_year: pass_year) if pass_year.present?
|
param.merge!(pass_year: @pass_year)
|
||||||
|
|
||||||
param
|
param
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Gitea::Commit::DiffService < Gitea::ClientService
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
response = get(url, params)
|
response = get(url, params, true)
|
||||||
render_result(response)
|
render_result(response)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,20 +8,17 @@ class Gitea::User::GetTokenService < Gitea::ClientService
|
||||||
|
|
||||||
def call
|
def call
|
||||||
params = {}
|
params = {}
|
||||||
url = "/users/#{username}".freeze
|
url = "/users/#{username}/tokens".freeze
|
||||||
params = params.merge(data: request_params)
|
params = params.merge(sudo: username, page: 1, limit: 200, token: token)
|
||||||
get(url, params)
|
response = get(url, params)
|
||||||
|
render_status(response)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# def token_params
|
def token
|
||||||
# {
|
{
|
||||||
# username: username,
|
username: GiteaService.gitea_config[:access_key_id],
|
||||||
# password: password
|
password: GiteaService.gitea_config[:access_key_secret]
|
||||||
# }
|
}
|
||||||
# end
|
|
||||||
|
|
||||||
def request_params
|
|
||||||
{ username: username }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Projects::ForkService < ApplicationService
|
||||||
:license_id, :ignore_id, {repository: [:identifier, :hidden]}]
|
:license_id, :ignore_id, {repository: [:identifier, :hidden]}]
|
||||||
|
|
||||||
result = Gitea::Repository::ForkService.new(@project.owner, @target_owner, @project.identifier, @organization, @new_identifier).call
|
result = Gitea::Repository::ForkService.new(@project.owner, @target_owner, @project.identifier, @organization, @new_identifier).call
|
||||||
|
return false if result['clone_url'].nil?
|
||||||
clone_project.owner = @target_owner
|
clone_project.owner = @target_owner
|
||||||
clone_project.forked_from_project_id = @project.id
|
clone_project.forked_from_project_id = @project.id
|
||||||
clone_project.gpid = result['id']
|
clone_project.gpid = result['id']
|
||||||
|
|
|
@ -180,7 +180,7 @@ class PullRequests::CreateService < ApplicationService
|
||||||
end
|
end
|
||||||
|
|
||||||
def compare_head_base!
|
def compare_head_base!
|
||||||
head = pull_request.is_original && @params[:merge_user_login] ? "#{@params[:merge_user_login]}/#{@project.identifier}:#{@params[:head]}" : @params[:head]
|
head = pull_request.is_original && @params[:merge_user_login] ? "#{@params[:merge_user_login]}/#{@params[:merge_project_identifier]}:#{@params[:head]}" : @params[:head]
|
||||||
compare_result = Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, Addressable::URI.escape(@params[:base]), Addressable::URI.escape(head), @current_user.gitea_token)
|
compare_result = Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, Addressable::URI.escape(@params[:base]), Addressable::URI.escape(head), @current_user.gitea_token)
|
||||||
raise '分支内容相同,无需创建合并请求' if compare_result["Commits"].blank? && compare_result["Diff"].blank?
|
raise '分支内容相同,无需创建合并请求' if compare_result["Commits"].blank? && compare_result["Diff"].blank?
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
json.user do
|
||||||
|
json.id @user.id
|
||||||
|
json.type @user.type
|
||||||
|
json.name @user.real_name
|
||||||
|
json.login @user.login
|
||||||
|
json.image_url url_to_avatar(@user)
|
||||||
|
json.forked Project.exists?(user_id: @user.id, forked_from_project_id: @project.id)
|
||||||
|
end
|
||||||
|
json.organizations @organizations do |organization|
|
||||||
|
json.forked Project.exists?(user_id: organization.id, forked_from_project_id: @project.id)
|
||||||
|
json.id organization.id
|
||||||
|
json.name organization.login
|
||||||
|
json.nickname organization.nickname.blank? ? organization.name : organization.nickname
|
||||||
|
json.avatar_url url_to_avatar(organization)
|
||||||
|
json.created_at organization.created_on.strftime("%Y-%m-%d")
|
||||||
|
end
|
|
@ -3,7 +3,7 @@ json.identifier project.identifier
|
||||||
json.name project.name
|
json.name project.name
|
||||||
json.description project.description
|
json.description project.description
|
||||||
json.is_public project.is_public
|
json.is_public project.is_public
|
||||||
json.pr_need @project.owner.class == User ? false : @project.owner&.cla.try(:pr_need)
|
json.pr_need project.owner.class == User ? false : project.owner&.cla.try(:pr_need)
|
||||||
json.owner do
|
json.owner do
|
||||||
json.partial! "/users/user_simple", locals: {user: project.owner}
|
json.partial! "/users/user_simple", locals: {user: project.owner}
|
||||||
end
|
end
|
|
@ -25,11 +25,17 @@ if popular_project.blank?
|
||||||
json.project nil
|
json.project nil
|
||||||
else
|
else
|
||||||
popular_project_common = $redis_cache.hgetall("v2-project-common:#{popular_project[0]}")
|
popular_project_common = $redis_cache.hgetall("v2-project-common:#{popular_project[0]}")
|
||||||
json.project do
|
if popular_project_common["owner_id"].to_s == item[0].to_s
|
||||||
json.id popular_project[0]
|
json.project do
|
||||||
json.name popular_project_common["name"]
|
json.id popular_project[0]
|
||||||
json.identifier popular_project_common["identifier"]
|
json.name popular_project_common["name"]
|
||||||
json.description popular_project_common["description"]
|
json.identifier popular_project_common["identifier"]
|
||||||
|
json.description popular_project_common["description"]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# owner changed remove rank
|
||||||
|
$redis_cache.zrem("v2-user-project-rank:#{item[0]}", popular_project[0])
|
||||||
|
json.project nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -625,7 +625,11 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :hooks
|
resources :hooks
|
||||||
resources :forks, only: [:create]
|
resources :forks, only: [:create] do
|
||||||
|
collection do
|
||||||
|
get :fork_list
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :project_trends, :path => :activity, only: [:index, :create]
|
resources :project_trends, :path => :activity, only: [:index, :create]
|
||||||
resources :issue_tags, :path => :labels, only: [:create, :edit, :update, :destroy, :index]
|
resources :issue_tags, :path => :labels, only: [:create, :edit, :update, :destroy, :index]
|
||||||
resources :version_releases, :path => :releases, only: [:index,:new, :show, :create, :edit, :update, :destroy]
|
resources :version_releases, :path => :releases, only: [:index,:new, :show, :create, :edit, :update, :destroy]
|
||||||
|
|
Loading…
Reference in New Issue