Browse Source

Merge branch 'chenjing' of https://gitlink.org.cn/KingChan/forgeplus into chenjing

pull/338/head
chenjing 3 years ago
parent
commit
5490dd8ee4
23 changed files with 140518 additions and 50 deletions
  1. +1
    -1
      app/controllers/application_controller.rb
  2. +4
    -3
      app/controllers/attachments_controller.rb
  3. +37
    -6
      app/controllers/forks_controller.rb
  4. +5
    -1
      app/controllers/repositories_controller.rb
  5. +2
    -0
      app/controllers/users_controller.rb
  6. +8
    -8
      app/helpers/repositories_helper.rb
  7. +3
    -0
      app/interactors/gitea/update_file_interactor.rb
  8. +2
    -0
      app/queries/admins/organization_query.rb
  9. +3
    -3
      app/services/api/v1/projects/contributors/stat_service.rb
  10. +1
    -1
      app/services/gitea/commit/diff_service.rb
  11. +9
    -12
      app/services/gitea/user/get_token_service.rb
  12. +1
    -1
      app/services/projects/fork_service.rb
  13. +2
    -6
      app/views/admins/feedbacks/_list.html.erb
  14. +4
    -0
      app/views/admins/organizations/index.html.erb
  15. +16
    -0
      app/views/forks/fork_list.json.jbuilder
  16. +1
    -1
      app/views/projects/_detail.json.jbuilder
  17. +11
    -5
      app/views/user_rank/_detail.json.jbuilder
  18. +5
    -1
      config/routes.rb
  19. +1
    -1
      public/assets/.sprockets-manifest-fcdcb36eff7e19f6646153ed2fcfd2b4.json
  20. +42
    -0
      public/assets/admin-a7edfa013f5e822c43ac1a1f813c1929ff7aa9e12cd1313f9e1b7292fa406470.css
  21. BIN
      public/assets/admin-a7edfa013f5e822c43ac1a1f813c1929ff7aa9e12cd1313f9e1b7292fa406470.css.gz
  22. +140360
    -0
      public/assets/admin-ac55ef6d0ab68e7b7fc33b36616fb687dab371f3c6c8414daffe341ab264ab2c.js
  23. BIN
      public/assets/admin-ac55ef6d0ab68e7b7fc33b36616fb687dab371f3c6c8414daffe341ab264ab2c.js.gz

+ 1
- 1
app/controllers/application_controller.rb View File

@@ -1103,7 +1103,7 @@ class ApplicationController < ActionController::Base
"author_time": commit['commit']['author']['date'],
"committer_time": commit['commit']['committer']['date'],
"content": commit['commit']['message'],
"commit_diff": commit_diff['Files'].to_s
"commit_diff": commit_diff.present? ? commit_diff['Files'].to_s : ""
}.to_json
resp_body = Blockchain::InvokeBlockchainApi.call(params)
if resp_body['status'] == 7


+ 4
- 3
app/controllers/attachments_controller.rb View File

@@ -38,12 +38,13 @@ class AttachmentsController < ApplicationController
url = ("/repos"+url.split(base_url + "/api")[1])
filepath, ref = url.split("/")[-1].split("?")
url.gsub!(url.split("/")[-1], '')
puts filepath
request_url = [domain, api_url, url, CGI.escape(filepath), "?ref=#{CGI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join
Rails.logger.info("url===#{url}")
request_url = [domain, api_url, URI.encode(url), CGI.escape(filepath), "?ref=#{CGI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join
Rails.logger.info("request_url===#{request_url}")
response = Faraday.get(request_url)
filename = filepath
else
response = Faraday.get(url)
response = Faraday.get(URI.encode(url))
filename = params[:download_url].to_s.split("/").pop()
end
send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment')


+ 37
- 6
app/controllers/forks_controller.rb View File

@@ -2,18 +2,44 @@ class ForksController < ApplicationController
before_action :require_login
before_action :require_profile_completed, only: [:create]
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
@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

private
def authenticate_project!
if current_user&.id == @project.user_id && (params[:new_identifier].blank? || params[:new_identifier] == @project.identifier)
render_result(-1, "自己不能fork自己的项目")
elsif Project.exists?(user_id: current_user.id, identifier: (params[:new_identifier] || @project.identifier))
render_result(0, "fork失败,你已拥有了这个项目")
if params[:organization].present?
return render_forbidden('参数错误,当organization存在时不允许fork重命名') if params[:new_identifier].present? || params[:new_name].present?
@organization = Organization.find_by(login:params[:organization])
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
# return if current_user != @project.owner
# render_result(-1, "自己不能fork自己的项目")
@@ -24,4 +50,9 @@ class ForksController < ApplicationController
return if @project.member?(current_user) || current_user.admin?
render_forbidden('你没有权限操作')
end

def gitea_check_exit(user)
data = Gitea::Repository::GetService.new(user, params[:new_identifier]|| @project.identifier).call
data.present?
end
end

+ 5
- 1
app/controllers/repositories_controller.rb View File

@@ -176,6 +176,9 @@ class RepositoriesController < ApplicationController
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]})
@total_count = result[:total_count]
@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
rescue
@contributors = []
@@ -263,8 +266,9 @@ class RepositoriesController < ApplicationController
end
@path = GiteaService.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/"
@readme = result[:status] === :success ? result[:body] : nil
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path)
# replace_content 前置,防止被content改写
@readme['replace_content'] = readme_decode64_content(@readme, @owner, @repository, params[:ref], @path)
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path)
render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content")
rescue
render json: nil


