Add action AsymmetricKeysController#new
This commit is contained in:
parent
eae61994be
commit
ad7b6186f4
15 changed files with 88 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AsymmetricKeysController < ApplicationController
|
||||
before_action :set_asymmetric_key, except: :index
|
||||
before_action :set_asymmetric_key, except: %i[index new]
|
||||
|
||||
# GET /asymmetric_keys
|
||||
def index
|
||||
|
@ -21,6 +21,12 @@ class AsymmetricKeysController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# GET /asymmetric_keys/new
|
||||
def new
|
||||
@asymmetric_key_form = AsymmetricKeyForm.new
|
||||
authorize @asymmetric_key_form
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_asymmetric_key
|
||||
|
|
15
app/forms/asymmetric_key_form.rb
Normal file
15
app/forms/asymmetric_key_form.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AsymmetricKeyForm < ApplicationForm
|
||||
attribute :public_key_pem, :string
|
||||
|
||||
validates :public_key_pem, presence: true
|
||||
|
||||
def self.model_name
|
||||
ActiveModel::Name.new(self, nil, AsymmetricKey.name)
|
||||
end
|
||||
|
||||
def self.policy_class
|
||||
'AsymmetricKeyPolicy'
|
||||
end
|
||||
end
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class EcurveKey < AsymmetricKey
|
||||
ALGO_CLASS = 'Elliptic curve'
|
||||
CURVES = %w[prime256v1 secp384r1].freeze
|
||||
|
||||
###############
|
||||
|
@ -16,7 +17,7 @@ class EcurveKey < AsymmetricKey
|
|||
###########
|
||||
|
||||
def algo_class
|
||||
'Elliptic curve'
|
||||
ALGO_CLASS
|
||||
end
|
||||
|
||||
def algo_variant
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RSAKey < AsymmetricKey
|
||||
ALGO_CLASS = 'RSA'
|
||||
BITS = [2048, 4096].freeze
|
||||
|
||||
###############
|
||||
|
@ -16,7 +17,7 @@ class RSAKey < AsymmetricKey
|
|||
###########
|
||||
|
||||
def algo_class
|
||||
'RSA'
|
||||
ALGO_CLASS
|
||||
end
|
||||
|
||||
def algo_variant
|
||||
|
|
|
@ -9,6 +9,10 @@ class AsymmetricKeyPolicy < ApplicationPolicy
|
|||
true
|
||||
end
|
||||
|
||||
def new?
|
||||
true
|
||||
end
|
||||
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
scope.all
|
||||
|
|
|
@ -1,7 +1,20 @@
|
|||
<div class="container">
|
||||
<%= nav_breadcrumb AsymmetricKey.model_name.human count: 0 %>
|
||||
|
||||
<%= render partial: 'table',
|
||||
locals: { asymmetric_keys: @asymmetric_keys } %>
|
||||
<%= pagination @asymmetric_keys %>
|
||||
<% if policy(AsymmetricKey).new? %>
|
||||
<div class="btn-group" role="group">
|
||||
<% if policy(AsymmetricKey).new? %>
|
||||
<%= link_to translate(:add_existing),
|
||||
new_asymmetric_key_path,
|
||||
class: 'btn btn-primary',
|
||||
role: :button %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="mt-3">
|
||||
<%= render partial: 'table',
|
||||
locals: { asymmetric_keys: @asymmetric_keys } %>
|
||||
<%= pagination @asymmetric_keys %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
14
app/views/asymmetric_keys/new.html.erb
Normal file
14
app/views/asymmetric_keys/new.html.erb
Normal file
|
@ -0,0 +1,14 @@
|
|||
<div class="container">
|
||||
<%= nav_breadcrumb(
|
||||
[AsymmetricKey.model_name.human(count: 0), asymmetric_keys_path],
|
||||
translate(:add_existing),
|
||||
) %>
|
||||
|
||||
<%= simple_form_for @asymmetric_key_form do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<%= f.input :public_key_pem, as: :text %>
|
||||
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
</div>
|
|
@ -1,6 +1,8 @@
|
|||
en:
|
||||
activemodel:
|
||||
attributes:
|
||||
asymmetric_key:
|
||||
public_key_pem: Public key in PEM format
|
||||
x509_certificate:
|
||||
distinguished_name: Distinguished name
|
||||
not_before: Active since
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
ru:
|
||||
activemodel:
|
||||
attributes:
|
||||
asymmetric_key:
|
||||
public_key_pem: Публичный ключ в формате PEM
|
||||
x509_certificate:
|
||||
distinguished_name: Уникальное имя (distinguished name)
|
||||
not_before: Активен с
|
||||
|
|
|
@ -11,6 +11,8 @@ en:
|
|||
display_entries: 'Displaying %{entry_name}
|
||||
<b>%{first} - %{last}</b> of <b>%{total}</b> in total'
|
||||
submit:
|
||||
asymmetric_key:
|
||||
create: Add
|
||||
person:
|
||||
create: Send
|
||||
person_comment:
|
||||
|
|
|
@ -11,6 +11,8 @@ ru:
|
|||
display_entries: 'Отображение %{entry_name}
|
||||
<b>%{first} - %{last}</b> из <b>%{total}</b> всего'
|
||||
submit:
|
||||
asymmetric_key:
|
||||
create: Добавить
|
||||
person:
|
||||
create: Отправить
|
||||
person_comment:
|
||||
|
|
|
@ -12,3 +12,4 @@ en:
|
|||
save: Save
|
||||
hello: Hello
|
||||
new_sign_in: New sign in to your account
|
||||
add_existing: Add existing
|
||||
|
|
|
@ -12,3 +12,4 @@ ru:
|
|||
save: Сохранить
|
||||
hello: Здравствуйте
|
||||
new_sign_in: Произведён вход в ваш аккаунт
|
||||
add_existing: Добавить существующий
|
||||
|
|
|
@ -13,7 +13,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :federal_subjects, param: :number, only: %i[index show]
|
||||
|
||||
resources :asymmetric_keys, only: %i[index show] do
|
||||
resources :asymmetric_keys, only: %i[index show new] do
|
||||
resource :private_key, only: :show
|
||||
end
|
||||
|
||||
|
|
17
spec/requests/asymmetric_keys/new_spec.rb
Normal file
17
spec/requests/asymmetric_keys/new_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /asymmetric_keys/new' do
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
|
||||
get '/asymmetric_keys/new'
|
||||
end
|
||||
|
||||
for_account_types nil, :usual, :superuser do
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
Reference in a new issue