forked from Gitlink/forgeplus
FIX merge
This commit is contained in:
commit
2636923c9b
|
@ -10,7 +10,7 @@ class ApplicationController < ActionController::Base
|
|||
include LoggerHelper
|
||||
include LoginHelper
|
||||
include RegisterHelper
|
||||
|
||||
|
||||
protect_from_forgery prepend: true, unless: -> { request.format.json? }
|
||||
|
||||
before_action :check_sign
|
||||
|
@ -386,7 +386,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def current_user
|
||||
if Rails.env.development?
|
||||
User.current = User.find 36480
|
||||
User.current = User.find 1
|
||||
else
|
||||
User.current
|
||||
end
|
||||
|
@ -750,7 +750,7 @@ class ApplicationController < ActionController::Base
|
|||
if @project and current_user.can_read_project?(@project)
|
||||
logger.info "###########: has project and can read project"
|
||||
@project
|
||||
elsif current_user.is_a?(AnonymousUser)
|
||||
elsif @project && current_user.is_a?(AnonymousUser)
|
||||
logger.info "###########:This is AnonymousUser"
|
||||
@project = nil if !@project.is_public?
|
||||
render_forbidden and return
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
# 文件上传
|
||||
class AttachmentsController < ApplicationController
|
||||
before_action :require_login, :check_auth, except: [:show]
|
||||
before_action :require_login, :check_auth, except: [:show, :preview_attachment]
|
||||
before_action :find_file, only: %i[show destroy]
|
||||
before_action :attachment_candown, only: [:show]
|
||||
skip_before_action :check_sign, only: [:show, :create]
|
||||
|
@ -98,6 +98,26 @@ class AttachmentsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# 附件为视频时,点击播放
|
||||
def preview_attachment
|
||||
attachment = Attachment.find_by(id: params[:id])
|
||||
dir_path = "#{Rails.root}/public/preview"
|
||||
Dir.mkdir(dir_path) unless Dir.exist?(dir_path)
|
||||
if params[:status] == "preview"
|
||||
if system("cp -r #{absolute_path(local_path(attachment))} #{dir_path}/")
|
||||
render json: {status: 1, url: "/preview/#{attachment.disk_filename}"}
|
||||
else
|
||||
normal_status(-1, "出现错误,请稍后重试")
|
||||
end
|
||||
else
|
||||
if system("rm -rf #{dir_path}/#{attachment.disk_filename}")
|
||||
normal_status(1, "操作成功")
|
||||
else
|
||||
normal_status(-1, "出现错误,请稍后重试")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_file
|
||||
@file =
|
||||
|
|
|
@ -183,16 +183,23 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
if @issue.issue_type.to_s == "2" && @issue.status_id == 5 #已关闭的情况下,只能更新标题和内容,附件
|
||||
new_issue_params = {
|
||||
subject: params[:subject],
|
||||
description: params[:description],
|
||||
}
|
||||
if @issue.update_attributes(new_issue_params)
|
||||
normal_status(0, "更新成功")
|
||||
else
|
||||
normal_status(-1, "更新失败")
|
||||
end
|
||||
# if params[:issue_tag_ids].present?
|
||||
# issue_current_tags = @issue&.issue_tags&.select(:id)&.pluck(:id)
|
||||
# new_tag_ids = params[:issue_tag_ids] - issue_current_tags
|
||||
# old_tag_ids = issue_current_tags - params[:issue_tag_ids]
|
||||
# if old_tag_ids.size > 0
|
||||
# @issue.issue_tags_relates.where(issue_tag_id: old_tag_ids).delete_all
|
||||
# end
|
||||
# if new_tag_ids.size > 0
|
||||
# new_tag_ids.each do |tag|
|
||||
# IssueTagsRelate.create(issue_id: @issue.id, issue_tag_id: tag)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
if params[:status_id].to_i == 5
|
||||
@issue.issue_times.update_all(end_time: Time.now)
|
||||
# @issue.update_closed_issues_count_in_project! #已经有after_update方法了,这里就不需要了
|
||||
elsif @issue.issue_type.to_s == "2" && params[:status_id].to_i == 5 && @issue.author_id != current_user.try(:id)
|
||||
normal_status(-1, "不允许修改为关闭状态")
|
||||
else
|
||||
|
@ -205,12 +212,12 @@ class IssuesController < ApplicationController
|
|||
if @issue.issue_type.to_s == "2" && last_status_id != 5
|
||||
if @issue.assigned_to_id.present? && last_status_id == 3 #只有当用户完成100%时,才给token
|
||||
post_to_chain("add", @issue.token, @issue.get_assign_user.try(:login))
|
||||
else
|
||||
else
|
||||
post_to_chain("add", @issue.token, @issue.user.try(:login))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if @issue.issue_type.to_s == "2" && @issue.status_id != 5 && @issue.saved_change_to_attribute("token")
|
||||
#表示修改token值
|
||||
change_token = last_token - @issue.token
|
||||
|
@ -483,7 +490,7 @@ class IssuesController < ApplicationController
|
|||
PostChainJob.perform_later(change_params)
|
||||
end
|
||||
|
||||
def check_token_enough
|
||||
def check_token_enough
|
||||
if params[:issue_type].to_s == "2" && (@issue.blank? || (@issue.present? && @issue.author_id == current_user.try(:id)))
|
||||
return normal_status(-1, "悬赏的奖金必须大于0") if params[:token].to_i == 0
|
||||
query_params = {
|
||||
|
@ -494,7 +501,7 @@ class IssuesController < ApplicationController
|
|||
}
|
||||
}
|
||||
response = Gitea::Chain::ChainGetService.new(query_params).call
|
||||
return normal_status(-1, "获取token失败,请稍后重试") if response.status != 200
|
||||
return normal_status(-1, "获取token失败,请稍后重试") if response.status != 200
|
||||
return normal_status(-1, "您的token值不足") if JSON.parse(response.body)["balance"].to_i < params[:token].to_i
|
||||
end
|
||||
end
|
||||
|
|
|
@ -95,7 +95,7 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def fork_users
|
||||
fork_users = @project.fork_users.includes(:user, :project).order("fork_users.created_at desc").distinct
|
||||
fork_users = @project.fork_users.includes(:user, :project, :fork_project).order("fork_users.created_at desc").distinct
|
||||
@forks_count = fork_users.size
|
||||
@fork_users = paginate(fork_users)
|
||||
end
|
||||
|
|
|
@ -139,7 +139,7 @@ class VersionReleasesController < ApplicationController
|
|||
body: params[:body],
|
||||
draft: params[:draft] || false,
|
||||
name: params[:name],
|
||||
prerelease: params[:prerelease],
|
||||
prerelease: params[:prerelease] || false,
|
||||
tag_name: params[:tag_name],
|
||||
target_commitish: params[:target_commitish] || "master" #分支
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ module Gitea
|
|||
attr_reader :error, :result
|
||||
|
||||
def initialize(token, owner, params)
|
||||
@owner = owner
|
||||
@token = token
|
||||
@owner = owner
|
||||
@params = params
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class ForkUser < ApplicationRecord
|
||||
belongs_to :project
|
||||
belongs_to :user
|
||||
belongs_to :fork_project, class_name: 'ForkUser', foreign_key: :fork_project_id
|
||||
belongs_to :fork_project, class_name: 'Project', foreign_key: :fork_project_id
|
||||
|
||||
end
|
||||
|
|
|
@ -20,7 +20,6 @@ class Gitea::ClientService < ApplicationService
|
|||
# }
|
||||
def post(url, params={})
|
||||
puts "[gitea] request params: #{params}"
|
||||
request_url = [api_url, url].join('').freeze
|
||||
auth_token = authen_params(params[:token])
|
||||
response = conn(auth_token).post do |req|
|
||||
req.url "#{request_url}"
|
||||
|
@ -32,7 +31,7 @@ class Gitea::ClientService < ApplicationService
|
|||
def get(url, params={})
|
||||
auth_token = authen_params(params[:token])
|
||||
conn(auth_token).get do |req|
|
||||
req.url full_url(url)
|
||||
req.url full_url(url, 'get')
|
||||
params.except(:token).each_pair do |key, value|
|
||||
req.params["#{key}"] = value
|
||||
end
|
||||
|
@ -114,14 +113,15 @@ class Gitea::ClientService < ApplicationService
|
|||
[domain, base_url].join('')
|
||||
end
|
||||
|
||||
def full_url(api_rest)
|
||||
[api_url, api_rest].join('').freeze
|
||||
def full_url(api_rest, action='post')
|
||||
url = [api_url, api_rest].join('').freeze
|
||||
url = action === 'get' ? url : URI.escape(url)
|
||||
puts "[gitea] request url: #{url}"
|
||||
return url
|
||||
end
|
||||
|
||||
def render_status(response)
|
||||
Rails.logger.info("###############____response__#{response}")
|
||||
Rails.logger.info("###############____response_status_#{response.status}")
|
||||
Rails.logger.info("###############____response_body_#{response.body}")
|
||||
puts "[gitea] response status: #{response.status}"
|
||||
mark = "[gitea] "
|
||||
case response.status
|
||||
when 201, 200, 202
|
||||
|
|
|
@ -2,10 +2,9 @@ json.count @forks_count
|
|||
json.users do
|
||||
json.array! @fork_users.each do |f|
|
||||
user = f.user
|
||||
fork_project = Project.select(:id,:name, :identifier).find_by(id: f.fork_project_id)
|
||||
json.id f.fork_project_id
|
||||
json.identifier fork_project.identifier
|
||||
json.name "#{user.try(:show_real_name)}/#{fork_project.try(:name)}"
|
||||
json.id f.fork_project.id
|
||||
json.identifier f.fork_project.identifier
|
||||
json.name "#{user.try(:show_real_name)}/#{f.fork_project.try(:name)}"
|
||||
json.login user.try(:login)
|
||||
json.image_url url_to_avatar(user)
|
||||
json.format_time f.created_at.strftime("%Y-%m-%d")
|
||||
|
|
|
@ -48,6 +48,9 @@ Rails.application.routes.draw do
|
|||
resources :compose_projects, only: [:create, :destroy]
|
||||
end
|
||||
resources :attachments do
|
||||
member do
|
||||
post :preview_attachment
|
||||
end
|
||||
collection do
|
||||
delete :destroy_files
|
||||
end
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
class ResetVersionsCount < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
execute "ALTER TABLE licenses MODIFY COLUMN id INT AUTO_INCREMENT;"
|
||||
versions = Version.includes(:issues).select(:id, :closed_issues_count, :percent,:issues_count)
|
||||
versions.each do |v|
|
||||
Version.reset_counters v.id, :issues
|
||||
closed_issues = Issue.select(:id, :fixed_version_id, :status_id).where(fixed_version_id: v.id, status_id: 5).size
|
||||
unless v.closed_issues_count.to_i == closed_issues
|
||||
percent = v.issues_count.to_i <=0 ? 0.0 : (closed_issues.to_f / v.issues_count.to_i)
|
||||
v.closed_issues_count = closed_issues
|
||||
v.percent = percent
|
||||
v.save
|
||||
end
|
||||
puts v.id
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue