1
0
Fork 0

Add action AsymmetricKeysController#new

This commit is contained in:
Alex Kotov 2019-09-15 06:38:32 +05:00
parent eae61994be
commit ad7b6186f4
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
15 changed files with 88 additions and 7 deletions

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class AsymmetricKeysController < ApplicationController class AsymmetricKeysController < ApplicationController
before_action :set_asymmetric_key, except: :index before_action :set_asymmetric_key, except: %i[index new]
# GET /asymmetric_keys # GET /asymmetric_keys
def index def index
@ -21,6 +21,12 @@ class AsymmetricKeysController < ApplicationController
end end
end end
# GET /asymmetric_keys/new
def new
@asymmetric_key_form = AsymmetricKeyForm.new
authorize @asymmetric_key_form
end
private private
def set_asymmetric_key def set_asymmetric_key

View 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

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class EcurveKey < AsymmetricKey class EcurveKey < AsymmetricKey
ALGO_CLASS = 'Elliptic curve'
CURVES = %w[prime256v1 secp384r1].freeze CURVES = %w[prime256v1 secp384r1].freeze
############### ###############
@ -16,7 +17,7 @@ class EcurveKey < AsymmetricKey
########### ###########
def algo_class def algo_class
'Elliptic curve' ALGO_CLASS
end end
def algo_variant def algo_variant

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class RSAKey < AsymmetricKey class RSAKey < AsymmetricKey
ALGO_CLASS = 'RSA'
BITS = [2048, 4096].freeze BITS = [2048, 4096].freeze
############### ###############
@ -16,7 +17,7 @@ class RSAKey < AsymmetricKey
########### ###########
def algo_class def algo_class
'RSA' ALGO_CLASS
end end
def algo_variant def algo_variant

View file

@ -9,6 +9,10 @@ class AsymmetricKeyPolicy < ApplicationPolicy
true true
end end
def new?
true
end
class Scope < Scope class Scope < Scope
def resolve def resolve
scope.all scope.all

View file

@ -1,7 +1,20 @@
<div class="container"> <div class="container">
<%= nav_breadcrumb AsymmetricKey.model_name.human count: 0 %> <%= nav_breadcrumb AsymmetricKey.model_name.human count: 0 %>
<%= render partial: 'table', <% if policy(AsymmetricKey).new? %>
locals: { asymmetric_keys: @asymmetric_keys } %> <div class="btn-group" role="group">
<%= pagination @asymmetric_keys %> <% 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> </div>

View 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>

View file

@ -1,6 +1,8 @@
en: en:
activemodel: activemodel:
attributes: attributes:
asymmetric_key:
public_key_pem: Public key in PEM format
x509_certificate: x509_certificate:
distinguished_name: Distinguished name distinguished_name: Distinguished name
not_before: Active since not_before: Active since

View file

@ -1,6 +1,8 @@
ru: ru:
activemodel: activemodel:
attributes: attributes:
asymmetric_key:
public_key_pem: Публичный ключ в формате PEM
x509_certificate: x509_certificate:
distinguished_name: Уникальное имя (distinguished name) distinguished_name: Уникальное имя (distinguished name)
not_before: Активен с not_before: Активен с

View file

@ -11,6 +11,8 @@ en:
display_entries: 'Displaying %{entry_name} display_entries: 'Displaying %{entry_name}
<b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total' <b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total'
submit: submit:
asymmetric_key:
create: Add
person: person:
create: Send create: Send
person_comment: person_comment:

View file

@ -11,6 +11,8 @@ ru:
display_entries: 'Отображение %{entry_name} display_entries: 'Отображение %{entry_name}
<b>%{first}&nbsp;-&nbsp;%{last}</b> из <b>%{total}</b> всего' <b>%{first}&nbsp;-&nbsp;%{last}</b> из <b>%{total}</b> всего'
submit: submit:
asymmetric_key:
create: Добавить
person: person:
create: Отправить create: Отправить
person_comment: person_comment:

View file

@ -12,3 +12,4 @@ en:
save: Save save: Save
hello: Hello hello: Hello
new_sign_in: New sign in to your account new_sign_in: New sign in to your account
add_existing: Add existing

View file

@ -12,3 +12,4 @@ ru:
save: Сохранить save: Сохранить
hello: Здравствуйте hello: Здравствуйте
new_sign_in: Произведён вход в ваш аккаунт new_sign_in: Произведён вход в ваш аккаунт
add_existing: Добавить существующий

View file

@ -13,7 +13,7 @@ Rails.application.routes.draw do
resources :federal_subjects, param: :number, only: %i[index show] 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 resource :private_key, only: :show
end end

View 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