feat: add new view and controller to display app configs together (#3563)
fixes: #3578
This commit is contained in:
21
app/controllers/super_admin/app_configs_controller.rb
Normal file
21
app/controllers/super_admin/app_configs_controller.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class SuperAdmin::AppConfigsController < SuperAdmin::ApplicationController
|
||||
def show
|
||||
@allowed_configs = %w[FB_APP_ID FB_VERIFY_TOKEN FB_APP_SECRET]
|
||||
# ref: https://github.com/rubocop/rubocop/issues/7767
|
||||
# rubocop:disable Style/HashTransformValues
|
||||
@fb_config = InstallationConfig.where(name: @allowed_configs)
|
||||
.pluck(:name, :serialized_value)
|
||||
.map { |name, serialized_value| [name, serialized_value['value']] }
|
||||
.to_h
|
||||
# rubocop:enable Style/HashTransformValues
|
||||
end
|
||||
|
||||
def create
|
||||
params['app_config'].each do |key, value|
|
||||
i = InstallationConfig.where(name: key).first_or_create(value: value, locked: false)
|
||||
i.value = value
|
||||
i.save!
|
||||
end
|
||||
redirect_to super_admin_app_config_url
|
||||
end
|
||||
end
|
||||
25
app/views/super_admin/app_configs/show.html.erb
Normal file
25
app/views/super_admin/app_configs/show.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<% content_for(:title) do %>
|
||||
App Config
|
||||
<% end %>
|
||||
<header class="main-content__header" role="banner">
|
||||
<h1 class="main-content__page-title" id="page-title">
|
||||
<%= content_for(:title) %>
|
||||
</h1>
|
||||
</header>
|
||||
<section class="main-content__body">
|
||||
<%= form_with url: super_admin_app_config_url , method: :post do |form| %>
|
||||
<% @allowed_configs.each do |c| %>
|
||||
<div class="field-unit">
|
||||
<div class="field-unit__label">
|
||||
<%= form.label "app_config[#{c}]", c %>
|
||||
</div>
|
||||
<div class="field-unit__field">
|
||||
<%= form.text_field "app_config[#{c}]", value: @fb_config[c] %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-actions">
|
||||
<%= form.submit "Submit" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</section>
|
||||
@@ -32,8 +32,14 @@ as defined by the routes in the `admin/` namespace
|
||||
<i class="ion ion-ios-keypad"></i>
|
||||
<%= link_to "Dashboard", super_admin_root_url %>
|
||||
</li>
|
||||
|
||||
<li class="navigation__link">
|
||||
<i class="ion ion-android-settings"></i>
|
||||
<%= link_to "App Config", super_admin_app_config_url %>
|
||||
</li>
|
||||
|
||||
<% Administrate::Namespace.new(namespace).resources.each do |resource| %>
|
||||
<% next if ["account_users", "agent_bots", "dashboard", "devise/sessions"].include? resource.resource %>
|
||||
<% next if ["account_users", "agent_bots", "dashboard", "devise/sessions", "app_configs" ].include? resource.resource %>
|
||||
<li class="navigation__link navigation__link--<%= nav_link_state(resource) %>">
|
||||
<i class="<%= sidebar_icons[resource.resource.to_sym] %>"></i>
|
||||
<%= link_to(
|
||||
|
||||
@@ -295,6 +295,8 @@ Rails.application.routes.draw do
|
||||
namespace :super_admin do
|
||||
root to: 'dashboard#index'
|
||||
|
||||
resource :app_config, only: [:show, :create]
|
||||
|
||||
# order of resources affect the order of sidebar navigation in super admin
|
||||
resources :accounts
|
||||
resources :users, only: [:index, :new, :create, :show, :edit, :update]
|
||||
|
||||
47
spec/controllers/super_admin/app_config_controller_spec.rb
Normal file
47
spec/controllers/super_admin/app_config_controller_spec.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Super Admin Application Config API', type: :request do
|
||||
let(:super_admin) { create(:super_admin) }
|
||||
|
||||
describe 'GET /super_admin/app_config' do
|
||||
context 'when it is an unauthenticated super admin' do
|
||||
it 'returns unauthorized' do
|
||||
get '/super_admin/app_config'
|
||||
expect(response).to have_http_status(:redirect)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated super admin' do
|
||||
let!(:config) { create(:installation_config, { name: 'FB_APP_ID', value: 'TESTVALUE' }) }
|
||||
|
||||
it 'shows the app_config page' do
|
||||
sign_in super_admin
|
||||
get '/super_admin/app_config'
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(config.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /super_admin/app_config' do
|
||||
context 'when it is an unauthenticated super admin' do
|
||||
it 'returns unauthorized' do
|
||||
post '/super_admin/app_config', params: { app_config: { TESTKEY: 'TESTVALUE' } }
|
||||
expect(response).to have_http_status(:redirect)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an aunthenticated super admin' do
|
||||
it 'shows the app_config page' do
|
||||
sign_in super_admin
|
||||
post '/super_admin/app_config', params: { app_config: { TESTKEY: 'TESTVALUE' } }
|
||||
|
||||
expect(response.status).to eq(302)
|
||||
expect(response).should redirect_to(super_admin_app_config_path)
|
||||
|
||||
config = GlobalConfig.get('TESTKEY')
|
||||
expect(config['TESTKEY']).to eq('TESTVALUE')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user