Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

## Ruby

You have to use Ruby version 3.3.9 with installed bundler.
You have to use Ruby version 4.0.6 with installed bundler.

## Postgresql

Expand Down
4 changes: 2 additions & 2 deletions app/admin/equipment/gateways.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ def resource_params
f.input :contact_user

if f.object.external_id.nil? || authorized?(:allow_incoming_auth_credentials)
f.input :incoming_auth_username, hint: "#{link_to('Сlick to fill random username', 'javascript:void(0)', onclick: 'generateCredential(this)')}. #{t('formtastic.hints.gateway.incoming_auth_username')}".html_safe
f.input :incoming_auth_password, as: :string, input_html: { autocomplete: 'off' }, hint: link_to('Сlick to fill random password', 'javascript:void(0)', onclick: 'generateCredential(this)')
f.input :incoming_auth_username, hint: "#{link_to('Click to fill random username', '#', data: { generate_credential: '' })}. #{t('formtastic.hints.gateway.incoming_auth_username')}".html_safe
f.input :incoming_auth_password, as: :string, input_html: { autocomplete: 'off' }, hint: link_to('Click to fill random password', '#', data: { generate_credential: '' })
end

f.input :incoming_auth_allow_jwt
Expand Down
4 changes: 2 additions & 2 deletions app/admin/system/api_accesses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
f.semantic_errors *f.object.errors.attribute_names

