Use BaseController in admin

This commit is contained in:
Artur Beljajev 2017-08-22 01:17:50 +03:00
parent cee4c84edd
commit a63b989cd6
36 changed files with 1265 additions and 1215 deletions

View file

@ -1,4 +1,5 @@
class Admin::AccountActivitiesController < AdminController
module Admin
class AccountActivitiesController < BaseController
load_and_authorize_resource
before_action :set_default_dates, only: [:index]
@ -57,4 +58,5 @@ class Admin::AccountActivitiesController < AdminController
end
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::AdminUsersController < AdminController
module Admin
class AdminUsersController < BaseController
load_and_authorize_resource
before_action :set_user, only: [:show, :edit, :update, :destroy]
@ -11,9 +12,11 @@ class Admin::AdminUsersController < AdminController
@admin_user = AdminUser.new
end
def show; end
def show;
end
def edit; end
def edit;
end
def create
@admin_user = AdminUser.new(admin_user_params)
@ -60,4 +63,5 @@ class Admin::AdminUsersController < AdminController
params.require(:admin_user).permit(:username,
:password, :password_confirmation, :identity_code, :email, :country_code, { roles: [] })
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::ApiUsersController < AdminController
module Admin
class ApiUsersController < BaseController
load_and_authorize_resource
before_action :set_api_user, only: [:show, :edit, :update, :destroy]
@ -24,9 +25,11 @@ class Admin::ApiUsersController < AdminController
end
end
def show; end
def show;
end
def edit; end
def edit;
end
def update
params[:api_user].delete(:password) if params[:api_user][:password].blank?
@ -60,4 +63,5 @@ class Admin::ApiUsersController < AdminController
:registrar_id, :registrar_typeahead,
:identity_code, { roles: [] })
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::BankStatementsController < AdminController
module Admin
class BankStatementsController < BaseController
load_and_authorize_resource
before_action :set_bank_statement, only: [:show, :download_import_file, :bind_invoices]
@ -84,4 +85,5 @@ class Admin::BankStatementsController < AdminController
:description, :sum, :currency, :reference_no, :paid_at
])
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::BankTransactionsController < AdminController
module Admin
class BankTransactionsController < BaseController
load_and_authorize_resource
def new
@ -51,4 +52,5 @@ class Admin::BankTransactionsController < AdminController
:buyer_name, :currency, :paid_at
)
end
end
end

View file

@ -0,0 +1,10 @@
module Admin
class BaseController < ApplicationController
before_action :authenticate_user!
helper_method :head_title_sufix
def head_title_sufix
t(:admin_head_title_sufix)
end
end
end

View file

@ -1,6 +1,6 @@
module Admin
module Billing
class PricesController < AdminController
class PricesController < BaseController
authorize_resource(class: 'Billing::Price')
before_action :load_price, only: %i[edit update expire]
helper_method :zones

View file

@ -1,4 +1,5 @@
class Admin::BlockedDomainsController < AdminController
module Admin
class BlockedDomainsController < BaseController
load_and_authorize_resource
def index
@ -52,4 +53,5 @@ class Admin::BlockedDomainsController < AdminController
def set_domain
@domain = BlockedDomain.find(params[:id])
end
end
end

View file

@ -1,8 +1,10 @@
class Admin::CertificatesController < AdminController
module Admin
class CertificatesController < BaseController
load_and_authorize_resource
before_action :set_certificate, :set_api_user, only: [:sign, :show, :download_csr, :download_crt, :revoke, :destroy]
def show; end
def show;
end
def new
@api_user = ApiUser.find(params[:api_user_id])
@ -81,4 +83,5 @@ class Admin::CertificatesController < AdminController
{}
end
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::ContactVersionsController < AdminController
module Admin
class ContactVersionsController < BaseController
load_and_authorize_resource
def index
@ -52,5 +53,5 @@ class Admin::ContactVersionsController < AdminController
def create_where_string(key, value)
" AND object->>'#{key}' ~* '#{value}'"
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::ContactsController < AdminController
module Admin
class ContactsController < BaseController
load_and_authorize_resource
before_action :set_contact, only: [:show]
@ -78,4 +79,5 @@ class Admin::ContactsController < AdminController
params[:q][:created_at_lteq] = ca_cache
end
end
end

View file

@ -1,7 +1,9 @@
class Admin::DashboardsController < AdminController
module Admin
class DashboardsController < BaseController
authorize_resource class: false
def show
redirect_to [:admin, :domains] if can? :show, Domain
end
end
end

View file

@ -1,7 +1,9 @@
class Admin::DelayedJobsController < AdminController
module Admin
class DelayedJobsController < BaseController
authorize_resource class: false
def index
@jobs = Delayed::Job.all
end
end
end

View file

