Pass registrar in URL instead of POST params

This commit is contained in:
Artur Beljajev 2019-12-09 20:53:58 +02:00
parent 044bf9caad
commit 3c5c0c4310
5 changed files with 10 additions and 35 deletions

View file

@ -47,12 +47,6 @@ class @Autocomplete
selector: '.js-contact-typeahead' selector: '.js-contact-typeahead'
hiddenSelector: '.js-contact-id' hiddenSelector: '.js-contact-id'
@bindAdminRegistrarSearch: ->
Autocomplete.bindTypeahead
remote: '/admin/registrars/search'
selector: '.js-registrar-typeahead'
hiddenSelector: '.js-registrar-id'
@bindClientContactSearch: -> @bindClientContactSearch: ->
Autocomplete.bindTypeahead Autocomplete.bindTypeahead
remote: '/client/contacts/search' remote: '/client/contacts/search'

View file

@ -2,6 +2,7 @@ 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]
before_action :find_registrar, only: %i[new create]
def index def index
@q = ApiUser.includes(:registrar).search(params[:q]) @q = ApiUser.includes(:registrar).search(params[:q])
@ -9,12 +10,11 @@ module Admin
end end
def new def new
@registrar = Registrar.find_by(id: params[:registrar_id]) @api_user = ApiUser.new
@api_user = ApiUser.new(registrar: @registrar)
end end
def create def create
@api_user = ApiUser.new(api_user_params) @api_user = @registrar.api_users.build(api_user_params)
if @api_user.save if @api_user.save
flash[:notice] = I18n.t('record_created') flash[:notice] = I18n.t('record_created')
@ -63,8 +63,11 @@ module Admin
def api_user_params def api_user_params
params.require(:api_user).permit(:username, :plain_text_password, :active, params.require(:api_user).permit(:username, :plain_text_password, :active,
:registrar_id, :registrar_typeahead,
:identity_code, { roles: [] }) :identity_code, { roles: [] })
end end
def find_registrar
@registrar = Registrar.find(params[:registrar_id])
end
end end
end end

View file

@ -28,7 +28,6 @@ class ApiUser < User
delegate :code, :name, to: :registrar, prefix: true delegate :code, :name, to: :registrar, prefix: true
alias_attribute :login, :username alias_attribute :login, :username
attr_accessor :registrar_typeahead
SUPER = 'super' SUPER = 'super'
EPP = 'epp' EPP = 'epp'
@ -53,10 +52,6 @@ class ApiUser < User
end end
end end
def registrar_typeahead
@registrar_typeahead || registrar || nil
end
def to_s def to_s
username username
end end

View file

@ -1,4 +1,4 @@
= form_for([:admin, @api_user], html: {class: 'form-horizontal', autocomplete: 'off'}) do |f| = form_for([:admin, @registrar, @api_user], html: {class: 'form-horizontal', autocomplete: 'off'}) do |f|
= render 'shared/full_errors', object: @api_user = render 'shared/full_errors', object: @api_user
.row .row
@ -20,18 +20,6 @@
.col-md-7 .col-md-7
= f.text_field(:identity_code, class: 'form-control') = f.text_field(:identity_code, class: 'form-control')
.form-group
.form-group.has-feedback.js-typeahead-container
.col-md-4.control-label
= f.label :registrar_typeahead, t(:registrar_name), class: 'required'
.col-md-7
= f.text_field(:registrar_typeahead,
class: 'form-control js-registrar-typeahead typeahead required',
placeholder: t(:registrar_name), autocomplete: 'off')
%span.glyphicon.glyphicon-ok.form-control-feedback.js-typeahead-ok.hidden
%span.glyphicon.glyphicon-remove.form-control-feedback.js-typeahead-remove
= f.hidden_field(:registrar_id, class: 'js-registrar-id')
.form-group .form-group
.col-md-4.control-label .col-md-4.control-label
= f.label :role, nil, class: 'required' = f.label :role, nil, class: 'required'
@ -49,8 +37,3 @@
.row .row
.col-md-8.text-right .col-md-8.text-right
= button_tag(t(:save), class: 'btn btn-primary') = button_tag(t(:save), class: 'btn btn-primary')
:javascript
window.addEventListener('load', function() {
Autocomplete.bindAdminRegistrarSearch();
});

View file

@ -259,7 +259,7 @@ Rails.application.routes.draw do
end end
resources :registrars do resources :registrars do
resources :api_users, except: %i[create show edit update destroy] resources :api_users, except: %i[show edit update destroy]
resources :white_ips resources :white_ips
end end
@ -270,7 +270,7 @@ Rails.application.routes.draw do
end end
resources :admin_users resources :admin_users
resources :api_users, except: %i[new] do resources :api_users, except: %i[new create] do
resources :certificates do resources :certificates do
member do member do
post 'sign' post 'sign'