From 5e0eca22cfcde08b595f0e1326ec57374cd6e1bb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 15 May 2019 13:39:01 +0300 Subject: [PATCH 1/3] Remove useless spec --- app/views/registrar/base/_current_user.html.erb | 3 +-- spec/features/registrar/profile_spec.rb | 13 ------------- 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 spec/features/registrar/profile_spec.rb diff --git a/app/views/registrar/base/_current_user.html.erb b/app/views/registrar/base/_current_user.html.erb index 0e45c9c7d..f200c9376 100644 --- a/app/views/registrar/base/_current_user.html.erb +++ b/app/views/registrar/base/_current_user.html.erb @@ -1,5 +1,4 @@ <% current_user_presenter = UserPresenter.new(user: current_registrar_user, view: self) %> -<%= link_to current_user_presenter.login_with_role, registrar_profile_path, id: 'registrar-profile-btn', - class: 'navbar-link' %> +<%= link_to current_user_presenter.login_with_role, registrar_profile_path, class: 'navbar-link' %> | <%= link_to t('.sign_out'), destroy_registrar_user_session_path, method: :delete, class: 'navbar-link' %> diff --git a/spec/features/registrar/profile_spec.rb b/spec/features/registrar/profile_spec.rb deleted file mode 100644 index 745542b58..000000000 --- a/spec/features/registrar/profile_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'rails_helper' - -RSpec.feature 'Registrar area profile', settings: false do - background do - sign_in_to_registrar_area(user: create(:api_user_with_unlimited_balance)) - end - - scenario 'shows profile' do - visit registrar_root_path - click_on 'registrar-profile-btn' - expect(page).to have_text(t('registrar.profile.show.header')) - end -end From 207c2a704c1ac2c5744f2677b3743d5a3e39ee35 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 15 May 2019 13:44:36 +0300 Subject: [PATCH 2/3] Rename profile page in registrar area to account --- .../{profile_controller.rb => account_controller.rb} | 2 +- app/controllers/registrar/sessions_controller.rb | 2 +- app/views/layouts/registrar/base.html.erb | 2 +- .../registrar/{profile => account}/_linked_users.html.erb | 0 app/views/registrar/{profile => account}/show.html.erb | 0 app/views/registrar/base/_current_user.html.erb | 2 +- config/locales/registrar/{profile.en.yml => account.en.yml} | 4 ++-- config/routes.rb | 2 +- spec/features/registrar/linked_users_spec.rb | 2 +- test/system/registrar_area/sign_in/password_test.rb | 4 ++-- 10 files changed, 10 insertions(+), 10 deletions(-) rename app/controllers/registrar/{profile_controller.rb => account_controller.rb} (84%) rename app/views/registrar/{profile => account}/_linked_users.html.erb (100%) rename app/views/registrar/{profile => account}/show.html.erb (100%) rename config/locales/registrar/{profile.en.yml => account.en.yml} (71%) diff --git a/app/controllers/registrar/profile_controller.rb b/app/controllers/registrar/account_controller.rb similarity index 84% rename from app/controllers/registrar/profile_controller.rb rename to app/controllers/registrar/account_controller.rb index 1fe6d6a0b..2c942aed7 100644 --- a/app/controllers/registrar/profile_controller.rb +++ b/app/controllers/registrar/account_controller.rb @@ -1,5 +1,5 @@ class Registrar - class ProfileController < BaseController + class AccountController < BaseController skip_authorization_check helper_method :linked_users diff --git a/app/controllers/registrar/sessions_controller.rb b/app/controllers/registrar/sessions_controller.rb index e8873c584..c97c3155d 100644 --- a/app/controllers/registrar/sessions_controller.rb +++ b/app/controllers/registrar/sessions_controller.rb @@ -182,7 +182,7 @@ class Registrar if can?(:show, :poll) registrar_root_path else - registrar_profile_path + registrar_account_path end end diff --git a/app/views/layouts/registrar/base.html.erb b/app/views/layouts/registrar/base.html.erb index e3e93f89f..4d4f1b972 100644 --- a/app/views/layouts/registrar/base.html.erb +++ b/app/views/layouts/registrar/base.html.erb @@ -24,7 +24,7 @@ - <%= link_to can?(:show, :poll) ? registrar_root_path : registrar_profile_path, + <%= link_to can?(:show, :poll) ? registrar_root_path : registrar_account_path, class: 'navbar-brand' do %> <%= t(:registrar_head_title) %> <% if unstable_env.present? %> diff --git a/app/views/registrar/profile/_linked_users.html.erb b/app/views/registrar/account/_linked_users.html.erb similarity index 100% rename from app/views/registrar/profile/_linked_users.html.erb rename to app/views/registrar/account/_linked_users.html.erb diff --git a/app/views/registrar/profile/show.html.erb b/app/views/registrar/account/show.html.erb similarity index 100% rename from app/views/registrar/profile/show.html.erb rename to app/views/registrar/account/show.html.erb diff --git a/app/views/registrar/base/_current_user.html.erb b/app/views/registrar/base/_current_user.html.erb index f200c9376..a21792b3c 100644 --- a/app/views/registrar/base/_current_user.html.erb +++ b/app/views/registrar/base/_current_user.html.erb @@ -1,4 +1,4 @@ <% current_user_presenter = UserPresenter.new(user: current_registrar_user, view: self) %> -<%= link_to current_user_presenter.login_with_role, registrar_profile_path, class: 'navbar-link' %> +<%= link_to current_user_presenter.login_with_role, registrar_account_path, class: 'navbar-link' %> | <%= link_to t('.sign_out'), destroy_registrar_user_session_path, method: :delete, class: 'navbar-link' %> diff --git a/config/locales/registrar/profile.en.yml b/config/locales/registrar/account.en.yml similarity index 71% rename from config/locales/registrar/profile.en.yml rename to config/locales/registrar/account.en.yml index 2ccec1406..42e0de6de 100644 --- a/config/locales/registrar/profile.en.yml +++ b/config/locales/registrar/account.en.yml @@ -1,8 +1,8 @@ en: registrar: - profile: + account: show: - header: My profile + header: Your account linked_users: header: Linked users diff --git a/config/routes.rb b/config/routes.rb index 0f093d45b..23ac67a50 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,7 +66,7 @@ Rails.application.routes.draw do resources :account_activities put 'current_user/switch/:new_user_id', to: 'current_user#switch', as: :switch_current_user - resource :profile, controller: :profile, only: :show + resource :account, controller: :account, only: :show resources :domains do collection do diff --git a/spec/features/registrar/linked_users_spec.rb b/spec/features/registrar/linked_users_spec.rb index f7731a168..aa1e3785b 100644 --- a/spec/features/registrar/linked_users_spec.rb +++ b/spec/features/registrar/linked_users_spec.rb @@ -10,7 +10,7 @@ RSpec.feature 'Registrar area linked users', settings: false do end scenario 'switches current user to a linked one' do - visit registrar_profile_path + visit registrar_account_path click_link_or_button 'switch-current-user-2-btn' expect(page).to have_text('You are now signed in as a user "new-user-name"') end diff --git a/test/system/registrar_area/sign_in/password_test.rb b/test/system/registrar_area/sign_in/password_test.rb index 04dffd07b..433c56d9d 100644 --- a/test/system/registrar_area/sign_in/password_test.rb +++ b/test/system/registrar_area/sign_in/password_test.rb @@ -17,10 +17,10 @@ class RegistrarAreaPasswordSignInTest < ApplicationSystemTestCase assert_current_path registrar_root_path end - def test_after_successful_sign_in_billing_user_sees_profile + def test_after_successful_sign_in_billing_user_sees_account @user.update!(roles: [ApiUser::BILLING]) login_with_correct_credentials - assert_current_path registrar_profile_path + assert_current_path registrar_account_path end def test_wrong_password From 37249a24f79f2c7904fbf4efa06c39fab639b849 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 15 May 2019 14:29:20 +0300 Subject: [PATCH 3/3] Let registrar users change registrar account --- .../registrar/account_controller.rb | 19 +++++++++++----- app/views/registrar/account/_details.html.erb | 16 ++++++++++++++ app/views/registrar/account/_form.html.erb | 21 ++++++++++++++++++ app/views/registrar/account/edit.html.erb | 10 +++++++++ app/views/registrar/account/show.html.erb | 10 +++++++-- config/locales/registrar/account.en.yml | 13 +++++++++++ config/routes.rb | 2 +- test/system/registrar_area/account_test.rb | 22 +++++++++++++++++++ 8 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 app/views/registrar/account/_details.html.erb create mode 100644 app/views/registrar/account/_form.html.erb create mode 100644 app/views/registrar/account/edit.html.erb create mode 100644 test/system/registrar_area/account_test.rb diff --git a/app/controllers/registrar/account_controller.rb b/app/controllers/registrar/account_controller.rb index 2c942aed7..1bcf9e468 100644 --- a/app/controllers/registrar/account_controller.rb +++ b/app/controllers/registrar/account_controller.rb @@ -2,16 +2,23 @@ class Registrar class AccountController < BaseController skip_authorization_check - helper_method :linked_users + def show; end - def show - @user = current_registrar_user + def edit + @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 private - def linked_users - current_registrar_user.linked_users + def registrar_params + params.require(:registrar).permit(:billing_email) end end -end +end \ No newline at end of file diff --git a/app/views/registrar/account/_details.html.erb b/app/views/registrar/account/_details.html.erb new file mode 100644 index 000000000..9e35da899 --- /dev/null +++ b/app/views/registrar/account/_details.html.erb @@ -0,0 +1,16 @@ +
+
+ <%= t '.header' %> +
+ +
+
+
<%= Registrar.human_attribute_name :billing_email %>
+
<%= registrar.billing_email %>
+
+
+ + +
diff --git a/app/views/registrar/account/_form.html.erb b/app/views/registrar/account/_form.html.erb new file mode 100644 index 000000000..c2bb6aa82 --- /dev/null +++ b/app/views/registrar/account/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for @registrar, url: registrar_account_path, method: :patch, html: { class: 'form-horizontal' } do |f| %> + <%= render 'form_errors', target: @registrar %> + +
+
+ <%= f.label :billing_email %> +
+ +
+ <%= f.email_field :billing_email, autofocus: true, class: 'form-control' %> +
+
+ +
+ +
+
+ <%= f.submit t('.submit_btn'), class: 'btn btn-success' %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/registrar/account/edit.html.erb b/app/views/registrar/account/edit.html.erb new file mode 100644 index 000000000..20aa88d2d --- /dev/null +++ b/app/views/registrar/account/edit.html.erb @@ -0,0 +1,10 @@ + + + + +<%= render 'form' %> \ No newline at end of file diff --git a/app/views/registrar/account/show.html.erb b/app/views/registrar/account/show.html.erb index d6a90d64c..53218d1f7 100644 --- a/app/views/registrar/account/show.html.erb +++ b/app/views/registrar/account/show.html.erb @@ -3,7 +3,13 @@
-
- <%= render 'linked_users', linked_users: linked_users %> +
+ <%= render 'details', registrar: current_registrar_user.registrar %>
+ +
+
+ <%= render 'linked_users', linked_users: current_registrar_user.linked_users %> +
+
\ No newline at end of file diff --git a/config/locales/registrar/account.en.yml b/config/locales/registrar/account.en.yml index 42e0de6de..94d4783d5 100644 --- a/config/locales/registrar/account.en.yml +++ b/config/locales/registrar/account.en.yml @@ -4,6 +4,19 @@ en: show: 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: header: Linked users switch_btn: Switch diff --git a/config/routes.rb b/config/routes.rb index 23ac67a50..216946a08 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,7 +66,7 @@ Rails.application.routes.draw do resources :account_activities 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 collection do diff --git a/test/system/registrar_area/account_test.rb b/test/system/registrar_area/account_test.rb new file mode 100644 index 000000000..438de2629 --- /dev/null +++ b/test/system/registrar_area/account_test.rb @@ -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 \ No newline at end of file