@ -1,6 +1,6 @@
module Admin
module DNS
class ZonesController < AdminController
class ZonesController < BaseController
authorize_resource(class: 'DNS::Zone')
before_action :load_zone, only: %i[edit update destroy]

View file

@ -1,4 +1,5 @@
class Admin::DomainVersionsController < AdminController
module Admin
class DomainVersionsController < BaseController
load_and_authorize_resource
def index
@ -70,6 +71,5 @@ class Admin::DomainVersionsController < AdminController
def create_where_string(key, value)
" AND object->>'#{key}' ~* '#{value}'"
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::DomainsController < AdminController
module Admin
class DomainsController < BaseController
load_and_authorize_resource
before_action :set_domain, only: [:show, :edit, :update, :zonefile]
helper_method :force_delete_templates
@ -33,6 +34,7 @@ class Admin::DomainsController < AdminController
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
# rubocop: enable Metrics/AbcSize
@ -83,7 +85,7 @@ class Admin::DomainsController < AdminController
end
def versions
@domain = Domain.where(id: params[:domain_id]).includes({versions: :item}).first
@domain = Domain.where(id: params[:domain_id]).includes({ versions: :item }).first
@versions = @domain.versions
end
@ -130,4 +132,5 @@ class Admin::DomainsController < AdminController
def force_delete_templates
%w(removed_company death)
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::EppLogsController < AdminController
module Admin
class EppLogsController < BaseController
load_and_authorize_resource class: ApiLog::EppLog
before_action :set_default_dates, only: [:index]
@ -30,4 +31,5 @@ class Admin::EppLogsController < AdminController
end
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::InvoicesController < AdminController
module Admin
class InvoicesController < BaseController
load_and_authorize_resource
before_action :set_invoice, only: [:forward, :download_pdf]
@ -70,4 +71,5 @@ class Admin::InvoicesController < AdminController
def set_invoice
@invoice = Invoice.find(params[:invoice_id])
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::KeyrelaysController < AdminController
module Admin
class KeyrelaysController < BaseController
load_and_authorize_resource
def index
@ -6,5 +7,7 @@ class Admin::KeyrelaysController < AdminController
@keyrelays = @q.result.page(params[:page])
end
def show; end
def show;
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::LegalDocumentsController < AdminController
module Admin
class LegalDocumentsController < BaseController
load_and_authorize_resource
def show
@ -6,4 +7,5 @@ class Admin::LegalDocumentsController < AdminController
filename = @ld.path.split('/').last
send_data File.open(@ld.path).read, filename: filename
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::MailTemplatesController < AdminController
module Admin
class MailTemplatesController < BaseController
load_and_authorize_resource
def index
@ -58,4 +59,5 @@ class Admin::MailTemplatesController < AdminController
def mail_template_params
params.require(:mail_template).permit(:name, :subject, :from, :bcc, :cc, :body, :text_body)
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::PendingDeletesController < AdminController
module Admin
class PendingDeletesController < BaseController
before_action :find_domain
before_action :check_status
@ -39,4 +40,5 @@ class Admin::PendingDeletesController < AdminController
def check_status
return redirect_to admin_domain_path(@domain.id), alert: t(:something_wrong) unless @domain.pending_delete?
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::PendingUpdatesController < AdminController
module Admin
class PendingUpdatesController < BaseController
before_action :find_domain
before_action :check_status
@ -38,4 +39,5 @@ class Admin::PendingUpdatesController < AdminController
def check_status
return redirect_to admin_domain_path(@domain.id), alert: t(:something_wrong) unless @domain.pending_update?
end
end
end

View file

