Browse Source

add: org valid

tags/v3.0.2^2
vilet.yy jasder 5 years ago
parent
commit
a3c49b3d5f
5 changed files with 22 additions and 2 deletions
  1. +1
    -0
      app/controllers/organizations/organizations_controller.rb
  2. +4
    -1
      app/controllers/organizations/teams_controller.rb
  3. +8
    -0
      app/forms/organizations/create_form.rb
  4. +8
    -0
      app/forms/organizations/create_team_form.rb
  5. +1
    -1
      app/views/organizations/organizations/_detail.json.jbuilder

+ 1
- 0
app/controllers/organizations/organizations_controller.rb View File

@@ -25,6 +25,7 @@ class Organizations::OrganizationsController < Organizations::BaseController

def create
ActiveRecord::Base.transaction do
Organizations::CreateForm.new(organization_params).validate!
@organization = Organizations::CreateService.call(current_user, organization_params)
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
end


+ 4
- 1
app/controllers/organizations/teams_controller.rb View File

@@ -33,7 +33,10 @@ class Organizations::TeamsController < Organizations::BaseController
end

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
uid_logger_error(e.message)
tip_exception(e.message)


+ 8
- 0
app/forms/organizations/create_form.rb View File

@@ -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

+ 8
- 0
app/forms/organizations/create_team_form.rb View File

@@ -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, :includes_all_project, presence: true
validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }

end

+ 1
- 1
app/views/organizations/organizations/_detail.json.jbuilder View File

@@ -1,6 +1,6 @@
json.id organization.id
json.name organization.login
json.nickname organization.nickname
json.nickname organization.nickname.blank? ? organization.name : organization.nickname
json.description organization.description
json.website organization.website
json.location organization.location


Loading…
Cancel
Save