Merge branch 'develop' of https://git.trustie.net/jasder/forgeplus into develop

This commit is contained in:
jasder 2021-05-08 14:23:05 +08:00
commit f470807225
23 changed files with 151 additions and 50 deletions

View File

@ -169,6 +169,7 @@ class AccountsController < ApplicationController
# 用户登录
def login
Users::LoginForm.new(account_params).validate!
@user = User.try_to_login(params[:login], params[:password])
return normal_status(-2, "错误的账号或密码") if @user.blank?
@ -345,4 +346,7 @@ class AccountsController < ApplicationController
params.require(:user).permit(:login, :email, :phone)
end
def account_params
params.require(:account).permit(:login, :password)
end
end

View File

@ -101,51 +101,46 @@ class IssuesController < ApplicationController
end
def create
if params[:subject].blank?
normal_status(-1, "标题不能为空")
elsif params[:subject].to_s.size > 255
normal_status(-1, "标题不能超过255个字符")
else
issue_params = issue_send_params(params)
@issue = Issue.new(issue_params)
if @issue.save!
if params[:attachment_ids].present?
params[:attachment_ids].each do |id|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
unless attachment.blank?
attachment.container = @issue
attachment.author_id = current_user.id
attachment.description = ""
attachment.save
end
issue_params = issue_send_params(params)
Issues::CreateForm.new({subject:issue_params[:subject]}).validate!
@issue = Issue.new(issue_params)
if @issue.save!
if params[:attachment_ids].present?
params[:attachment_ids].each do |id|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
unless attachment.blank?
attachment.container = @issue
attachment.author_id = current_user.id
attachment.description = ""
attachment.save
end
end
if params[:issue_tag_ids].present?
params[:issue_tag_ids].each do |tag|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
end
end
if params[:issue_tag_ids].present?
params[:issue_tag_ids].each do |tag|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
end
if params[:assigned_to_id].present?
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
container_id: @issue.id, container_type: 'Issue',
parent_container_id: @project.id, parent_container_type: "Project",
tiding_type: 'issue', status: 0)
end
#为悬赏任务时, 扣除当前用户的积分
if params[:issue_type].to_s == "2"
post_to_chain("minus", params[:token].to_i, current_user.try(:login))
end
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
render json: {status: 0, message: "创建成", id: @issue.id}
else
normal_status(-1, "创建失败")
end
if params[:assigned_to_id].present?
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
container_id: @issue.id, container_type: 'Issue',
parent_container_id: @project.id, parent_container_type: "Project",
tiding_type: 'issue', status: 0)
end
end
#为悬赏任务时, 扣除当前用户的积分
if params[:issue_type].to_s == "2"
post_to_chain("minus", params[:token].to_i, current_user.try(:login))
end
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
render json: {status: 0, message: "创建成", id: @issue.id}
else
normal_status(-1, "创建失败")
end
rescue Exception => exception
puts exception.message
normal_status(-1, exception.message)
end
def edit
@ -199,7 +194,7 @@ class IssuesController < ApplicationController
normal_status(-1, "不允许修改为关闭状态")
else
issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id)
Issues::UpdateForm.new({subject:issue_params[:subject]}).validate!
if @issue.update_attributes(issue_params)
if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时
@issue.issue_times.update_all(end_time: Time.now)
@ -225,6 +220,9 @@ class IssuesController < ApplicationController
normal_status(-1, "更新失败")
end
end
rescue Exception => exception
puts exception.message
normal_status(-1, exception.message)
end
def show

View File

@ -36,6 +36,7 @@ class Organizations::OrganizationsController < Organizations::BaseController
def update
ActiveRecord::Base.transaction do
Organizations::CreateForm.new(organization_params).validate!
login = @organization.login
@organization.login = organization_params[:name] if organization_params[:name].present?
@organization.nickname = organization_params[:nickname] if organization_params[:nickname].present?

View File

@ -43,6 +43,7 @@ class Organizations::TeamsController < Organizations::BaseController
end
def update
Organizations::CreateTeamForm.new(team_params).validate!
@team = Organizations::Teams::UpdateService.call(current_user, @team, team_params)
rescue Exception => e
uid_logger_error(e.message)

View File

@ -106,7 +106,7 @@ class ProjectsController < ApplicationController
def update
ActiveRecord::Base.transaction do
# Projects::CreateForm.new(project_params).validate!
Projects::UpdateForm.new(project_params).validate!
private = params[:private] || false
new_project_params = project_params.except(:private).merge(is_public: !private)

View File

@ -0,0 +1,11 @@
class Issues::CreateForm
include ActiveModel::Model
attr_accessor :subject
validates :subject, presence: { message: "不能为空" }
validates :subject, length: { maximum: 80, too_long: "不能超过80个字符" }
end

View File

@ -0,0 +1,10 @@
class Issues::UpdateForm
include ActiveModel::Model
attr_accessor :subject
validates :subject, presence: { message: "不能为空" }
validates :subject, length: { maximum: 80, too_long: "不能超过80个字符" }
end

View File

@ -3,6 +3,9 @@ class Organizations::CreateForm < BaseForm
attr_accessor :name, :description, :website, :location, :repo_admin_change_team_access, :visibility, :max_repo_creation, :nickname
validates :name, :nickname, :visibility, presence: true
validates :name, :nickname, length: { maximum: 100 }
validates :location, length: { maximum: 50 }
validates :description, length: { maximum: 200 }
validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
end

