add: team valid
This commit is contained in:
		
							parent
							
								
									411c10e8f3
								
							
						
					
					
						commit
						fc5876fc32
					
				| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
'zh-CN':
 | 
			
		||||
  activemodel:
 | 
			
		||||
    attributes:
 | 
			
		||||
      organizations/create_team_form:
 | 
			
		||||
        name: 团队标识
 | 
			
		||||
        nickname: 团队名称
 | 
			
		||||
        description: 团队描述
 | 
			
		||||
		Loading…
	
		Reference in New Issue