Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve API key on user edit page #2243

Merged
merged 4 commits into from
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions api/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ en:
resource_not_found: "The resource you were looking for could not be found."
gateway_error: "There was a problem with the payment gateway: %{text}"
delete_restriction_error: "Cannot delete record."
access: "API Access"
key: "Key"
clear_key: "Clear key"
regenerate_key: "Regenerate Key"
no_key: "No key"
generate_key: "Generate API key"
key_generated: "Key generated"
key_cleared: "Key cleared"
order:
Expand Down
29 changes: 14 additions & 15 deletions backend/app/views/spree/admin/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= render partial: 'spree/admin/users/user_page_actions' %>

<fieldset data-hook="admin_user_edit_general_settings">
<legend><%= Spree.t(:general_settings) %></legend>
<legend><%= Spree.user_class.model_name.human %></legend>

<div data-hook="admin_user_edit_form_header">
<%= render partial: 'spree/shared/error_messages', locals: { target: @user } %>
Expand All @@ -28,30 +28,29 @@

<% if can?(:update, @user) %>
<fieldset data-hook="admin_user_api_key" id="admin_user_edit_api_key">
<legend><%= Spree.t('access', scope: 'api') %></legend>
<legend><%= t('.api_access') %></legend>

<% if @user.spree_api_key.present? %>
<div class="field">
<div id="current-api-key"><%= Spree.t('key', scope: 'api') %>: (<%= Spree.t('hidden') %>)</div>
</div>
<div class="filter-actions actions">
<%= form_tag spree.clear_api_key_admin_user_path(@user), method: :put do %>
<%= button Spree.t('clear_key', scope: 'api') %>
<div id="current-api-key">
<strong><%= t('.key') %>: </strong>
<% if @user == try_spree_current_user %>
<%= @user.spree_api_key %>
<% else %>
<i>(<%= Spree.t('hidden') %>)</i>
<% end %>

<%= form_tag spree.generate_api_key_admin_user_path(@user), method: :put do %>
<%= button Spree.t('regenerate_key', scope: 'api') %>
<% end %>
</div>
<div class="filter-actions actions">
<%= button_link_to t('.clear_key'), spree.clear_api_key_admin_user_path(@user), method: :put, data: { confirm: t('.confirm_clear_key') }, class: 'btn btn-primary' %>
<%= button_link_to t('.regenerate_key'), spree.generate_api_key_admin_user_path(@user), method: :put, data: { confirm: t('.confirm_regenerate_key') }, class: 'btn btn-primary' %>
</div>

<% else %>

<div class="no-objects-found"><%= Spree.t('no_key', scope: 'api') %></div>
<div class="no-objects-found"><%= t('.no_key') %></div>

<div class="filter-actions actions">
<%= form_tag spree.generate_api_key_admin_user_path(@user), method: :put do %>
<%= button Spree.t('generate_key', scope: 'api') %>
<% end %>
<%= button_link_to t('.generate_key'), spree.generate_api_key_admin_user_path(@user), method: :put, class: 'btn btn-primary' %>
</div>
<% end %>
</fieldset>
Expand Down
6 changes: 3 additions & 3 deletions backend/spec/features/admin/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def always_invalid_email
it 'can generate a new api key' do
within("#admin_user_edit_api_key") do
expect(user_a.spree_api_key).to be_blank
click_button Spree.t('generate_key', scope: 'api')
click_button "Generate API key"
end

expect(user_a.reload.spree_api_key).to be_present
Expand All @@ -257,7 +257,7 @@ def always_invalid_email
it 'can clear an api key' do
expect(page).to have_css('#current-api-key')

click_button Spree.t('clear_key', scope: 'api')
click_button "Clear key"

expect(page).to have_no_css('#current-api-key')

Expand All @@ -268,7 +268,7 @@ def always_invalid_email
old_key = user_a.spree_api_key

within("#admin_user_edit_api_key") do
click_button Spree.t('regenerate_key', scope: 'api')
click_button "Regenerate key"
end

expect(user_a.reload.spree_api_key).to be_present
Expand Down
9 changes: 9 additions & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,15 @@ en:
users:
user_page_actions:
create_order: Create order for this user
edit:
api_access: "API Access"
clear_key: "Clear key"
confirm_clear_key: "Are you sure you want to clear this user's API key? It will invalidate the existing key."
confirm_regenerate_key: "Are you sure you want to regenerate this user's API key? It will invalidate the existing key."
generate_key: "Generate API key"
key: "Key"
no_key: "No key"
regenerate_key: "Regenerate key"
variants:
table_filter:
show_deleted: Show deleted variants
Expand Down