Merge pull request '一些功能修改以及bug修复' (#263) from yystopf/forgeplus:hh_hotfix into develop

This commit is contained in:
xxq250 2021-11-26 09:39:58 +08:00
commit 72553dec57
24 changed files with 108 additions and 36 deletions

View File

@ -43,7 +43,7 @@ class CompareController < ApplicationController
def load_compare_params
@base = Addressable::URI.unescape(params[:base])
@head = params[:head].include?('json') ? params[:head]&.split('.json')[0] : params[:head]
@head = params[:head].include?('.json') ? params[:head][0..-6] : params[:head]
end

View File

@ -13,7 +13,7 @@ class ForksController < ApplicationController
if current_user&.id == @project.user_id
render_result(-1, "自己不能fork自己的项目")
elsif Project.exists?(user_id: current_user.id, identifier: @project.identifier)
render_result(-1, "fork失败你已拥有了这个项目")
render_result(0, "fork失败你已拥有了这个项目")
end
# return if current_user != @project.owner
# render_result(-1, "自己不能fork自己的项目")

View File

@ -2,7 +2,7 @@ class IssueTagsController < ApplicationController
before_action :require_login, except: [:index]
before_action :load_repository
before_action :set_user
before_action :check_issue_permission, except: :index
before_action :check_issue_tags_permission
before_action :set_issue_tag, only: [:edit, :update, :destroy]
@ -122,9 +122,9 @@ class IssueTagsController < ApplicationController
@user = @project.owner
end
def check_issue_permission
unless @project.member?(current_user) || current_user.admin?
normal_status(-1, "您没有权限")
def check_issue_tags_permission
unless @project.manager?(current_user) || current_user.admin?
return render_forbidden('你不是管理员,没有权限操作')
end
end

View File

@ -3,7 +3,7 @@ class MembersController < ApplicationController
before_action :load_project
before_action :find_user_with_id, only: %i[create remove change_role]
before_action :check_user_profile_completed, only: [:create]
before_action :operate!, except: %i[index]
before_action :operate!
before_action :check_member_exists!, only: %i[create]
before_action :check_member_not_exists!, only: %i[remove change_role]

View File

@ -46,7 +46,7 @@ class Organizations::OrganizationsController < Organizations::BaseController
@organization.save!
sync_organization_extension!
Gitea::Organization::UpdateService.call(@organization.gitea_token, login, @organization.reload)
Gitea::Organization::UpdateService.call(current_user.gitea_token, login, @organization.reload)
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
end
rescue Exception => e
@ -57,10 +57,14 @@ class Organizations::OrganizationsController < Organizations::BaseController
def destroy
tip_exception("密码不正确") unless current_user.check_password?(password)
ActiveRecord::Base.transaction do
Gitea::Organization::DeleteService.call(@organization.gitea_token, @organization.login)
@organization.destroy!
gitea_status, gitea_message = Gitea::Organization::DeleteService.call(current_user.gitea_token, @organization.login)
if gitea_status == 204
@organization.destroy!
render_ok
else
tip_exception("当组织内含有仓库时,无法删除此组织")
end
end
render_ok
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)

View File

@ -56,6 +56,7 @@ class PullRequestsController < ApplicationController
end
def create
return render_forbidden("你没有权限操作.") unless @project.operator?(current_user)
ActiveRecord::Base.transaction do
@pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params)
if @gitea_pull_request[:status] == :success
@ -78,6 +79,7 @@ class PullRequestsController < ApplicationController
end
def update
return render_forbidden("你没有权限操作.") unless @project.operator?(current_user)
if params[:title].nil?
normal_status(-1, "名称不能为空")
elsif params[:issue_tag_ids].nil?
@ -197,7 +199,7 @@ class PullRequestsController < ApplicationController
def check_can_merge
target_head = params[:head] #源分支
target_base = params[:base] #目标分支
is_original = params[:is_original]
is_original = params[:is_original] || false
if target_head.blank? || target_base.blank?
normal_status(-2, "请选择分支")
elsif target_head === target_base && !is_original
@ -228,11 +230,11 @@ class PullRequestsController < ApplicationController
private
def load_pull_request
@pull_request = PullRequest.find params[:id]
@pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || PullRequest.find_by_id(params[:id])
end
def find_pull_request
@pull_request = PullRequest.find_by_id(params[:id])
@pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || PullRequest.find_by_id(params[:id])
@issue = @pull_request&.issue
if @pull_request.blank?
normal_status(-1, "合并请求不存在")