+ 2
- 0
app/controllers/users_controller.rb View File

@@ -212,6 +212,8 @@ class UsersController < ApplicationController
def update
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)
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?
@user.attributes = user_params.except(:image)
unless @user.save


+ 8
- 8
app/helpers/repositories_helper.rb View File

@@ -55,7 +55,7 @@ module RepositoriesHelper
def readme_render_decode64_content(str, owner, repo, ref, path)
return nil if str.blank?
begin
content = Base64.decode64(str).force_encoding('UTF-8')
content = Base64.decode64(content).force_encoding('UTF-8').valid_encoding? ? Base64.decode64(str).force_encoding('UTF-8') : Base64.decode64(str).force_encoding("GBK").encode("UTF-8")

c_regex = /\!\[.*?\]\((.*?)\)/
src_regex = /src=\"(.*?)\"/
@@ -115,7 +115,7 @@ module RepositoriesHelper
def new_readme_render_decode64_content(str, owner, repo, ref, readme_path, readme_name)
file_path = readme_path.include?('/') ? readme_path.gsub("/#{readme_name}", '') : readme_path.gsub("#{readme_name}", '')
return nil if str.blank?
content = Base64.decode64(str).force_encoding('UTF-8')
content = Base64.decode64(str).force_encoding('UTF-8').valid_encoding? ? Base64.decode64(str).force_encoding('UTF-8') : Base64.decode64(str).force_encoding("GBK").encode("UTF-8")
# s_regex = /\s\!\[.*?\]\((.*?)\)\s/
s_regex_c = /`{1,2}[^`](.*?)`{1,2}/
s_regex = /```([\s\S]*?)```[\s]?/
@@ -178,9 +178,10 @@ module RepositoriesHelper
after_ss_c_souces.each_with_index do |s, index|
content = content.gsub("#{s[0]}","#{total_sources[:ss_c][index][0]}")
end
return content
rescue
rescue Exception => e
Rails.logger.error("===================#{readme_path}:#{readme_name}:error:#{e}")
# e.backtrace.each { |msg| Rails.logger.error(msg) }
return str
end

@@ -196,8 +197,7 @@ module RepositoriesHelper

def readme_decode64_content(entry, owner, repo, ref, path=nil)
Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}")
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
# Rails.logger.info("content===#{content}")
content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
# readme_render_decode64_content(content, owner, repo, ref)
new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name'])
end
@@ -205,9 +205,9 @@ module RepositoriesHelper
def decode64_content(entry, owner, repo, ref, path=nil)
if is_readme?(entry['type'], entry['name'])
Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}")
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
# Rails.logger.info("content===#{content}")
# readme_render_decode64_content(content, owner, repo, ref)
return Base64.decode64(content).force_encoding("GBK").encode("UTF-8") unless Base64.decode64(content).force_encoding('UTF-8').valid_encoding?
return Base64.decode64(content).force_encoding('UTF-8')
else
file_type = File.extname(entry['name'].to_s)[1..-1]


+ 3
- 0
app/interactors/gitea/update_file_interactor.rb View File

@@ -42,6 +42,9 @@ module Gitea
def render_result(response)
if response.status == 200
@result = JSON.parse(response.body)
else
Rails.logger.info("Gitea::Repository::Entries::UpdateService error======#{response.body}")
@error = "更新失败"
end
end



+ 2
- 0
app/queries/admins/organization_query.rb View File

@@ -9,6 +9,8 @@ class Admins::OrganizationQuery < ApplicationQuery

def call
orgs = Organization.all

orgs = orgs.where(enabling_cla: params[:enabling_cla]) if params[:enabling_cla].present?
# 关键字检索
keyword = params[:keyword].to_s.strip.presence
if keyword


+ 3
- 3
app/services/api/v1/projects/contributors/stat_service.rb View File

@@ -6,7 +6,7 @@ class Api::V1::Projects::Contributors::StatService < ApplicationService
def initialize(project, params, token=nil)
@project = project
@branch = params[:branch]
@pass_year = params[:pass_year]
@pass_year = params[:pass_year] || 3
@page = params[:page] || 1
@limit = params[:limit] || 15
@owner = project&.owner.login
@@ -23,10 +23,10 @@ class Api::V1::Projects::Contributors::StatService < ApplicationService
private
def request_params
param = {
access_token: token
access_token: token, page: page, limit: limit
}
param.merge!(branch: branch) if branch.present?
param.merge!(pass_year: pass_year) if pass_year.present?
param.merge!(pass_year: @pass_year)

param
end


+ 1
- 1
app/services/gitea/commit/diff_service.rb View File

@@ -16,7 +16,7 @@ class Gitea::Commit::DiffService < Gitea::ClientService
end

def call
response = get(url, params)
response = get(url, params, true)
render_result(response)
end



+ 9
- 12
app/services/gitea/user/get_token_service.rb View File

@@ -8,20 +8,17 @@ class Gitea::User::GetTokenService < Gitea::ClientService

def call
params = {}
url = "/users/#{username}".freeze
params = params.merge(data: request_params)
get(url, params)
url = "/users/#{username}/tokens".freeze
params = params.merge(sudo: username, page: 1, limit: 200, token: token)
response = get(url, params)
render_status(response)
end

private
# def token_params
# {
# username: username,
# password: password
# }
# end

def request_params
{ username: username }
def token
{
username: GiteaService.gitea_config[:access_key_id],
password: GiteaService.gitea_config[:access_key_secret]
}
end
end

+ 1
- 1
app/services/projects/fork_service.rb View File

@@ -18,7 +18,7 @@ class Projects::ForkService < ApplicationService
:license_id, :ignore_id, {repository: [:identifier, :hidden]}]

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.forked_from_project_id = @project.id
clone_project.gpid = result['id']


+ 2
- 6
app/views/admins/feedbacks/_list.html.erb View File

@@ -17,12 +17,8 @@
<td><%= feedback&.user&.login%></td>
<td><%= feedback&.user&.mail%></td>
<td><%= feedback.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td>
<span class="d-inline-block" tabindex="0" data-toggle="tooltip" data-placement="left" title="<%= feedback.content%>">
<a href="javascript:">
<%= feedback.content.truncate(20) %>
</a>
</span>
<td style="word-wrap: break-word;">
<%= feedback.content %>
</td>
<td class="action-container">
<%= link_to "发送邮件", new_history_admins_feedback_path(feedback), remote: true, class: "action" %>


+ 4
- 0
app/views/admins/organizations/index.html.erb View File

@@ -5,6 +5,10 @@
<%= form_tag(admins_organizations_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>

<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: 'login/昵称') %>
<label for="user_enabling_cla">
是否签署CLA
</label>
<%= check_box_tag("enabling_cla", true, false, id: "user_enabling_cla", style: 'margin-left: 2px;') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<% end %>


+ 16
- 0
app/views/forks/fork_list.json.jbuilder View File

@@ -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

+ 1
- 1
app/views/projects/_detail.json.jbuilder View File

@@ -3,7 +3,7 @@ json.identifier project.identifier
json.name project.name
json.description project.description
json.is_public project.is_public
json.pr_need @project.owner&.cla.try(:pr_need)
json.pr_need project.owner.class == User ? false : project.owner&.cla.try(:pr_need)
json.owner do
json.partial! "/users/user_simple", locals: {user: project.owner}
end

+ 11
- 5
app/views/user_rank/_detail.json.jbuilder View File

@@ -25,11 +25,17 @@ if popular_project.blank?
json.project nil
else
popular_project_common = $redis_cache.hgetall("v2-project-common:#{popular_project[0]}")
json.project do
json.id popular_project[0]
json.name popular_project_common["name"]
json.identifier popular_project_common["identifier"]
json.description popular_project_common["description"]
if popular_project_common["owner_id"].to_s == item[0].to_s
json.project do
json.id popular_project[0]
json.name popular_project_common["name"]
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



+ 5
- 1
config/routes.rb View File

@@ -625,7 +625,11 @@ Rails.application.routes.draw do
end

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 :issue_tags, :path => :labels, only: [:create, :edit, :update, :destroy, :index]
resources :version_releases, :path => :releases, only: [:index,:new, :show, :create, :edit, :update, :destroy]


+ 1
- 1
public/assets/.sprockets-manifest-fcdcb36eff7e19f6646153ed2fcfd2b4.json
File diff suppressed because it is too large
View File


+ 42
- 0
public/assets/admin-a7edfa013f5e822c43ac1a1f813c1929ff7aa9e12cd1313f9e1b7292fa406470.css
File diff suppressed because it is too large
View File


BIN
public/assets/admin-a7edfa013f5e822c43ac1a1f813c1929ff7aa9e12cd1313f9e1b7292fa406470.css.gz View File


+ 140360
- 0
public/assets/admin-ac55ef6d0ab68e7b7fc33b36616fb687dab371f3c6c8414daffe341ab264ab2c.js
File diff suppressed because it is too large
View File


BIN
public/assets/admin-ac55ef6d0ab68e7b7fc33b36616fb687dab371f3c6c8414daffe341ab264ab2c.js.gz View File


Loading…
Cancel
Save