From aac76b333cbe598cccf33071cacbcc7fb7bf9b34 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 24 Jul 2018 12:53:51 +0300 Subject: [PATCH] Revert "Use inflector rule to acronym Api to API" This reverts commit 06f5eb10d4b193e22b831d7e8f8208fec9048a3e. --- app/api/repp/api.rb | 2 +- app/controllers/admin/api_users_controller.rb | 10 +++++----- app/controllers/admin/certificates_controller.rb | 6 +++--- app/controllers/api/v1/registrant/auth_controller.rb | 2 +- app/controllers/api/v1/registrant/base_controller.rb | 2 +- .../api/v1/registrant/domains_controller.rb | 2 +- app/controllers/epp/sessions_controller.rb | 2 +- app/controllers/registrant/sessions_controller.rb | 2 +- app/controllers/registrar/current_user_controller.rb | 2 +- app/controllers/registrar/sessions_controller.rb | 8 ++++---- app/models/ability.rb | 4 ++-- app/models/api_user.rb | 2 +- app/models/concerns/versions.rb | 2 +- app/models/epp/domain.rb | 2 +- app/views/admin/api_users/_form.haml | 2 +- app/views/admin/registrars/_users.html.erb | 4 ++-- config/initializers/inflections.rb | 1 - lib/tasks/import.rake | 10 +++++----- spec/factories/api_user.rb | 2 +- spec/models/api_user_spec.rb | 6 +++--- spec/models/domain_spec.rb | 4 ++-- spec/presenters/user_presenter_spec.rb | 2 +- test/fixtures/users.yml | 4 ++-- .../registrant/registrant_api_authentication_test.rb | 2 +- .../api/registrant/registrant_api_domains_test.rb | 2 +- 25 files changed, 43 insertions(+), 44 deletions(-) diff --git a/app/api/repp/api.rb b/app/api/repp/api.rb index a726d226c..7858cd625 100644 --- a/app/api/repp/api.rb +++ b/app/api/repp/api.rb @@ -4,7 +4,7 @@ module Repp prefix :repp 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 true else diff --git a/app/controllers/admin/api_users_controller.rb b/app/controllers/admin/api_users_controller.rb index e7ac175e8..84344c2e9 100644 --- a/app/controllers/admin/api_users_controller.rb +++ b/app/controllers/admin/api_users_controller.rb @@ -1,20 +1,20 @@ module Admin - class APIUsersController < BaseController + class ApiUsersController < BaseController load_and_authorize_resource before_action :set_api_user, only: [:show, :edit, :update, :destroy] def index - @q = APIUser.includes(:registrar).search(params[:q]) + @q = ApiUser.includes(:registrar).search(params[:q]) @api_users = @q.result.page(params[:page]) end def new @registrar = Registrar.find_by(id: params[:registrar_id]) - @api_user = APIUser.new(registrar: @registrar) + @api_user = ApiUser.new(registrar: @registrar) end def create - @api_user = APIUser.new(api_user_params) + @api_user = ApiUser.new(api_user_params) if @api_user.save flash[:notice] = I18n.t('record_created') @@ -55,7 +55,7 @@ module Admin private def set_api_user - @api_user = APIUser.find(params[:id]) + @api_user = ApiUser.find(params[:id]) end def api_user_params diff --git a/app/controllers/admin/certificates_controller.rb b/app/controllers/admin/certificates_controller.rb index f25651c39..a08654db3 100644 --- a/app/controllers/admin/certificates_controller.rb +++ b/app/controllers/admin/certificates_controller.rb @@ -7,12 +7,12 @@ module Admin end 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) end 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] csr = certificate_params[:csr].open.read if certificate_params[:csr] @@ -73,7 +73,7 @@ module Admin end def set_api_user - @api_user = APIUser.find(params[:api_user_id]) + @api_user = ApiUser.find(params[:api_user_id]) end def certificate_params diff --git a/app/controllers/api/v1/registrant/auth_controller.rb b/app/controllers/api/v1/registrant/auth_controller.rb index 0e014da02..7ba0e9199 100644 --- a/app/controllers/api/v1/registrant/auth_controller.rb +++ b/app/controllers/api/v1/registrant/auth_controller.rb @@ -1,7 +1,7 @@ require 'rails5_api_controller_backport' require 'auth_token/auth_token_creator' -module API +module Api module V1 module Registrant class AuthController < ActionController::API diff --git a/app/controllers/api/v1/registrant/base_controller.rb b/app/controllers/api/v1/registrant/base_controller.rb index 99ff9d90b..510f16745 100644 --- a/app/controllers/api/v1/registrant/base_controller.rb +++ b/app/controllers/api/v1/registrant/base_controller.rb @@ -1,7 +1,7 @@ require 'rails5_api_controller_backport' require 'auth_token/auth_token_decryptor' -module API +module Api module V1 module Registrant class BaseController < ActionController::API diff --git a/app/controllers/api/v1/registrant/domains_controller.rb b/app/controllers/api/v1/registrant/domains_controller.rb index 308f81709..fdfc6872c 100644 --- a/app/controllers/api/v1/registrant/domains_controller.rb +++ b/app/controllers/api/v1/registrant/domains_controller.rb @@ -1,7 +1,7 @@ require 'rails5_api_controller_backport' require 'auth_token/auth_token_decryptor' -module API +module Api module V1 module Registrant class DomainsController < BaseController diff --git a/app/controllers/epp/sessions_controller.rb b/app/controllers/epp/sessions_controller.rb index f463f4365..e3e9f3114 100644 --- a/app/controllers/epp/sessions_controller.rb +++ b/app/controllers/epp/sessions_controller.rb @@ -7,7 +7,7 @@ class Epp::SessionsController < EppController def login 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) if webclient_request && !Rails.env.test? && !Rails.env.development? diff --git a/app/controllers/registrant/sessions_controller.rb b/app/controllers/registrant/sessions_controller.rb index cb51a94f5..80a23eb0a 100644 --- a/app/controllers/registrant/sessions_controller.rb +++ b/app/controllers/registrant/sessions_controller.rb @@ -95,6 +95,6 @@ class Registrant::SessionsController < Devise::SessionsController def find_user_by_idc(idc) return User.new unless idc - APIUser.find_by(identity_code: idc) || User.new + ApiUser.find_by(identity_code: idc) || User.new end end diff --git a/app/controllers/registrar/current_user_controller.rb b/app/controllers/registrar/current_user_controller.rb index 3f969ecb2..266e4b915 100644 --- a/app/controllers/registrar/current_user_controller.rb +++ b/app/controllers/registrar/current_user_controller.rb @@ -12,7 +12,7 @@ class Registrar private def new_user - @new_user ||= APIUser.find(params[:new_user_id]) + @new_user ||= ApiUser.find(params[:new_user_id]) end end end diff --git a/app/controllers/registrar/sessions_controller.rb b/app/controllers/registrar/sessions_controller.rb index c369051e6..11841481d 100644 --- a/app/controllers/registrar/sessions_controller.rb +++ b/app/controllers/registrar/sessions_controller.rb @@ -26,7 +26,7 @@ class Registrar @depp_user.errors.add(:base, :webserver_client_cert_directive_should_be_required) 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 @depp_user.errors.add(:base, t(:no_such_user)) @@ -53,7 +53,7 @@ class Registrar end 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 sign_in(@user, event: :authentication) @@ -150,12 +150,12 @@ class Registrar def find_user_by_idc(idc) return User.new unless idc - APIUser.find_by(identity_code: idc) || User.new + ApiUser.find_by(identity_code: idc) || User.new end def find_user_by_idc_and_allowed(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| if selected_user.registrar.white_ips.registrar_area.include_ip?(request.ip) return selected_user diff --git a/app/models/ability.rb b/app/models/ability.rb index 1bc4ae386..97086110b 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -10,7 +10,7 @@ class Ability case @user.class.to_s when 'AdminUser' @user.roles&.each { |role| send(role) } - when 'APIUser' + when 'ApiUser' @user.roles&.each { |role| send(role) } when 'RegistrantUser' static_registrant @@ -94,7 +94,7 @@ class Ability can :manage, ContactVersion can :manage, Billing::Price can :manage, User - can :manage, APIUser + can :manage, ApiUser can :manage, AdminUser can :manage, Certificate can :manage, Keyrelay diff --git a/app/models/api_user.rb b/app/models/api_user.rb index bee04a954..ce32c4045 100644 --- a/app/models/api_user.rb +++ b/app/models/api_user.rb @@ -1,6 +1,6 @@ require 'open3' -class APIUser < User +class ApiUser < User include EppErrors def epp_code_map diff --git a/app/models/concerns/versions.rb b/app/models/concerns/versions.rb index 50ea935d2..5e2bad90c 100644 --- a/app/models/concerns/versions.rb +++ b/app/models/concerns/versions.rb @@ -34,7 +34,7 @@ module Versions end 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? user = AdminUser.find_by(id: $1) if str =~ /^(\d+)-AdminUser:/ unless user.present? diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 49049665c..749f5310c 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -490,7 +490,7 @@ class Epp::Domain < Domain def apply_pending_update! preclean_pendings - user = APIUser.find(pending_json['current_user_id']) + user = ApiUser.find(pending_json['current_user_id']) frame = Nokogiri::XML(pending_json['frame']) self.statuses.delete(DomainStatus::PENDING_UPDATE) diff --git a/app/views/admin/api_users/_form.haml b/app/views/admin/api_users/_form.haml index 722b98d0d..9a26b9fc8 100644 --- a/app/views/admin/api_users/_form.haml +++ b/app/views/admin/api_users/_form.haml @@ -38,7 +38,7 @@ = f.label :role, nil, class: 'required' .col-md-7 = 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' .checkbox %label{for: 'api_user_active'} diff --git a/app/views/admin/registrars/_users.html.erb b/app/views/admin/registrars/_users.html.erb index d85eaaf36..f182e4615 100644 --- a/app/views/admin/registrars/_users.html.erb +++ b/app/views/admin/registrars/_users.html.erb @@ -6,8 +6,8 @@ - - + + diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index b4a84b01d..b4eccb451 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -12,5 +12,4 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym 'DNS' - inflect.acronym 'API' end diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 1d83ec5ef..2fa67a827 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -131,7 +131,7 @@ namespace :import do ips = [] temp = [] - existing_ids = APIUser.pluck(:legacy_id) + existing_ids = ApiUser.pluck(:legacy_id) existing_ips = WhiteIp.pluck(:ipv4) Legacy::Registrar.all.each do |x| @@ -143,7 +143,7 @@ namespace :import do if y.try(:cert) != 'pki' if y.try(:cert) == 'idkaart' - id_users << APIUser.new({ + id_users << ApiUser.new({ username: y.try(:password) ? y.try(:password) : y.try(:password), password: ('a'..'z').to_a.shuffle.first(8).join, identity_code: y.try(:password) ? y.try(:password) : y.try(:password), @@ -152,7 +152,7 @@ namespace :import do legacy_id: y.try(:id) }) else - temp << APIUser.new({ + temp << ApiUser.new({ username: x.handle.try(:strip), 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), @@ -181,8 +181,8 @@ namespace :import do end end - APIUser.import id_users, validate: false - APIUser.import users, validate: false + ApiUser.import id_users, validate: false + ApiUser.import users, validate: false if ips WhiteIp.import ips, validate: false diff --git a/spec/factories/api_user.rb b/spec/factories/api_user.rb index 31355f141..a3f9623b6 100644 --- a/spec/factories/api_user.rb +++ b/spec/factories/api_user.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :api_user do sequence(:username) { |n| "test#{n}" } - password 'a' * APIUser.min_password_length + password 'a' * ApiUser.min_password_length roles ['super'] registrar diff --git a/spec/models/api_user_spec.rb b/spec/models/api_user_spec.rb index b710a05c9..89feeac6d 100644 --- a/spec/models/api_user_spec.rb +++ b/spec/models/api_user_spec.rb @@ -1,16 +1,16 @@ require 'rails_helper' -RSpec.describe APIUser do +RSpec.describe ApiUser do context 'with invalid attribute' do before do - @api_user = APIUser.new + @api_user = ApiUser.new end it 'should not be valid' do @api_user.valid? @api_user.errors.full_messages.should match_array([ "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", "Username Username is missing", "Roles is missing" diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 007b1e3de..6b282d651 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -316,10 +316,10 @@ RSpec.describe Domain do @api_user = create(:api_user) @user.id.should == 1 @api_user.id.should == 2 - ::PaperTrail.whodunnit = '2-APIUser: testuser' + ::PaperTrail.whodunnit = '2-ApiUser: testuser' @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_not == @user diff --git a/spec/presenters/user_presenter_spec.rb b/spec/presenters/user_presenter_spec.rb index c0cff114b..ba9e1673f 100644 --- a/spec/presenters/user_presenter_spec.rb +++ b/spec/presenters/user_presenter_spec.rb @@ -4,7 +4,7 @@ RSpec.describe UserPresenter do let(:presenter) { described_class.new(user: user, view: view) } describe '#login_with_role' do - let(:user) { instance_double(APIUser, + let(:user) { instance_double(ApiUser, login: 'login', roles: %w[role], registrar_name: 'registrar') } diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 9d3001959..5fd2dc925 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,7 +1,7 @@ api_bestnames: username: test_bestnames password: testtest - type: APIUser + type: ApiUser registrar: bestnames active: true roles: @@ -10,7 +10,7 @@ api_bestnames: api_goodnames: username: test_goodnames password: testtest - type: APIUser + type: ApiUser registrar: goodnames active: true roles: diff --git a/test/system/api/registrant/registrant_api_authentication_test.rb b/test/system/api/registrant/registrant_api_authentication_test.rb index 9ed518caa..94693ddd5 100644 --- a/test/system/api/registrant/registrant_api_authentication_test.rb +++ b/test/system/api/registrant/registrant_api_authentication_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class RegistrantAPIAuthenticationTest < ApplicationSystemTestCase +class RegistrantApiAuthenticationTest < ApplicationSystemTestCase def setup super diff --git a/test/system/api/registrant/registrant_api_domains_test.rb b/test/system/api/registrant/registrant_api_domains_test.rb index ab08b4ba2..da5813518 100644 --- a/test/system/api/registrant/registrant_api_domains_test.rb +++ b/test/system/api/registrant/registrant_api_domains_test.rb @@ -1,7 +1,7 @@ require 'test_helper' require 'auth_token/auth_token_creator' -class RegistrantAPIDomainsTest < ApplicationSystemTestCase +class RegistrantApiDomainsTest < ApplicationSystemTestCase def setup super
<%= APIUser.human_attribute_name :username %><%= APIUser.human_attribute_name :active %><%= ApiUser.human_attribute_name :username %><%= ApiUser.human_attribute_name :active %>