View File

@ -32,7 +32,8 @@ class UsersController < ApplicationController
@waiting_applied_messages = @user.applied_messages.waiting
@common_applied_transfer_projects = AppliedTransferProject.where(owner_id: @user.id).common + AppliedTransferProject.where(owner_id: Organization.joins(team_users: :team).where(team_users: {user_id: @user.id}, teams: {authorize: %w(admin owner)} )).common
@common_applied_projects = AppliedProject.where(project_id: @user.full_admin_projects).common
@undo_events = @waiting_applied_messages.size + @common_applied_transfer_projects.size + @common_applied_projects.size
#@undo_events = @waiting_applied_messages.size + @common_applied_transfer_projects.size + @common_applied_projects.size
@undo_events = @common_applied_transfer_projects.size + @common_applied_projects.size
else
@waiting_applied_messages = AppliedMessage.none
@common_applied_transfer_projects = AppliedTransferProject.none

View File

@ -8,4 +8,11 @@ class Organizations::CreateForm < BaseForm
validates :description, length: { maximum: 200 }
validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
validate do
check_name(name) unless name.blank?
end
def check_name(name)
raise "组织账号已被使用." if Owner.where(login: name.strip).exists?
end
end

View File

@ -131,7 +131,7 @@ class Project < ApplicationRecord
after_create :incre_user_statistic, :incre_platform_statistic
after_save :check_project_members, :reset_cache_data
before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned
before_destroy :decre_project_common
before_destroy :decre_project_common, :decre_forked_from_project_count
after_destroy :decre_user_statistic, :decre_platform_statistic
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :description, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
@ -173,6 +173,14 @@ class Project < ApplicationRecord
CacheAsyncClearJob.perform_later('project_common_service', self.id)
end
def decre_forked_from_project_count
forked_project = self.forked_from_project
if forked_project.present?
forked_project.decrement(:forked_count, 1)
forked_project.save
end
end
def incre_user_statistic
CacheAsyncSetJob.perform_later("user_statistic_service", {project_count: 1, project_language_count_key: self.project_language&.name, project_language_count: 1}, self.user_id)
end

View File

@ -144,6 +144,8 @@ class Gitea::ClientService < ApplicationService
{status: 403, message: '你没有权限操作!'}
when 404
{status: 404, message: '你访问的链接不存在!'}
when 500
{status: 500, message: ''}
else
if response&.body.blank?
message = "请求失败"

View File

@ -94,7 +94,7 @@ class PullRequests::CreateService < ApplicationService
user: @current_user,
issue: pull_issue,
fork_project_id: @params[:fork_project_id],
is_original: @params[:is_original],
is_original: is_original,
files_count: @params[:files_count] || 0,
commits_count: @params[:commits_count] || 0
})
@ -145,7 +145,13 @@ class PullRequests::CreateService < ApplicationService
raise "title参数不能为空" if @params[:title].blank?
raise "head参数不能为空" if @params[:head].blank?
raise "base参数不能为空" if @params[:base].blank?
raise "分支内容相同,无需创建合并请求" if @params[:head] === @params[:base] && !is_original
raise "合并请求已存在" if @project&.pull_requests.where(head: @params[:head], base: @params[:base], status: 0, is_original: is_original, fork_project_id: @params[:fork_project_id]).present?
raise @pull_issue.errors.full_messages.join(", ") unless pull_issue.valid?
raise @pull_request.errors.full_messages.join(", ") unless pull_request.valid?
end
def is_original
@params[:is_original] || false
end
end

