Skip to content

Commit

Permalink
Merge branch 'feature/3705_click_to_copy_api' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Eardley committed Nov 23, 2023
2 parents 5abad62 + 5ef1f30 commit 67a3330
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
13 changes: 13 additions & 0 deletions doajtest/testbook/user_management/user_management.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ fragments:
- Your API Key at the top of the page is updated
- You receive a flash message saying your record is updated and the API key has
changed
- step: Click "Click to Copy" icon next to your API key
results:
- The API key is copied to your clipboard
- Confirmation message appears and dissapears after a moment
- step: Enter mismatched passwords into the "Change your password" boxes and click
"Update Account"
results:
Expand Down Expand Up @@ -205,3 +209,12 @@ tests:
- step: Click on the user's journals
results:
- All the same journals are still associated with the user

- title: User account without API role
context:
role: admin
steps:
- step: Find (or create) a user account which does not have the API role
- step: View the user account page at /account/[account name]
results:
- The API key is not displayed
15 changes: 14 additions & 1 deletion portality/templates/account/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ <h2 class="label">Your API access</h2>
{% if account.has_role("api") %}
<dt>API Key</dt>
<dd>
<code>{{ account.api_key }}</code>
<code id="user-api">{{ account.api_key }}</code>
<span class="form__click-to-copy" id="click-to-copy--api" data-feather="copy" aria-hidden="true"></span><span class="sr-only">Copy value</span>
<span class="tag tag--confirmation" style="display:none" id="copy-confirmation--api">Copied!</span>
</dd>
{% endif %}
</dl>
Expand Down Expand Up @@ -121,6 +123,17 @@ <h2 class="label">Your API access</h2>
$(window).scrollTop($(firstError).offset().top - 100)
}

{% if account.has_role("api") %}
// Copy API key to clipboard
$('#click-to-copy--api').click(function() {
let value_to_copy = $('#user-api').html();
navigator.clipboard.writeText(value_to_copy);
var confirmation = $("#copy-confirmation--api");
confirmation.text("Copied: " + value_to_copy);
confirmation.show().delay(3000).fadeOut();
});
{% endif %}

// If the user is editing their own account, make them confirm when email address is updated
{% if current_user.id == account.id %}
$('form#edit_user').submit(function () {
Expand Down

0 comments on commit 67a3330

Please sign in to comment.