mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 18:29:40 +02:00
Context switching for client
This commit is contained in:
parent
5dfee40b87
commit
b48b91878d
9 changed files with 44 additions and 12 deletions
|
@ -24,7 +24,7 @@ class Client::ContactsController < ClientController
|
|||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
def destroy
|
||||
if @contact.destroy_and_clean
|
||||
flash[:notice] = I18n.t('shared.contact_deleted')
|
||||
redirect_to client_contacts_path
|
||||
|
|
|
@ -7,9 +7,10 @@ class Client::DomainTransfersController < ClientController
|
|||
end
|
||||
|
||||
def create
|
||||
@domain_transfer = @domain.pending_transfer || @domain.domain_transfers.create(domain_transfer_params)
|
||||
@domain_transfer = @domain.pending_transfer || @domain.domain_transfers.build(domain_transfer_params)
|
||||
if can? :read, @domain_transfer
|
||||
flash[:notice] = I18n.t('shared.domain_transfer_requested')
|
||||
@domain_transfer.save
|
||||
flash[:notice] = I18n.t('shared.domain_transfer_requested') if @domain.registrar != current_registrar
|
||||
redirect_to [:client, @domain_transfer]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('shared.other_registrar_has_already_requested_to_transfer_this_domain')
|
||||
|
@ -38,7 +39,7 @@ class Client::DomainTransfersController < ClientController
|
|||
ret = {
|
||||
status: DomainTransfer::PENDING,
|
||||
transfer_requested_at: Time.zone.now,
|
||||
transfer_to: current_user.registrar,
|
||||
transfer_to: current_registrar,
|
||||
transfer_from: @domain.registrar
|
||||
}
|
||||
|
||||
|
@ -61,7 +62,7 @@ class Client::DomainTransfersController < ClientController
|
|||
render 'new' and return
|
||||
end
|
||||
|
||||
if @domain.registrar == current_user.registrar
|
||||
if @domain.registrar == current_registrar && !@domain.pending_transfer
|
||||
flash.now[:alert] = I18n.t('shared.domain_already_belongs_to_the_querying_registrar')
|
||||
render 'new' and return
|
||||
end
|
||||
|
|
|
@ -4,14 +4,13 @@ class Client::DomainsController < ClientController
|
|||
before_action :verify_deletion, only: [:destroy]
|
||||
|
||||
def index
|
||||
@q = Domain.search(params[:q]) if current_user.admin?
|
||||
@q = current_user.registrar.domains.search(params[:q]) unless current_user.admin?
|
||||
@q = current_registrar.domains.search(params[:q])
|
||||
@domains = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
owner_contact = Contact.find(params[:owner_contact_id]) if params[:owner_contact_id]
|
||||
@domain = Domain.new(owner_contact: owner_contact, registrar: current_user.registrar)
|
||||
@domain = Domain.new(owner_contact: owner_contact, registrar: current_registrar)
|
||||
params[:domain_owner_contact] = owner_contact
|
||||
|
||||
build_associations
|
||||
|
@ -21,7 +20,7 @@ class Client::DomainsController < ClientController
|
|||
add_prefix_to_statuses
|
||||
|
||||
@domain = Domain.new(domain_params)
|
||||
@domain.registrar = current_user.registrar
|
||||
@domain.registrar = current_registrar
|
||||
|
||||
if @domain.save
|
||||
flash[:notice] = I18n.t('shared.domain_added')
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
class ClientController < ApplicationController
|
||||
helper_method :current_registrar
|
||||
|
||||
def current_registrar
|
||||
return Registrar.find(session[:current_user_registrar_id]) if current_user.admin?
|
||||
current_user.registrar
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,8 @@ class SessionsController < Devise::SessionsController
|
|||
@user = User.find_by(username: 'gitlab') if params[:gitlab]
|
||||
@user = User.find_by(username: 'zone') if params[:zone]
|
||||
|
||||
session[:current_user_registrar_id] = Registrar.first.id if @user.admin?
|
||||
|
||||
flash[:notice] = I18n.t('shared.welcome')
|
||||
sign_in_and_redirect @user, :event => :authentication
|
||||
return
|
||||
|
@ -15,4 +17,10 @@ class SessionsController < Devise::SessionsController
|
|||
def login
|
||||
render 'layouts/login', layout: false
|
||||
end
|
||||
|
||||
def switch_registrar
|
||||
authorize! :switch, :registrar
|
||||
session[:current_user_registrar_id] = params[:registrar_id]
|
||||
redirect_to client_root_path
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,9 +3,14 @@ class Ability
|
|||
|
||||
def initialize(user)
|
||||
|
||||
alias_action :create, :read, :update, :destroy, :to => :crud
|
||||
|
||||
user ||= User.new
|
||||
if user.admin?
|
||||
can :manage, Domain
|
||||
can :switch, :registrar
|
||||
can :crud, DomainTransfer
|
||||
can :approve_as_client, DomainTransfer, status: DomainTransfer::PENDING
|
||||
elsif user.persisted?
|
||||
can :manage, Domain, registrar_id: user.registrar.id
|
||||
can :read, DomainTransfer, transfer_to_id: user.registrar.id
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
.col-sm-6
|
||||
%h2.text-right.text-center-xs
|
||||
- if can? :approve_as_client, @domain_transfer
|
||||
= button_to(t('shared.approve'), approve_client_domain_transfer_path, class: 'btn btn-primary')
|
||||
|
||||
= button_to(t('shared.approve'), approve_client_domain_transfer_path, class: 'btn btn-success')
|
||||
%hr
|
||||
.row
|
||||
.col-md-12
|
||||
|
@ -23,6 +22,9 @@
|
|||
%dt= t('shared.transfer_from')
|
||||
%dd= @domain_transfer.transfer_from
|
||||
|
||||
%dt= t('shared.transfer_to')
|
||||
%dd= @domain_transfer.transfer_to
|
||||
|
||||
- if @domain_transfer.transferred_at
|
||||
%dt= t('shared.transferred_at')
|
||||
%dd= l(@domain_transfer.transferred_at)
|
||||
|
|
|
@ -43,6 +43,15 @@
|
|||
- if current_user.admin?
|
||||
%li
|
||||
= link_to 'Admin', admin_root_path
|
||||
%li.dropdown
|
||||
%a.dropdown-toggle{"data-toggle" => "dropdown", href: "#"}
|
||||
= current_registrar
|
||||
%span.caret
|
||||
%ul.dropdown-menu{role: "menu"}
|
||||
- Registrar.all.each do |x|
|
||||
- next if x == current_registrar
|
||||
%li
|
||||
= link_to x, switch_registrar_sessions_path(registrar_id: x)
|
||||
%ul.nav.navbar-nav.navbar-right
|
||||
%li= link_to t('shared.log_out'), '/logout'
|
||||
/ /.nav-collapse
|
||||
|
|
|
@ -45,7 +45,10 @@ Rails.application.routes.draw do
|
|||
devise_for :users
|
||||
|
||||
devise_scope :user do
|
||||
resources :sessions
|
||||
resources :sessions do
|
||||
get :switch_registrar, on: :collection
|
||||
end
|
||||
|
||||
get 'logout' => 'devise/sessions#destroy'
|
||||
get 'login' => 'sessions#login'
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue