add: reversed keyword and api forbidden
This commit is contained in:
parent
d1246b8e30
commit
fe7dfcea52
|
@ -9,6 +9,7 @@ class AccountsController < ApplicationController
|
|||
# 其他平台同步注册的用户
|
||||
def remote_register
|
||||
username = params[:username]&.gsub(/\s+/, "")
|
||||
return render_forbidden('该用户名为系统保留关键字.') if ReversedKeyword.is_reversed(username).present?
|
||||
email = params[:email]&.gsub(/\s+/, "")
|
||||
password = params[:password]
|
||||
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")
|
||||
|
|
|
@ -25,6 +25,7 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
|||
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
return render_forbidden('该组织标识为系统保留关键字.') if ReversedKeyword.is_reversed(organization_params[:name]).present?
|
||||
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?
|
||||
|
|
|
@ -45,6 +45,7 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
return render_forbidden('该项目标识为系统保留关键字.') if ReversedKeyword.is_reversed(project_params[:repository_name]).present?
|
||||
Projects::CreateForm.new(project_params).validate!
|
||||
@project = Projects::CreateService.new(current_user, project_params).call
|
||||
|
||||
|
@ -55,6 +56,7 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def migrate
|
||||
return render_forbidden('该项目标识为系统保留关键字.') if ReversedKeyword.is_reversed(mirror_params[:repository_name]).present?
|
||||
Projects::MigrateForm.new(mirror_params).validate!
|
||||
|
||||
@project =
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: reversed_keywords
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# identifier :string(255)
|
||||
# description :text(65535)
|
||||
# closed :boolean default("0")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class ReversedKeyword < ApplicationRecord
|
||||
|
||||
scope :is_reversed, -> (identifier){where(identifier: identifier, closed: false) if identifier.present?}
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class CreateReversedKeywords < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :reversed_keywords do |t|
|
||||
t.string :identifier, comment: '保留关键字'
|
||||
t.text :description, comment: '描述'
|
||||
t.boolean :closed, default: false, comment: '是否关闭'
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ReversedKeyword, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue