Browse Source

FIX code review

tags/v4.0.0
jasder 4 years ago
parent
commit
cbf8f1fa67
5 changed files with 8 additions and 4 deletions
  1. +1
    -1
      app/controllers/accounts_controller.rb
  2. +1
    -1
      app/controllers/organizations/organizations_controller.rb
  3. +1
    -1
      app/forms/base_form.rb
  4. +1
    -1
      app/forms/register/check_columns_form.rb
  5. +4
    -0
      app/models/reversed_keyword.rb

+ 1
- 1
app/controllers/accounts_controller.rb View File

@@ -9,7 +9,7 @@ class AccountsController < ApplicationController
# 其他平台同步注册的用户
def remote_register
username = params[:username]&.gsub(/\s+/, "")
tip_exception("无法使用以下关键词:#{username},请重新命名") if ReversedKeyword.is_reversed(username).present?
tip_exception("无法使用以下关键词:#{username},请重新命名") if ReversedKeyword.check_exists?(username)
email = params[:email]&.gsub(/\s+/, "")
password = params[:password]
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")


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

@@ -26,7 +26,7 @@ class Organizations::OrganizationsController < Organizations::BaseController

def create
ActiveRecord::Base.transaction do
tip_exception("无法使用以下关键词:#{organization_params[:name]},请重新命名") if ReversedKeyword.is_reversed(organization_params[:name]).present?
tip_exception("无法使用以下关键词:#{organization_params[:name]},请重新命名") if ReversedKeyword.check_exists?(organization_params[:name])
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?


+ 1
- 1
app/forms/base_form.rb View File

@@ -23,7 +23,7 @@ class BaseForm
end

def check_reversed_keyword(repository_name)
raise "项目标识已被占用." if ReversedKeyword.is_reversed(repository_name).exists?
raise "项目标识已被占用." if ReversedKeyword.check_exists?(repository_name)
end
end

+ 1
- 1
app/forms/register/check_columns_form.rb View File

@@ -20,7 +20,7 @@ module Register
def check_login
raise("登录名格式有误") unless strip_value =~ CustomRegexp::LOGIN

login_exist = Owner.exists?(login: strip_value) || ReversedKeyword.exists?(identifier: strip_value)
login_exist = Owner.exists?(login: strip_value) || ReversedKeyword.check_exists?(strip_value)
raise('登录名已被使用') if login_exist
end



+ 4
- 0
app/models/reversed_keyword.rb View File

@@ -18,6 +18,10 @@ class ReversedKeyword < ApplicationRecord

before_validation :set_identifier

def self.check_exists?(identifier)
self.is_reversed(identifier).exists?
end
private

def set_identifier


Loading…
Cancel
Save