f.inputs do
f.input :login, hint: link_to('Сlick to fill random login', 'javascript:void(0)', onclick: 'generateCredential(this)')
f.input :password, as: :string, hint: link_to('Сlick to fill random password', 'javascript:void(0)', onclick: 'generateCredential(this)')
f.input :login, hint: link_to('Click to fill random login', '#', data: { generate_credential: '' })
f.input :password, as: :string, hint: link_to('Click to fill random password', '#', data: { generate_credential: '' })
f.contractor_input :customer_id, label: 'Customer'
f.account_input :account_ids,
multiple: true,
Expand Down
13 changes: 13 additions & 0 deletions app/assets/javascripts/credential_generator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Fills an input with a random credential. The "click to fill random ..." hint
// links opt in with a `data-generate-credential` attribute (optionally carrying a
// length) and are bound by the delegated handler below rather than an inline
// onclick=, so the admin runs under a Content-Security-Policy without
// `script-src 'unsafe-inline'` — see also chart_init.js.
function generateCredential(target, length) {
if (!$(target).is('input')) { target = $(target).closest('li[id$=input]').find('input')[0]; }
if (typeof(target) === 'undefined' || target.length === 0) return;
Expand All @@ -13,3 +18,11 @@ function generateCredential(target, length) {

$(target).val(credential);
}

// Delegated: the hint links live inside formtastic inputs that are re-rendered
// (and, on the gateway form, revealed) after page load.
$(document).on('click', '[data-generate-credential]', function (e) {
e.preventDefault();
var length = parseInt($(this).data('generateCredential'), 10);
generateCredential(this, isNaN(length) ? undefined : length);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::RoutingPlanStaticRoutesController < Api::Rest::Admin::BaseController
end
7 changes: 7 additions & 0 deletions app/resources/api/rest/admin/routing_plan_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class Api::Rest::Admin::RoutingPlanResource < BaseResource
relation_name: :routing_groups,
foreign_key_on: :related

# read-only: routing_plan_id is NOT NULL, so static routes can only be
# (re)assigned from the routing-plan-static-routes endpoint
has_many :static_routes, class_name: 'RoutingPlanStaticRoute',
exclude_links: %i[default self],
relation_name: :static_routes,
foreign_key_on: :related
Comment on lines +15 to +20

filter :name # DEPRECATED in favor of name_eq

ransack_filter :name, type: :string
Expand Down
34 changes: 34 additions & 0 deletions app/resources/api/rest/admin/routing_plan_static_route_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

class Api::Rest::Admin::RoutingPlanStaticRouteResource < BaseResource
model_name 'Routing::RoutingPlanStaticRoute'

paginator :paged

# network_prefix_id is detected from prefix by Yeti::NetworkDetector, so it is read-only
attributes :prefix, :priority, :weight, :network_prefix_id

has_one :routing_plan, class_name: 'RoutingPlan', always_include_linkage_data: true
has_one :vendor, class_name: 'Contractor', always_include_linkage_data: true

ransack_filter :prefix, type: :string
ransack_filter :priority, type: :number
ransack_filter :weight, type: :number
ransack_filter :routing_plan_id, type: :number
ransack_filter :vendor_id, type: :number
ransack_filter :network_prefix_id, type: :number

def self.updatable_fields(_context)
%i[
prefix
priority
weight
routing_plan
vendor
]
end

def self.creatable_fields(context)
updatable_fields(context)
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def dasherized_resource(name, options = {}, &block)
jsonapi_resources :payments, except: %i[update destroy]

jsonapi_resources :routing_plans
jsonapi_resources :routing_plan_static_routes
jsonapi_resources :codec_groups

jsonapi_resources :disconnect_policies
Expand Down
69 changes: 69 additions & 0 deletions spec/acceptance/rest/admin/api/routing_plan_static_routes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

require 'rspec_api_documentation/dsl'

RSpec.resource 'Routing plan static routes' do
include_context :acceptance_admin_user
let(:type) { 'routing-plan-static-routes' }

required_params = %i[prefix]
optional_params = %i[priority weight]
required_relationships = %i[routing-plan vendor]

get '/api/rest/admin/routing-plan-static-routes' do
jsonapi_filters Api::Rest::Admin::RoutingPlanStaticRouteResource._allowed_filters

before { create_list(:routing_plan_static_route, 2) }

example_request 'get listing' do
expect(status).to eq(200)
end
end

get '/api/rest/admin/routing-plan-static-routes/:id' do
let(:id) { create(:routing_plan_static_route).id }

example_request 'get specific entry' do
expect(status).to eq(200)
end
end

post '/api/rest/admin/routing-plan-static-routes' do
parameter :type, 'Resource type (routing-plan-static-routes)', scope: :data, required: true

jsonapi_attributes(required_params, optional_params)
jsonapi_relationships(required_relationships, [])

let(:prefix) { '1234' }
let(:priority) { 100 }
let(:weight) { 100 }
let(:'routing-plan') { wrap_relationship(:routing_plans, create(:routing_plan, :with_static_routes).id) }
let(:vendor) { wrap_relationship(:contractors, create(:vendor).id) }

example_request 'create new entry' do
expect(status).to eq(201)
end
end

put '/api/rest/admin/routing-plan-static-routes/:id' do
parameter :type, 'Resource type (routing-plan-static-routes)', scope: :data, required: true
parameter :id, 'Routing plan static route ID', scope: :data, required: true

jsonapi_attributes(required_params, optional_params)

let(:id) { create(:routing_plan_static_route).id }
let(:prefix) { '5678' }

example_request 'update values' do
expect(status).to eq(200)
end
end

delete '/api/rest/admin/routing-plan-static-routes/:id' do
let(:id) { create(:routing_plan_static_route).id }

example_request 'delete entry' do
expect(status).to eq(204)
end
end
end
8 changes: 4 additions & 4 deletions spec/features/equipment/gateways/edit_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
it 'should generate new credential by click on the link in hint for :incoming_auth_username with 20 chars' do
subject

click_link('Сlick to fill random username')
click_link('Click to fill random username')
incoming_auth_username = find_field('gateway_incoming_auth_username')
expect(incoming_auth_username).to be_present
expect(incoming_auth_username.value).to be_present
Expand All @@ -51,7 +51,7 @@
it 'should generate new credential by click on the link in hint for :incoming_auth_password with 20 chars' do
subject

click_link('Сlick to fill random password')
click_link('Click to fill random password')
incoming_auth_password = find_field('gateway_incoming_auth_password')
expect(incoming_auth_password).to be_present
expect(incoming_auth_password.value).to be_present
Expand Down Expand Up @@ -82,7 +82,7 @@
it 'should generate new credential by click on the link in hint for :incoming_auth_username with 20 chars' do
subject

click_link('Сlick to fill random username')
click_link('Click to fill random username')
incoming_auth_username = find_field('gateway_incoming_auth_username')
expect(incoming_auth_username).to be_present
expect(incoming_auth_username.value).to be_present
Expand All @@ -94,7 +94,7 @@
it 'should generate new credential by click on the link in hint for :incoming_auth_password with 20 chars' do
subject

click_link('Сlick to fill random password')
click_link('Click to fill random password')
incoming_auth_password = find_field('gateway_incoming_auth_password')
expect(incoming_auth_password).to be_present
expect(incoming_auth_password.value).to be_present
Expand Down
8 changes: 4 additions & 4 deletions spec/features/equipment/gateways/new_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
it 'should generate new credential by click on the link in hint for :incoming_auth_username with 20 chars' do
subject

click_link('Сlick to fill random username')
click_link('Click to fill random username')
incoming_auth_username = find_field('gateway_incoming_auth_username')
expect(incoming_auth_username).to be_present
expect(incoming_auth_username.value).to be_present
Expand All @@ -105,7 +105,7 @@
it 'should generate new credential by click on the link in hint for :incoming_auth_password with 20 chars' do
subject

click_link('Сlick to fill random password')
click_link('Click to fill random password')
incoming_auth_password = find_field('gateway_incoming_auth_password')
expect(incoming_auth_password).to be_present
expect(incoming_auth_password.value).to be_present
Expand Down Expand Up @@ -142,7 +142,7 @@
it 'should generate new credential by click on the link in hint for :incoming_auth_username with 20 chars' do
subject

click_link('Сlick to fill random username')
click_link('Click to fill random username')
incoming_auth_username = find_field('gateway_incoming_auth_username')
expect(incoming_auth_username).to be_present
expect(incoming_auth_username.value).to be_present
Expand All @@ -154,7 +154,7 @@
it 'should generate new credential by click on the link in hint for :incoming_auth_password with 20 chars' do
subject

click_link('Сlick to fill random password')
click_link('Click to fill random password')
incoming_auth_password = find_field('gateway_incoming_auth_password')
expect(incoming_auth_password).to be_present
expect(incoming_auth_password.value).to be_present
Expand Down
4 changes: 2 additions & 2 deletions spec/features/system/api_accesses/edit_api_access_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
let!(:api_access) { FactoryBot.create(:api_access, attributes) }

it 'should generate new credential by click on the link in hint for :login with 20 chars' do
click_link('Сlick to fill random login')
click_link('Click to fill random login')
login = find_field('system_api_access_login')
expect(login).to be_present
expect(login.value).to be_present
Expand All @@ -31,7 +31,7 @@
end

it 'should generate new credential by click on the link in hint for :password with 20 chars' do
click_link('Сlick to fill random password')
click_link('Click to fill random password')
password = find_field('system_api_access_password')
expect(password).to be_present
expect(password.value).to be_present
Expand Down
8 changes: 4 additions & 4 deletions spec/features/system/api_accesses/new_api_access_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

context 'when credentials is empty' do
it 'should generate new credential by click on the link in hint for :login with 20 chars' do
click_link('Сlick to fill random login')
click_link('Click to fill random login')
login = find_field('system_api_access_login')
expect(login).to be_present
expect(login.value).to be_present
Expand All @@ -53,7 +53,7 @@
end

it 'should generate new credential by click on the link in hint for :password with 20 chars' do
click_link('Сlick to fill random password')
click_link('Click to fill random password')
password = find_field('system_api_access_password')
expect(password).to be_present
expect(password.value).to be_present
Expand Down Expand Up @@ -81,7 +81,7 @@
end

it 'should generate new credential by click on the link in hint for :login with 20 chars' do
click_link('Сlick to fill random login')
click_link('Click to fill random login')
login = find_field('system_api_access_login')
expect(login).to be_present
expect(login.value).to be_present
Expand All @@ -91,7 +91,7 @@
end

it 'should generate new credential by click on the link in hint for :password with 20 chars' do
click_link('Сlick to fill random password')
click_link('Click to fill random password')
password = find_field('system_api_access_password')
expect(password).to be_present
expect(password.value).to be_present
Expand Down
Loading
Loading