mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 21:25:39 +02:00
Revert "Use inflector rule to acronym Api to API"
This reverts commit 06f5eb10d4
.
This commit is contained in:
parent
90b2455032
commit
aac76b333c
25 changed files with 43 additions and 44 deletions
|
@ -4,7 +4,7 @@ module Repp
|
||||||
prefix :repp
|
prefix :repp
|
||||||
|
|
||||||
http_basic do |username, password|
|
http_basic do |username, password|
|
||||||
@current_user ||= APIUser.find_by(username: username, password: password)
|
@current_user ||= ApiUser.find_by(username: username, password: password)
|
||||||
if @current_user
|
if @current_user
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
module Admin
|
module Admin
|
||||||
class APIUsersController < BaseController
|
class ApiUsersController < BaseController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
before_action :set_api_user, only: [:show, :edit, :update, :destroy]
|
before_action :set_api_user, only: [:show, :edit, :update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@q = APIUser.includes(:registrar).search(params[:q])
|
@q = ApiUser.includes(:registrar).search(params[:q])
|
||||||
@api_users = @q.result.page(params[:page])
|
@api_users = @q.result.page(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@registrar = Registrar.find_by(id: params[:registrar_id])
|
@registrar = Registrar.find_by(id: params[:registrar_id])
|
||||||
@api_user = APIUser.new(registrar: @registrar)
|
@api_user = ApiUser.new(registrar: @registrar)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@api_user = APIUser.new(api_user_params)
|
@api_user = ApiUser.new(api_user_params)
|
||||||
|
|
||||||
if @api_user.save
|
if @api_user.save
|
||||||
flash[:notice] = I18n.t('record_created')
|
flash[:notice] = I18n.t('record_created')
|
||||||
|
@ -55,7 +55,7 @@ module Admin
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_api_user
|
def set_api_user
|
||||||
@api_user = APIUser.find(params[:id])
|
@api_user = ApiUser.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_user_params
|
def api_user_params
|
||||||
|
|
|
@ -7,12 +7,12 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@api_user = APIUser.find(params[:api_user_id])
|
@api_user = ApiUser.find(params[:api_user_id])
|
||||||
@certificate = Certificate.new(api_user: @api_user)
|
@certificate = Certificate.new(api_user: @api_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@api_user = APIUser.find(params[:api_user_id])
|
@api_user = ApiUser.find(params[:api_user_id])
|
||||||
|
|
||||||
crt = certificate_params[:crt].open.read if certificate_params[:crt]
|
crt = certificate_params[:crt].open.read if certificate_params[:crt]
|
||||||
csr = certificate_params[:csr].open.read if certificate_params[:csr]
|
csr = certificate_params[:csr].open.read if certificate_params[:csr]
|
||||||
|
@ -73,7 +73,7 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_api_user
|
def set_api_user
|
||||||
@api_user = APIUser.find(params[:api_user_id])
|
@api_user = ApiUser.find(params[:api_user_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def certificate_params
|
def certificate_params
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'rails5_api_controller_backport'
|
require 'rails5_api_controller_backport'
|
||||||
require 'auth_token/auth_token_creator'
|
require 'auth_token/auth_token_creator'
|
||||||
|
|
||||||
module API
|
module Api
|
||||||
module V1
|
module V1
|
||||||
module Registrant
|
module Registrant
|
||||||
class AuthController < ActionController::API
|
class AuthController < ActionController::API
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'rails5_api_controller_backport'
|
require 'rails5_api_controller_backport'
|
||||||
require 'auth_token/auth_token_decryptor'
|
require 'auth_token/auth_token_decryptor'
|
||||||
|
|
||||||
module API
|
module Api
|
||||||
module V1
|
module V1
|
||||||
module Registrant
|
module Registrant
|
||||||
class BaseController < ActionController::API
|
class BaseController < ActionController::API
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'rails5_api_controller_backport'
|
require 'rails5_api_controller_backport'
|
||||||
require 'auth_token/auth_token_decryptor'
|
require 'auth_token/auth_token_decryptor'
|
||||||
|
|
||||||
module API
|
module Api
|
||||||
module V1
|
module V1
|
||||||
module Registrant
|
module Registrant
|
||||||
class DomainsController < BaseController
|
class DomainsController < BaseController
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Epp::SessionsController < EppController
|
||||||
|
|
||||||
def login
|
def login
|
||||||
success = true
|
success = true
|
||||||
@api_user = APIUser.find_by(login_params)
|
@api_user = ApiUser.find_by(login_params)
|
||||||
|
|
||||||
webclient_request = ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip)
|
webclient_request = ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip)
|
||||||
if webclient_request && !Rails.env.test? && !Rails.env.development?
|
if webclient_request && !Rails.env.test? && !Rails.env.development?
|
||||||
|
|
|
@ -95,6 +95,6 @@ class Registrant::SessionsController < Devise::SessionsController
|
||||||
|
|
||||||
def find_user_by_idc(idc)
|
def find_user_by_idc(idc)
|
||||||
return User.new unless idc
|
return User.new unless idc
|
||||||
APIUser.find_by(identity_code: idc) || User.new
|
ApiUser.find_by(identity_code: idc) || User.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@ class Registrar
|
||||||
private
|
private
|
||||||
|
|
||||||
def new_user
|
def new_user
|
||||||
@new_user ||= APIUser.find(params[:new_user_id])
|
@new_user ||= ApiUser.find(params[:new_user_id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Registrar
|
||||||
@depp_user.errors.add(:base, :webserver_client_cert_directive_should_be_required)
|
@depp_user.errors.add(:base, :webserver_client_cert_directive_should_be_required)
|
||||||
end
|
end
|
||||||
|
|
||||||
@api_user = APIUser.find_by(username: params[:depp_user][:tag], password: params[:depp_user][:password])
|
@api_user = ApiUser.find_by(username: params[:depp_user][:tag], password: params[:depp_user][:password])
|
||||||
|
|
||||||
unless @api_user
|
unless @api_user
|
||||||
@depp_user.errors.add(:base, t(:no_such_user))
|
@depp_user.errors.add(:base, t(:no_such_user))
|
||||||
|
@ -53,7 +53,7 @@ class Registrar
|
||||||
end
|
end
|
||||||
|
|
||||||
def id
|
def id
|
||||||
@user = APIUser.find_by_idc_data_and_allowed(request.env['SSL_CLIENT_S_DN'], request.ip)
|
@user = ApiUser.find_by_idc_data_and_allowed(request.env['SSL_CLIENT_S_DN'], request.ip)
|
||||||
|
|
||||||
if @user
|
if @user
|
||||||
sign_in(@user, event: :authentication)
|
sign_in(@user, event: :authentication)
|
||||||
|
@ -150,12 +150,12 @@ class Registrar
|
||||||
|
|
||||||
def find_user_by_idc(idc)
|
def find_user_by_idc(idc)
|
||||||
return User.new unless idc
|
return User.new unless idc
|
||||||
APIUser.find_by(identity_code: idc) || User.new
|
ApiUser.find_by(identity_code: idc) || User.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_user_by_idc_and_allowed(idc)
|
def find_user_by_idc_and_allowed(idc)
|
||||||
return User.new unless idc
|
return User.new unless idc
|
||||||
possible_users = APIUser.where(identity_code: idc) || User.new
|
possible_users = ApiUser.where(identity_code: idc) || User.new
|
||||||
possible_users.each do |selected_user|
|
possible_users.each do |selected_user|
|
||||||
if selected_user.registrar.white_ips.registrar_area.include_ip?(request.ip)
|
if selected_user.registrar.white_ips.registrar_area.include_ip?(request.ip)
|
||||||
return selected_user
|
return selected_user
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Ability
|
||||||
case @user.class.to_s
|
case @user.class.to_s
|
||||||
when 'AdminUser'
|
when 'AdminUser'
|
||||||
@user.roles&.each { |role| send(role) }
|
@user.roles&.each { |role| send(role) }
|
||||||
when 'APIUser'
|
when 'ApiUser'
|
||||||
@user.roles&.each { |role| send(role) }
|
@user.roles&.each { |role| send(role) }
|
||||||
when 'RegistrantUser'
|
when 'RegistrantUser'
|
||||||
static_registrant
|
static_registrant
|
||||||
|
@ -94,7 +94,7 @@ class Ability
|
||||||
can :manage, ContactVersion
|
can :manage, ContactVersion
|
||||||
can :manage, Billing::Price
|
can :manage, Billing::Price
|
||||||
can :manage, User
|
can :manage, User
|
||||||
can :manage, APIUser
|
can :manage, ApiUser
|
||||||
can :manage, AdminUser
|
can :manage, AdminUser
|
||||||
can :manage, Certificate
|
can :manage, Certificate
|
||||||
can :manage, Keyrelay
|
can :manage, Keyrelay
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'open3'
|
require 'open3'
|
||||||
|
|
||||||
class APIUser < User
|
class ApiUser < User
|
||||||
include EppErrors
|
include EppErrors
|
||||||
|
|
||||||
def epp_code_map
|
def epp_code_map
|
||||||
|
|
|
@ -34,7 +34,7 @@ module Versions
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_from_id_role_username(str)
|
def user_from_id_role_username(str)
|
||||||
user = APIUser.find_by(id: $1) if str =~ /^(\d+)-(APIUser:|api-)/
|
user = ApiUser.find_by(id: $1) if str =~ /^(\d+)-(ApiUser:|api-)/
|
||||||
unless user.present?
|
unless user.present?
|
||||||
user = AdminUser.find_by(id: $1) if str =~ /^(\d+)-AdminUser:/
|
user = AdminUser.find_by(id: $1) if str =~ /^(\d+)-AdminUser:/
|
||||||
unless user.present?
|
unless user.present?
|
||||||
|
|
|
@ -490,7 +490,7 @@ class Epp::Domain < Domain
|
||||||
|
|
||||||
def apply_pending_update!
|
def apply_pending_update!
|
||||||
preclean_pendings
|
preclean_pendings
|
||||||
user = APIUser.find(pending_json['current_user_id'])
|
user = ApiUser.find(pending_json['current_user_id'])
|
||||||
frame = Nokogiri::XML(pending_json['frame'])
|
frame = Nokogiri::XML(pending_json['frame'])
|
||||||
|
|
||||||
self.statuses.delete(DomainStatus::PENDING_UPDATE)
|
self.statuses.delete(DomainStatus::PENDING_UPDATE)
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
= f.label :role, nil, class: 'required'
|
= f.label :role, nil, class: 'required'
|
||||||
.col-md-7
|
.col-md-7
|
||||||
= select_tag 'api_user[roles][]',
|
= select_tag 'api_user[roles][]',
|
||||||
options_for_select(APIUser::ROLES.map {|x| [x, x] }, @api_user.roles.try(:first)),
|
options_for_select(ApiUser::ROLES.map {|x| [x, x] }, @api_user.roles.try(:first)),
|
||||||
class: 'form-control selectize'
|
class: 'form-control selectize'
|
||||||
.checkbox
|
.checkbox
|
||||||
%label{for: 'api_user_active'}
|
%label{for: 'api_user_active'}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<table class="table table-hover table-bordered table-condensed">
|
<table class="table table-hover table-bordered table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="col-xs-6"><%= APIUser.human_attribute_name :username %></th>
|
<th class="col-xs-6"><%= ApiUser.human_attribute_name :username %></th>
|
||||||
<th class="col-xs-6"><%= APIUser.human_attribute_name :active %></th>
|
<th class="col-xs-6"><%= ApiUser.human_attribute_name :active %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
|
|
|
@ -12,5 +12,4 @@
|
||||||
|
|
||||||
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
inflect.acronym 'DNS'
|
inflect.acronym 'DNS'
|
||||||
inflect.acronym 'API'
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -131,7 +131,7 @@ namespace :import do
|
||||||
ips = []
|
ips = []
|
||||||
temp = []
|
temp = []
|
||||||
|
|
||||||
existing_ids = APIUser.pluck(:legacy_id)
|
existing_ids = ApiUser.pluck(:legacy_id)
|
||||||
existing_ips = WhiteIp.pluck(:ipv4)
|
existing_ips = WhiteIp.pluck(:ipv4)
|
||||||
|
|
||||||
Legacy::Registrar.all.each do |x|
|
Legacy::Registrar.all.each do |x|
|
||||||
|
@ -143,7 +143,7 @@ namespace :import do
|
||||||
if y.try(:cert) != 'pki'
|
if y.try(:cert) != 'pki'
|
||||||
|
|
||||||
if y.try(:cert) == 'idkaart'
|
if y.try(:cert) == 'idkaart'
|
||||||
id_users << APIUser.new({
|
id_users << ApiUser.new({
|
||||||
username: y.try(:password) ? y.try(:password) : y.try(:password),
|
username: y.try(:password) ? y.try(:password) : y.try(:password),
|
||||||
password: ('a'..'z').to_a.shuffle.first(8).join,
|
password: ('a'..'z').to_a.shuffle.first(8).join,
|
||||||
identity_code: y.try(:password) ? y.try(:password) : y.try(:password),
|
identity_code: y.try(:password) ? y.try(:password) : y.try(:password),
|
||||||
|
@ -152,7 +152,7 @@ namespace :import do
|
||||||
legacy_id: y.try(:id)
|
legacy_id: y.try(:id)
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
temp << APIUser.new({
|
temp << ApiUser.new({
|
||||||
username: x.handle.try(:strip),
|
username: x.handle.try(:strip),
|
||||||
password: y.try(:password) ? y.try(:password) : ('a'..'z').to_a.shuffle.first(8).join,
|
password: y.try(:password) ? y.try(:password) : ('a'..'z').to_a.shuffle.first(8).join,
|
||||||
registrar_id: Registrar.find_by(legacy_id: x.try(:id)).try(:id),
|
registrar_id: Registrar.find_by(legacy_id: x.try(:id)).try(:id),
|
||||||
|
@ -181,8 +181,8 @@ namespace :import do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
APIUser.import id_users, validate: false
|
ApiUser.import id_users, validate: false
|
||||||
APIUser.import users, validate: false
|
ApiUser.import users, validate: false
|
||||||
|
|
||||||
if ips
|
if ips
|
||||||
WhiteIp.import ips, validate: false
|
WhiteIp.import ips, validate: false
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :api_user do
|
factory :api_user do
|
||||||
sequence(:username) { |n| "test#{n}" }
|
sequence(:username) { |n| "test#{n}" }
|
||||||
password 'a' * APIUser.min_password_length
|
password 'a' * ApiUser.min_password_length
|
||||||
roles ['super']
|
roles ['super']
|
||||||
registrar
|
registrar
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe APIUser do
|
RSpec.describe ApiUser do
|
||||||
context 'with invalid attribute' do
|
context 'with invalid attribute' do
|
||||||
before do
|
before do
|
||||||
@api_user = APIUser.new
|
@api_user = ApiUser.new
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be valid' do
|
it 'should not be valid' do
|
||||||
@api_user.valid?
|
@api_user.valid?
|
||||||
@api_user.errors.full_messages.should match_array([
|
@api_user.errors.full_messages.should match_array([
|
||||||
"Password Password is missing",
|
"Password Password is missing",
|
||||||
"Password is too short (minimum is #{APIUser.min_password_length} characters)",
|
"Password is too short (minimum is #{ApiUser.min_password_length} characters)",
|
||||||
"Registrar Registrar is missing",
|
"Registrar Registrar is missing",
|
||||||
"Username Username is missing",
|
"Username Username is missing",
|
||||||
"Roles is missing"
|
"Roles is missing"
|
||||||
|
|
|
@ -316,10 +316,10 @@ RSpec.describe Domain do
|
||||||
@api_user = create(:api_user)
|
@api_user = create(:api_user)
|
||||||
@user.id.should == 1
|
@user.id.should == 1
|
||||||
@api_user.id.should == 2
|
@api_user.id.should == 2
|
||||||
::PaperTrail.whodunnit = '2-APIUser: testuser'
|
::PaperTrail.whodunnit = '2-ApiUser: testuser'
|
||||||
|
|
||||||
@domain = create(:domain)
|
@domain = create(:domain)
|
||||||
@domain.creator_str.should == '2-APIUser: testuser'
|
@domain.creator_str.should == '2-ApiUser: testuser'
|
||||||
|
|
||||||
@domain.creator.should == @api_user
|
@domain.creator.should == @api_user
|
||||||
@domain.creator.should_not == @user
|
@domain.creator.should_not == @user
|
||||||
|
|
|
@ -4,7 +4,7 @@ RSpec.describe UserPresenter do
|
||||||
let(:presenter) { described_class.new(user: user, view: view) }
|
let(:presenter) { described_class.new(user: user, view: view) }
|
||||||
|
|
||||||
describe '#login_with_role' do
|
describe '#login_with_role' do
|
||||||
let(:user) { instance_double(APIUser,
|
let(:user) { instance_double(ApiUser,
|
||||||
login: 'login',
|
login: 'login',
|
||||||
roles: %w[role],
|
roles: %w[role],
|
||||||
registrar_name: 'registrar') }
|
registrar_name: 'registrar') }
|
||||||
|
|
4
test/fixtures/users.yml
vendored
4
test/fixtures/users.yml
vendored
|
@ -1,7 +1,7 @@
|
||||||
api_bestnames:
|
api_bestnames:
|
||||||
username: test_bestnames
|
username: test_bestnames
|
||||||
password: testtest
|
password: testtest
|
||||||
type: APIUser
|
type: ApiUser
|
||||||
registrar: bestnames
|
registrar: bestnames
|
||||||
active: true
|
active: true
|
||||||
roles:
|
roles:
|
||||||
|
@ -10,7 +10,7 @@ api_bestnames:
|
||||||
api_goodnames:
|
api_goodnames:
|
||||||
username: test_goodnames
|
username: test_goodnames
|
||||||
password: testtest
|
password: testtest
|
||||||
type: APIUser
|
type: ApiUser
|
||||||
registrar: goodnames
|
registrar: goodnames
|
||||||
active: true
|
active: true
|
||||||
roles:
|
roles:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class RegistrantAPIAuthenticationTest < ApplicationSystemTestCase
|
class RegistrantApiAuthenticationTest < ApplicationSystemTestCase
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
require 'auth_token/auth_token_creator'
|
require 'auth_token/auth_token_creator'
|
||||||
|
|
||||||
class RegistrantAPIDomainsTest < ApplicationSystemTestCase
|
class RegistrantApiDomainsTest < ApplicationSystemTestCase
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue