commit
f055fed7d0
|
@ -25,6 +25,7 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
|
Organizations::CreateForm.new(organization_params).validate!
|
||||||
@organization = Organizations::CreateService.call(current_user, organization_params)
|
@organization = Organizations::CreateService.call(current_user, organization_params)
|
||||||
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
|
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,7 +33,10 @@ class Organizations::TeamsController < Organizations::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@team = Organizations::Teams::CreateService.call(current_user, @organization, team_params)
|
ActiveRecord::Base.transaction do
|
||||||
|
Organizations::CreateTeamForm.new(team_params).validate!
|
||||||
|
@team = Organizations::Teams::CreateService.call(current_user, @organization, team_params)
|
||||||
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
|
@ -60,7 +63,7 @@ class Organizations::TeamsController < Organizations::BaseController
|
||||||
|
|
||||||
private
|
private
|
||||||
def team_params
|
def team_params
|
||||||
params.permit(:name, :description, :authorize, :includes_all_project, :can_create_org_project, :unit_types => [])
|
params.permit(:name, :nickname, :description, :authorize, :includes_all_project, :can_create_org_project, :unit_types => [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_organization
|
def load_organization
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
class Organizations::CreateForm < BaseForm
|
||||||
|
NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||||
|
attr_accessor :name, :description, :website, :location, :repo_admin_change_team_access, :visibility, :max_repo_creation, :nickname
|
||||||
|
|
||||||
|
validates :name, :nickname, :visibility, presence: true
|
||||||
|
validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
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, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||||
|
|
||||||
|
end
|
|
@ -161,6 +161,7 @@ class Project < ApplicationRecord
|
||||||
|
|
||||||
#创建项目管理员
|
#创建项目管理员
|
||||||
def check_project_members
|
def check_project_members
|
||||||
|
return if owner.is_a?(Organization)
|
||||||
unless members.present? && members.exists?(user_id: self.user_id)
|
unless members.present? && members.exists?(user_id: self.user_id)
|
||||||
member_params = {
|
member_params = {
|
||||||
user_id: self.user_id,
|
user_id: self.user_id,
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# gtid :integer
|
# gtid :integer
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
|
# nickname :string(255)
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Organizations::Teams::UpdateService < ApplicationService
|
||||||
if team.authorize == "owner"
|
if team.authorize == "owner"
|
||||||
update_params = params.slice(:description)
|
update_params = params.slice(:description)
|
||||||
else
|
else
|
||||||
update_params = params.slice(:name, :description, :authorize, :includes_all_project, :can_create_org_project)
|
update_params = params.slice(:name, :nickname, :description, :authorize, :includes_all_project, :can_create_org_project)
|
||||||
end
|
end
|
||||||
update_params
|
update_params
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
json.id organization.id
|
json.id organization.id
|
||||||
json.name organization.login
|
json.name organization.login
|
||||||
json.nickname organization.nickname
|
json.nickname organization.nickname.blank? ? organization.name : organization.nickname
|
||||||
json.description organization.description
|
json.description organization.description
|
||||||
json.website organization.website
|
json.website organization.website
|
||||||
json.location organization.location
|
json.location organization.location
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
json.id team.id
|
json.id team.id
|
||||||
json.name team.name
|
json.name team.name
|
||||||
|
json.nickname team.nickname.blank? ? team.name : team.nickname
|
||||||
json.description team.description
|
json.description team.description
|
||||||
json.authorize team.authorize
|
json.authorize team.authorize
|
||||||
json.includes_all_project team.includes_all_project
|
json.includes_all_project team.includes_all_project
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddNicknameToTeams < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :teams, :nickname, :string
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue