From 0c7aac1584af52c98dbc64ed1489226282f2d226 Mon Sep 17 00:00:00 2001 From: Peter Lehwess Date: Tue, 6 Oct 2015 16:15:22 +0200 Subject: [PATCH] Clean up user experiance for generating tokens for the first time --- app/controllers/my_controller.rb | 16 ++++++++++ app/views/my/access_token.html.erb | 50 +++++++++++++++++++++--------- config/locales/en.yml | 3 ++ config/routes.rb | 2 ++ spec/features/users/my_spec.rb | 14 +++++---- 5 files changed, 65 insertions(+), 20 deletions(-) diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 53091a3501..1512f1b44b 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.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 diff --git a/app/views/my/access_token.html.erb b/app/views/my/access_token.html.erb index ae7fd9471f..a19f764c6c 100644 --- a/app/views/my/access_token.html.erb +++ b/app/views/my/access_token.html.erb @@ -78,16 +78,13 @@ See doc/COPYRIGHT.rdoc for more details. <% if Setting.feeds_enabled? %> + <% if @user.rss_token %> <%= l(:label_feeds_access_key_type) %> - <% if @user.rss_token %> - - <%= format_time(@user.rss_token.created_on.to_s) %> - - <% else %> - <%= l(:label_missing_feeds_access_key) %> - <% end %> + + <%= format_time(@user.rss_token.created_on.to_s) %> + <%= I18n.t('my_account.access_tokens.indefinite_expiration') %> @@ -105,18 +102,29 @@ See doc/COPYRIGHT.rdoc for more details. + <% else %> + + <%= l(:label_feeds_access_key_type) %> + <%= l(:label_missing_feeds_access_key) %> + + + <%= link_to l(:button_generate), + { action: 'generate_rss_key' }, + method: :post, + class: 'icon icon-key-1' %> + + + + <% end %> <% end %> <% if Setting.rest_api_enabled? %> + <% if @user.api_token %> <%= l(:label_api_access_key_type) %> - <% if @user.api_token %> - - <%= format_time(@user.api_token.created_on.to_s) %> - - <% else %> - <%= l(:label_missing_api_access_key) %> - <% end %> + + <%= format_time(@user.api_token.created_on.to_s) %> + <%= I18n.t('my_account.access_tokens.indefinite_expiration') %> @@ -134,6 +142,20 @@ See doc/COPYRIGHT.rdoc for more details. + <% else %> + + <%= l(:label_api_access_key_type) %> + <%= l(:label_missing_api_access_key) %> + + + <%= link_to l(:button_generate), + { action: 'generate_api_key' }, + method: :post, + class: 'icon icon-key-1' %> + + + + <% end %> <% end %> <%= call_hook(:view_access_tokens_table, user: @user) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index dc198926a5..0f6b56195f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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." diff --git a/config/routes.rb b/config/routes.rb index 9b0c0d2c0e..05abb031ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/features/users/my_spec.rb b/spec/features/users/my_spec.rb index 931bc5db73..e77b0a87e8 100644 --- a/spec/features/users/my_spec.rb +++ b/spec/features/users/my_spec.rb @@ -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