@ -1,6 +1,8 @@
class Admin::RegistrarsController < AdminController
module Admin
class RegistrarsController < BaseController
load_and_authorize_resource
before_action :set_registrar, only: [:show, :edit, :update, :destroy]
def search
render json: Registrar.search_by_query(params[:q])
end
@ -31,7 +33,8 @@ class Admin::RegistrarsController < AdminController
end
end
def edit; end
def edit;
end
def update
if @registrar.update(registrar_params)
@ -65,4 +68,5 @@ class Admin::RegistrarsController < AdminController
:country_code, :email, :phone, :website, :billing_email, :code, :test_registrar
)
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::ReppLogsController < AdminController
module Admin
class ReppLogsController < BaseController
load_and_authorize_resource class: ApiLog::ReppLog
before_action :set_default_dates, only: [:index]
@ -31,4 +32,5 @@ class Admin::ReppLogsController < AdminController
end
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::ReservedDomainsController < AdminController
module Admin
class ReservedDomainsController < BaseController
load_and_authorize_resource
before_action :set_domain, only: [:edit, :update]
@ -65,4 +66,5 @@ class Admin::ReservedDomainsController < AdminController
def set_domain
@domain = ReservedDomain.find(params[:id])
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::SessionsController < Devise::SessionsController
module Admin
class SessionsController < Devise::SessionsController
skip_authorization_check only: :create
def login
@ -23,4 +24,5 @@ class Admin::SessionsController < Devise::SessionsController
render 'login'
end
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::SettingsController < AdminController
module Admin
class SettingsController < BaseController
load_and_authorize_resource
before_action :set_setting_group, only: [:show, :update]
@ -21,7 +22,8 @@ class Admin::SettingsController < AdminController
end
end
def show; end
def show;
end
def update
if @setting_group.update(setting_group_params)
@ -92,4 +94,5 @@ class Admin::SettingsController < AdminController
settings
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::WhiteIpsController < AdminController
module Admin
class WhiteIpsController < BaseController
load_and_authorize_resource
before_action :set_registrar, only: [:new, :show, :edit, :destroy, :update]
@ -7,9 +8,11 @@ class Admin::WhiteIpsController < AdminController
@white_ip = WhiteIp.new(registrar: @registrar)
end
def show; end
def show;
end
def edit; end
def edit;
end
def destroy
if @white_ip.destroy
@ -53,4 +56,5 @@ class Admin::WhiteIpsController < AdminController
def white_ip_params
params.require(:white_ip).permit(:ipv4, :ipv6, :registrar_id, { interfaces: [] })
end
end
end

View file

@ -1,4 +1,5 @@
class Admin::ZonefilesController < ApplicationController
module Admin
class ZonefilesController < BaseController
authorize_resource class: false
# TODO: Refactor this
@ -15,4 +16,5 @@ class Admin::ZonefilesController < ApplicationController
redirect_to :back
end
end
end
end

View file

@ -1,8 +0,0 @@
class AdminController < ApplicationController
before_action :authenticate_user!
helper_method :head_title_sufix
def head_title_sufix
t(:admin_head_title_sufix)
end
end

View file

@ -52,11 +52,6 @@
<ellipse fill="none" stroke="black" cx="532" cy="-462" rx="87.9851" ry="18"/>
<text text-anchor="middle" x="532" y="-458.3" font-family="Times,serif" font-size="14.00">Epp::ErrorsController</text>
</g>
<!-- AdminController -->
<g id="node9" class="node"><title>AdminController</title>
<ellipse fill="none" stroke="black" cx="-361" cy="66" rx="71.4873" ry="18"/>
<text text-anchor="middle" x="-361" y="69.7" font-family="Times,serif" font-size="14.00">AdminController</text>
</g>
<!-- RegistrarController -->
<g id="node10" class="node"><title>RegistrarController</title>
<ellipse fill="none" stroke="black" cx="-173" cy="-462" rx="79.0865" ry="18"/>

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before After
Before After

View file

@ -131,16 +131,6 @@
<polyline fill="none" stroke="black" points="740.5,56 875.5,56 "/>
<text text-anchor="start" x="748.5" y="71.2" font-family="Times,serif" font-size="14.00">_layout</text>
</g>
<!-- AdminController -->
<g id="node9" class="node"><title>AdminController</title>
<path fill="none" stroke="black" d="M152,239.5C152,239.5 238,239.5 238,239.5 244,239.5 250,233.5 250,227.5 250,227.5 250,158.5 250,158.5 250,152.5 244,146.5 238,146.5 238,146.5 152,146.5 152,146.5 146,146.5 140,152.5 140,158.5 140,158.5 140,227.5 140,227.5 140,233.5 146,239.5 152,239.5"/>
<text text-anchor="middle" x="195" y="161.7" font-family="Times,serif" font-size="14.00">AdminController</text>
<polyline fill="none" stroke="black" points="140,169.5 250,169.5 "/>
<text text-anchor="start" x="148" y="184.7" font-family="Times,serif" font-size="14.00">head_title_sufix</text>
<polyline fill="none" stroke="black" points="140,192.5 250,192.5 "/>
<polyline fill="none" stroke="black" points="140,216.5 250,216.5 "/>
<text text-anchor="start" x="148" y="231.7" font-family="Times,serif" font-size="14.00">_layout</text>
</g>
<!-- RegistrarController -->
<g id="node10" class="node"><title>RegistrarController</title>
<path fill="none" stroke="black" d="M-708,539.5C-708,539.5 -610,539.5 -610,539.5 -604,539.5 -598,533.5 -598,527.5 -598,527.5 -598,428.5 -598,428.5 -598,422.5 -604,416.5 -610,416.5 -610,416.5 -708,416.5 -708,416.5 -714,416.5 -720,422.5 -720,428.5 -720,428.5 -720,527.5 -720,527.5 -720,533.5 -714,539.5 -708,539.5"/>

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Before After
Before After