View File

@ -1,13 +1,17 @@
project = object.project
json.project do
json.id project.id
json.identifier project.identifier
json.name project.name
json.description project.description
json.is_public project.is_public
json.owner do
json.partial! "/users/user_simple", locals: {user: project.owner}
if project.present?
json.project do
json.id project.id
json.identifier project.identifier
json.name project.name
json.description project.description
json.is_public project.is_public
json.owner do
json.partial! "/users/user_simple", locals: {user: project.owner}
end
end
else
json.project nil
end
json.user do
json.partial! "/users/user_simple", locals: {user: object.user}

View File

@ -14,6 +14,7 @@ json.issues do
json.array! @issues.to_a do |issue|
pr = issue.pull_request
json.pull_request_id pr.id
json.pull_request_number pr.gitea_number
json.pull_request_status pr.status
json.pull_request_head pr.head
json.pull_request_base pr.base

View File

@ -16,7 +16,7 @@ zh-CN:
'agreed': '已同意'
trend:
Issue: 易修(Issue)
PullRequest: 合并请求
PullRequest: 合并请求(PR)
VersionRelease: 版本发布
create: 创建了
journal: 回复了

View File

@ -12,12 +12,27 @@
body {
font-family: "微软雅黑","宋体";
background: #fff;
margin: 0px;
padding: 0px;
}
h1 {
font-size: 1.5em;
}
p {
font-size: 0.8em;
img{
vertical-align: middle;
border-style: none;
}
a{
text-decoration: none;
}
.font-16{
font-size: 16px !important;
}
.mt56{
margin-top: 56px;
}
.color-blue{
color:#466AFF !important;
}
.h_content{
text-align: center;
@ -33,6 +48,23 @@
align-items: center;
display: -webkit-flex;
}
.edu-txt-center {
text-align: center !important;
}
.newTable{
padding-top: 120px;
background-color: #F0F5FF;
position: relative;
height: 100vh;
text-align: center;
box-sizing: border-box;
}
.newMargin{
position: absolute;
left: 0;
bottom: 0;
width: 100%;
}
</style>
<script type="text/javascript">
$(function(){
@ -49,14 +81,19 @@
<p>An error occurred on the page you were trying to access.<br />
If you continue to experience problems please contact your Trustie administrator for assistance.</p>
<p>If you are the Trustie administrator, check your log files for details about the error.</p> -->
<div class="verticalCenter">
<div class="edu-txt-center">
<img src="/images/warn/pic_500.jpg" >
<p class="font-18 mt40">您可以稍后尝试&nbsp;
您可以稍后尝试&nbsp;<a href="javascript:history.back()" class="color-blue">返回上页</a>,或者&nbsp;
<a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=2f2043d88c1bd61d182b98bf1e061c6185e23055bec832c07d8148fe11c5a6cd" class="color-blue">QQ反馈>></a>
</p>
</div>
<div class="newTable clearfix">
<img src="images/warn/pic_500.jpg">
<div class="font-16 mt56" style="text-align: center;">
<p>服务器异常,请稍后重试</p>
您可尝试<a href="javascript:location.reload();" class="color-blue">刷新页面</a><a href="/explore"
class="color-blue">返回首页</a>,也可以通过
<a target="_blank"
href="https://qm.qq.com/cgi-bin/qm/qr?k=YVGUhY7uK8ovpyd7tG_lHe2qGZ63LOij&jump_from=webapi"
class="color-blue">QQ</a>向我们反馈
</div>
<div class="newMargin">
<img src="images/warn/pic_bg.png" width="100%" height="292px"/>
</div>
</div>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

BIN
public/favicon.ico.bak Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB