Clean up user experiance for generating tokens for the first time

pull/3451/head
Peter Lehwess 9 years ago
parent 1479031f0e
commit 0c7aac1584
  1. 16
      app/controllers/my_controller.rb
  2. 38
      app/views/my/access_token.html.erb
  3. 3
      config/locales/en.yml
  4. 2
      config/routes.rb
  5. 14
      spec/features/users/my_spec.rb

@ -147,6 +147,14 @@ class MyController < ApplicationController
redirect_to action: 'access_token'
end
def generate_rss_key
if request.post?
User.current.rss_key
flash[:notice] = l(:notice_feeds_access_key_generated)
end
redirect_to action: 'access_token'
end
# Create a new API key
def reset_api_key
if request.post?
@ -160,6 +168,14 @@ class MyController < ApplicationController
redirect_to action: 'access_token'
end
def generate_api_key
if request.post?
User.current.api_key
flash[:notice] = l(:notice_api_access_key_generated)
end
redirect_to action: 'access_token'
end
# User's page layout configuration
def page_layout
@user = User.current

@ -78,16 +78,13 @@ See doc/COPYRIGHT.rdoc for more details.
</thead>
<tbody>
<% if Setting.feeds_enabled? %>
<% if @user.rss_token %>
<tr>
<td><%= l(:label_feeds_access_key_type) %></td>
<td>
<% if @user.rss_token %>
<span title="<%= format_time(@user.rss_token.created_on) %>">
<%= format_time(@user.rss_token.created_on.to_s) %>
</span>
<% else %>
<%= l(:label_missing_feeds_access_key) %>
<% end %>
</td>
<td><%= I18n.t('my_account.access_tokens.indefinite_expiration') %></td>
<td>
@ -105,18 +102,29 @@ See doc/COPYRIGHT.rdoc for more details.
</a>
</td>
</tr>
<% else %>
<tr>
<td><%= l(:label_feeds_access_key_type) %></td>
<td><%= l(:label_missing_feeds_access_key) %></td>
<td></td>
<td>
<%= link_to l(:button_generate),
{ action: 'generate_rss_key' },
method: :post,
class: 'icon icon-key-1' %>
</a>
</td>
</tr>
<% end %>
<% end %>
<% if Setting.rest_api_enabled? %>
<% if @user.api_token %>
<tr>
<td><%= l(:label_api_access_key_type) %></td>
<td>
<% if @user.api_token %>
<span title="<%= format_time(@user.api_token.created_on) %>">
<%= format_time(@user.api_token.created_on.to_s) %>
</span>
<% else %>
<%= l(:label_missing_api_access_key) %>
<% end %>
</td>
<td><%= I18n.t('my_account.access_tokens.indefinite_expiration') %></td>
<td>
@ -134,6 +142,20 @@ See doc/COPYRIGHT.rdoc for more details.
</a>
</td>
</tr>
<% else %>
<tr>
<td><%= l(:label_api_access_key_type) %></td>
<td><%= l(:label_missing_api_access_key) %></td>
<td></td>
<td>
<%= link_to l(:button_generate),
{ action: 'generate_api_key' },
method: :post,
class: 'icon icon-key-1' %>
</a>
</td>
</tr>
<% end %>
<% end %>
<%= call_hook(:view_access_tokens_table, user: @user) %>
</tbody>

@ -1212,12 +1212,15 @@ en:
notice_account_registered_and_logged_in: "Welcome, your account has been activated. You are logged in now."
notice_activation_failed: The account could not be activated.
notice_api_access_key_reseted: "Your API access key was reset."
notice_api_access_key_generated: "Your API access key was generated."
notice_can_t_change_password: "This account uses an external authentication source. Impossible to change the password."
notice_email_error: "An error occurred while sending mail (%{value})"
notice_email_sent: "An email was sent to %{value}"
notice_failed_to_save_work_packages: "Failed to save %{count} work package(s) on %{total} selected: %{ids}."
notice_failed_to_save_members: "Failed to save member(s): %{errors}."
notice_feeds_access_key_reseted: "Your RSS access key was reset."
notice_feeds_access_key_generated: "Your RSS access key was generated."
notice_file_not_found: "The page you were trying to access doesn't exist or has been removed."
notice_forced_logout: "You have been automatically logged out after %{ttl_time} minutes of inactivity."
notice_internal_server_error: "An error occurred on the page you were trying to access. If you continue to experience problems please contact your %{app_title} administrator for assistance."

@ -545,7 +545,9 @@ OpenProject::Application.routes.draw do
match '/my/settings', action: 'settings', via: [:get, :patch]
match '/my/mail_notifications', action: 'mail_notifications', via: [:get, :patch]
post '/my/reset_rss_key', action: 'reset_rss_key'
post '/my/generate_rss_key', action: 'generate_rss_key'
post '/my/reset_api_key', action: 'reset_api_key'
post '/my/generate_api_key', action: 'generate_api_key'
get '/my/access_token', action: 'access_token'
end

@ -54,18 +54,20 @@ describe 'my', type: :feature, js: true do
expect(u.lastname).to eq 'Bar'
end
it 'in Access Tokens they can reset their API key' do
it 'in Access Tokens they can generate their API key' do
visit my_access_token_path
find(:xpath, "//tr[contains(.,'API')]/td/a", text: 'Reset').click
expect(page).to have_content 'Missing API access key'
find(:xpath, "//tr[contains(.,'API')]/td/a", text: 'Generate').click
expect(page).to have_content 'Your API access key was reset.'
expect(page).to have_content 'Your API access key was generated.'
end
it 'in Access Tokens they can reset their RSS key' do
it 'in Access Tokens they can generate their RSS key' do
visit my_access_token_path
find(:xpath, "//tr[contains(.,'RSS')]/td/a", text: 'Reset').click
expect(page).to have_content 'Missing RSS access key'
find(:xpath, "//tr[contains(.,'RSS')]/td/a", text: 'Generate').click
expect(page).to have_content 'Your RSS access key was reset.'
expect(page).to have_content 'Your RSS access key was generated.'
end
end
end

Loading…
Cancel
Save