mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 00:12:03 +02:00
Improve registrar area linked user switch
- Introduce profile - Move linked users to profile - Use PUT #599
This commit is contained in:
parent
bd78c9d5c8
commit
e2ebe0aa84
16 changed files with 248 additions and 73 deletions
|
@ -3,10 +3,16 @@ class Registrar
|
|||
skip_authorization_check
|
||||
|
||||
def switch
|
||||
new_user = ApiUser.find(params[:new_user_id])
|
||||
sign_in(new_user) if new_user.identity_code == current_user.identity_code
|
||||
raise 'Cannot switch to unlinked user' unless current_user.linked_with?(new_user)
|
||||
|
||||
sign_in(new_user)
|
||||
redirect_to :back, notice: t('.switched', new_user: new_user)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def new_user
|
||||
@new_user ||= ApiUser.find(params[:new_user_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
17
app/controllers/registrar/profile_controller.rb
Normal file
17
app/controllers/registrar/profile_controller.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class Registrar
|
||||
class ProfileController < BaseController
|
||||
skip_authorization_check
|
||||
|
||||
helper_method :linked_users
|
||||
|
||||
def show
|
||||
@user = current_user
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def linked_users
|
||||
current_user.linked_users
|
||||
end
|
||||
end
|
||||
end
|
|
@ -23,9 +23,9 @@ class ApiUser < User
|
|||
validates :password, length: { minimum: min_password_length }
|
||||
validates :username, uniqueness: true
|
||||
|
||||
# TODO: probably cache, because it's requested on every EPP
|
||||
delegate :code, to: :registrar, prefix: true
|
||||
delegate :code, :name, to: :registrar, prefix: true
|
||||
|
||||
alias_attribute :login, :username
|
||||
attr_accessor :registrar_typeahead
|
||||
|
||||
SUPER = 'super'
|
||||
|
@ -91,7 +91,11 @@ class ApiUser < User
|
|||
|
||||
def linked_users
|
||||
self.class.where(identity_code: identity_code)
|
||||
.where("identity_code is NOT NULL and identity_code != ''")
|
||||
.where("identity_code IS NOT NULL AND identity_code != ''")
|
||||
.where.not(id: id)
|
||||
end
|
||||
|
||||
def linked_with?(another_api_user)
|
||||
another_api_user.identity_code == self.identity_code
|
||||
end
|
||||
end
|
||||
|
|
19
app/presenters/user_presenter.rb
Normal file
19
app/presenters/user_presenter.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
class UserPresenter
|
||||
def initialize(user:, view:)
|
||||
@user = user
|
||||
@view = view
|
||||
end
|
||||
|
||||
def login_with_role
|
||||
"#{user.login} (#{role_name}) - #{user.registrar_name}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def role_name
|
||||
user.roles.first
|
||||
end
|
||||
|
||||
attr_reader :user
|
||||
attr_reader :view
|
||||
end
|
|
@ -1,3 +1,4 @@
|
|||
<%= "#{current_user} (#{current_user.roles.first}) - #{current_user.registrar}" %>
|
||||
<% current_user_presenter = UserPresenter.new(user: current_user, view: self) %>
|
||||
<%= link_to current_user_presenter.login_with_role, registrar_profile_path, id: 'registrar-profile-btn' %>
|
||||
<span class="text-muted">|</span>
|
||||
<%= link_to t('.sign_out'), registrar_destroy_user_session_path, method: :delete %>
|
||||
|
|
18
app/views/registrar/profile/_linked_users.html.erb
Normal file
18
app/views/registrar/profile/_linked_users.html.erb
Normal file
|
@ -0,0 +1,18 @@
|
|||
<div class="panel panel-default">
|
||||
<div class="panel-heading"><%= t '.header' %></div>
|
||||
<div class="panel-body">
|
||||
<ul>
|
||||
<% linked_users.each do |user| %>
|
||||
<% user_presenter = UserPresenter.new(user: user, view: self) %>
|
||||
<li><%= user_presenter.login_with_role %>
|
||||
<%= link_to t('.switch_btn'),
|
||||
registrar_switch_current_user_path(user),
|
||||
method: :put,
|
||||
id: "switch-current-user-#{user.id}-btn",
|
||||
class: 'btn btn-primary btn-xs' %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
9
app/views/registrar/profile/show.html.erb
Normal file
9
app/views/registrar/profile/show.html.erb
Normal file
|
@ -0,0 +1,9 @@
|
|||
<div class="page-header">
|
||||
<h1><%= t '.header' %></h1>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<%= render 'linked_users', linked_users: linked_users %>
|
||||
</div>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue