Let registrar users change registrar account

This commit is contained in:
Artur Beljajev 2019-05-15 14:29:20 +03:00
parent 207c2a704c
commit 37249a24f7
8 changed files with 104 additions and 9 deletions

View file

@ -2,16 +2,23 @@ class Registrar
class AccountController < BaseController class AccountController < BaseController
skip_authorization_check skip_authorization_check
helper_method :linked_users def show; end
def show def edit
@user = current_registrar_user @registrar = current_registrar_user.registrar
end
def update
@registrar = current_registrar_user.registrar
@registrar.update!(registrar_params)
redirect_to registrar_account_path, notice: t('.saved')
end end
private private
def linked_users def registrar_params
current_registrar_user.linked_users params.require(:registrar).permit(:billing_email)
end end
end end
end end

View file

@ -0,0 +1,16 @@
<div class="panel panel-default">
<div class="panel-heading">
<%= t '.header' %>
</div>
<div class="panel-body">
<dl class="dl-horizontal">
<dt><%= Registrar.human_attribute_name :billing_email %></dt>
<dd><%= registrar.billing_email %></dd>
</dl>
</div>
<div class="panel-footer text-right">
<%= link_to t('.edit_btn'), edit_registrar_account_path, class: 'btn btn-default btn-sm' %>
</div>
</div>

View file

@ -0,0 +1,21 @@
<%= form_for @registrar, url: registrar_account_path, method: :patch, html: { class: 'form-horizontal' } do |f| %>
<%= render 'form_errors', target: @registrar %>
<div class="form-group">
<div class="col-sm-2 control-label">
<%= f.label :billing_email %>
</div>
<div class="col-sm-4">
<%= f.email_field :billing_email, autofocus: true, class: 'form-control' %>
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-6 text-right">
<%= f.submit t('.submit_btn'), class: 'btn btn-success' %>
</div>
</div>
<% end %>

View file

@ -0,0 +1,10 @@
<ol class="breadcrumb">
<li><%= link_to t('registrar.account.show.header'), registrar_account_path %></li>
<li><%= t '.header' %></li>
</ol>
<div class="page-header">
<h1><%= t '.header' %></h1>
</div>
<%= render 'form' %>

View file

@ -3,7 +3,13 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-4"> <div class="col-sm-5">
<%= render 'linked_users', linked_users: linked_users %> <%= render 'details', registrar: current_registrar_user.registrar %>
</div>
</div>
<div class="row">
<div class="col-sm-5">
<%= render 'linked_users', linked_users: current_registrar_user.linked_users %>
</div> </div>
</div> </div>

View file

@ -4,6 +4,19 @@ en:
show: show:
header: Your account header: Your account
edit:
header: Edit your account
form:
submit_btn: Save changes
update:
saved: Your account has been updated
details:
header: Details
edit_btn: Edit
linked_users: linked_users:
header: Linked users header: Linked users
switch_btn: Switch switch_btn: Switch

View file

@ -66,7 +66,7 @@ Rails.application.routes.draw do
resources :account_activities resources :account_activities
put 'current_user/switch/:new_user_id', to: 'current_user#switch', as: :switch_current_user put 'current_user/switch/:new_user_id', to: 'current_user#switch', as: :switch_current_user
resource :account, controller: :account, only: :show resource :account, controller: :account, only: %i[show edit update]
resources :domains do resources :domains do
collection do collection do

View file

@ -0,0 +1,22 @@
require 'test_helper'
class RegistrarAccountTest < ApplicationSystemTestCase
setup do
@registrar = registrars(:bestnames)
sign_in users(:api_bestnames)
end
def test_updates_account
new_billing_email = 'new@registrar.test'
assert_not_equal new_billing_email, @registrar.billing_email
visit registrar_account_path
click_on 'Edit'
fill_in 'Billing email', with: new_billing_email
click_on 'Save changes'
assert_text 'Your account has been updated'
assert_text new_billing_email
end
end