View File

@ -2,7 +2,9 @@ class Organizations::CreateTeamForm < BaseForm
NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
attr_accessor :name, :nickname, :description, :authorize, :includes_all_project, :can_create_org_project, :unit_types
validates :name, :nickname, :authorize, presence: true
validates :name, :nickname, presence: true
validates :name, :nickname, length: { maximum: 100 }
validates :description, length: { maximum: 200 }
validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
end

View File

@ -2,11 +2,15 @@ class Projects::CreateForm < BaseForm
REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
attr_accessor :user_id, :name, :description, :repository_name, :project_category_id,
:project_language_id, :ignore_id, :license_id, :private, :owner
validates :user_id, :name, :description,:repository_name,
:project_category_id, :project_language_id, presence: true
validates :repository_name, format: { with: REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
validates :name, length: { maximum: 50 }
validates :repository_name, length: { maximum: 100 }
validates :description, length: { maximum: 200 }
validate :check_ignore, :check_license, :check_owner, :check_max_repo_creation
validate do
check_project_category(project_category_id)

View File

@ -1,4 +1,11 @@
class Projects::UpdateForm < BaseForm
attr_reader :name, :description, :repository_name, :project_category_id
attr_accessor :name, :description, :project_category_id, :project_language_id, :private
validates :name, :description, :project_category_id, :project_language_id, presence: true
validates :name, length: { maximum: 50 }
validates :description, length: { maximum: 200 }
validate do
check_project_category(project_category_id)
check_project_language(project_language_id)
end
end

View File

@ -0,0 +1,8 @@
class Users::LoginForm
include ActiveModel::Model
attr_accessor :password, :login
validates :login, presence: true
validates :password, presence: true, length: { minimum: 8, maximum: 16 }, format: { with: CustomRegexp::PASSWORD, message: "8~16位支持字母数字和符号" }
end

View File

@ -20,13 +20,16 @@ class ProjectUnit < ApplicationRecord
validates :unit_type, uniqueness: { scope: :project_id}
def self.init_types(project_id)
ProjectUnit::unit_types.each do |_, v|
def self.init_types(project_id, project_type='common')
unit_types = project_type == 'sync_mirror' ? ProjectUnit::unit_types.except("pulls") : ProjectUnit::unit_types
unit_types.each do |_, v|
self.create!(project_id: project_id, unit_type: v)
end
end
def self.update_by_unit_types!(project, types)
# 同步镜像项目不能有合并请求模块
types.delete("pulls") if project.sync_mirror?
# 默认code类型自动创建
types << "code"
project.project_units.where.not(unit_type: types).each(&:destroy!)

View File

@ -33,9 +33,10 @@ class Team < ApplicationRecord
enum authorize: {common: 0, read: 1, write: 2, admin: 3, owner: 4}
def self.build(organization_id, name, description, authorize, includes_all_project, can_create_org_project)
def self.build(organization_id, name, nickname, description, authorize, includes_all_project, can_create_org_project)
self.create!(organization_id: organization_id,
name: name,
nickname: nickname,
description: description,
authorize: authorize,
includes_all_project: includes_all_project,

View File

@ -28,6 +28,10 @@ class Organizations::Teams::CreateService < ApplicationService
params[:name]
end
def nickname
params[:nickname]
end
def description
params[:description]
end
@ -45,7 +49,7 @@ class Organizations::Teams::CreateService < ApplicationService
end
def create_team
@team = Team.build(org.id, name, description, authorize,
@team = Team.build(org.id, name, nickname, description, authorize,
includes_all_project, can_create_org_project)
end

View File

@ -10,7 +10,7 @@ class Projects::MigrateService < ApplicationService
def call
@project = Project.new(project_params)
if @project.save!
ProjectUnit.init_types(@project.id)
ProjectUnit.init_types(@project.id, project.project_type)
Project.update_mirror_projects_count!
@project.set_owner_permission(user)
Repositories::MigrateService.new(user, @project, repository_params).call

View File

@ -80,7 +80,7 @@ json.contributors do
total_count = @result[:contributor].size
json.list @result[:contributor].each do |contributor|
user = User.find_by(gitea_uid: contributor["id"])
if contributor["login"] == "root"
if contributor["login"] == "root" || user.nil?
total_count -= 1
next
end

View File

@ -0,0 +1,7 @@
'zh-CN':
activemodel:
attributes:
issues/create_form:
subject: 标题
issues/update_form:
subject: 标题

View File

@ -0,0 +1,9 @@
'zh-CN':
activemodel:
attributes:
organizations/create_form:
name: 组织账号
nickname: 组织名称
location: 组织所在地区
description: 组织简介
visibility: 组织可见性

View File

@ -0,0 +1,7 @@
'zh-CN':
activemodel:
attributes:
organizations/create_team_form:
name: 团队标识
nickname: 团队名称
description: 团队描述

View File

@ -0,0 +1,7 @@
'zh-CN':
activemodel:
attributes:
projects/create_form:
name: 项目名称
repository_name: 仓库名称
description: 项目简介

View File

@ -0,0 +1,8 @@
'zh-CN':
activemodel:
attributes:
projects/update_form:
name: 项目名称
description: 项目简介
project_category_id: 项目类别
project_language_id: 项目语言

View File

@ -0,0 +1,6 @@
'zh-CN':
activemodel:
attributes:
users/login_form:
login: 用户名
password: 密码