mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 02:04:33 +08:00
Add connected accounts section to settings [SCI-4106]
This commit is contained in:
parent
6b20a10473
commit
f5abb7c767
11 changed files with 164 additions and 23 deletions
|
@ -0,0 +1,19 @@
|
||||||
|
module Users
|
||||||
|
module Settings
|
||||||
|
module Account
|
||||||
|
class ConnectedAccountsController < ApplicationController
|
||||||
|
layout 'fluid'
|
||||||
|
|
||||||
|
def index
|
||||||
|
@linked_accounts = current_user.user_identities.pluck(:provider)
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
current_user.user_identities.where(provider: params.require(:provider)).take&.destroy!
|
||||||
|
@linked_accounts = current_user.user_identities.pluck(:provider)
|
||||||
|
render :index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,7 +18,7 @@ module LeftMenuBarHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def settings_are_selected?
|
def settings_are_selected?
|
||||||
controller_name.in? %(registrations preferences addons teams)
|
controller_name.in? %(registrations preferences addons teams connected_accounts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def activities_are_selected?
|
def activities_are_selected?
|
||||||
|
|
|
@ -2,7 +2,8 @@ module UserSettingsHelper
|
||||||
def on_settings_account_page?
|
def on_settings_account_page?
|
||||||
controller_name == 'registrations' && action_name == 'edit' ||
|
controller_name == 'registrations' && action_name == 'edit' ||
|
||||||
controller_name == 'preferences' && action_name == 'index' ||
|
controller_name == 'preferences' && action_name == 'index' ||
|
||||||
controller_name == 'addons' && action_name == 'index'
|
controller_name == 'addons' && action_name == 'index' ||
|
||||||
|
controller_name == 'connected_accounts'
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_settings_account_profile_page?
|
def on_settings_account_profile_page?
|
||||||
|
@ -21,4 +22,8 @@ module UserSettingsHelper
|
||||||
controller_name.in?(%w(teams audits)) &&
|
controller_name.in?(%w(teams audits)) &&
|
||||||
action_name.in?(%w(index new create show audits_index))
|
action_name.in?(%w(index new create show audits_index))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def on_settings_account_connected_accounts_page?
|
||||||
|
controller_name == 'connected_accounts'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,6 +56,20 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
|
<!-- Connected accounts -->
|
||||||
|
<li class="<%= 'active' if on_settings_account_connected_accounts_page? %>" >
|
||||||
|
<span class="tree-link line-wrap first-indent">
|
||||||
|
<% if on_settings_account_connected_accounts_page? %>
|
||||||
|
<span title="<%= t("users.settings.sidebar.account_nav.connected_accounts") %>">
|
||||||
|
<%= t("users.settings.sidebar.account_nav.connected_accounts") %>
|
||||||
|
</span>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to t("users.settings.sidebar.account_nav.connected_accounts"),
|
||||||
|
connected_accounts_path,
|
||||||
|
data: { 'no-turbolink' => 'true' } %>
|
||||||
|
<% end %>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="col-xs-8 col-sm-9 col-md-9 col-lg-9">
|
||||||
|
<strong><%= t('users.settings.account.connected_accounts.azure_ad.title') %></strong> <br>
|
||||||
|
<p><%= t('users.settings.account.connected_accounts.azure_ad.connect_hint') %></p>
|
||||||
|
</div>
|
||||||
|
<div class="pull-right">
|
||||||
|
<div>
|
||||||
|
<strong>
|
||||||
|
<%= t('users.settings.account.connected_accounts.azure_ad.connected') %>
|
||||||
|
<span class="fas fa-check" aria-hidden="true"></span>
|
||||||
|
</strong>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<%= link_to t('users.settings.account.connected_accounts.azure_ad.unlink_button'),
|
||||||
|
'#unlinkAzureADModal',
|
||||||
|
class: 'btn btn-danger',
|
||||||
|
data: { toggle: 'modal'} %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render partial: 'users/settings/account/connected_accounts/unlink_modals/azure_ad_modal', locals: { provider: provider } %>
|
|
@ -0,0 +1,31 @@
|
||||||
|
<% provide(:head_title, t("users.settings.account.connected_accounts.head_title")) %>
|
||||||
|
|
||||||
|
<%= render partial: "users/settings/sidebar.html.erb" %>
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="tab-pane tab-pane-settings active" role="tabpanel">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-sm-12">
|
||||||
|
<h4><%= t('users.settings.account.connected_accounts.title') %></h4>
|
||||||
|
|
||||||
|
<% if @linked_accounts.any? %>
|
||||||
|
<% @linked_accounts.each do |provider| %>
|
||||||
|
<% if Rails.configuration.x.azure_ad_apps.find { |_,value| value[:provider] == provider } %>
|
||||||
|
<% if lookup_context.exists?(provider, 'users/settings/account/connected_accounts', true) %>
|
||||||
|
<%= render partial: provider %>
|
||||||
|
<% else %>
|
||||||
|
<%= render partial: 'azure_ad', locals: { provider: provider } %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<h5>
|
||||||
|
<i><%= t('users.settings.account.connected_accounts.not_connected') %></i>
|
||||||
|
</h5>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane tab-pane-settings" role="tabpanel"></div>
|
||||||
|
</div>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<div class="modal fade" id="unlinkAzureADModal" tabindex="-1" role="dialog">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="<%= t('general.close') %>">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
<h4 class="modal-title" >
|
||||||
|
<%= t('users.settings.account.connected_accounts.azure_ad.unlink_modal.title') %>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p><%= t('users.settings.account.connected_accounts.azure_ad.unlink_modal.description_1') %></p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<%= form_tag(unlink_connected_account_path, method: :delete) do %>
|
||||||
|
<%= hidden_field_tag :provider, provider %>
|
||||||
|
<%= submit_tag t('users.settings.account.connected_accounts.azure_ad.unlink_modal.submit_button'), class: 'btn btn-danger' %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
Rails.application.configure do
|
Rails.application.configure do
|
||||||
config.x.core_api_sign_alg = ENV['CORE_API_SIGN_ALG'] if ENV['CORE_API_SIGN_ALG']
|
config.x.core_api_sign_alg = ENV['CORE_API_SIGN_ALG'] if ENV['CORE_API_SIGN_ALG']
|
||||||
|
|
||||||
|
@ -8,25 +10,4 @@ Rails.application.configure do
|
||||||
config.x.core_api_rate_limit = ENV['CORE_API_RATE_LIMIT'] ? ENV['CORE_API_RATE_LIMIT'].to_i : 1000
|
config.x.core_api_rate_limit = ENV['CORE_API_RATE_LIMIT'] ? ENV['CORE_API_RATE_LIMIT'].to_i : 1000
|
||||||
|
|
||||||
config.x.core_api_v1_enabled = true if ENV['CORE_API_V1_ENABLED']
|
config.x.core_api_v1_enabled = true if ENV['CORE_API_V1_ENABLED']
|
||||||
|
|
||||||
vars = ENV.select { |name, _| name =~ /^[[:alnum:]]*_AZURE_AD_APP_ID/ }
|
|
||||||
vars.each do |name, value|
|
|
||||||
app_name = name.sub('_AZURE_AD_APP_ID', '')
|
|
||||||
config.x.azure_ad_apps[value] = {}
|
|
||||||
|
|
||||||
iss = ENV["#{app_name}_AZURE_AD_ISS"]
|
|
||||||
raise StandardError, "No ISS for #{app_name} Azure app" unless iss
|
|
||||||
|
|
||||||
config.x.azure_ad_apps[value][:iss] = iss
|
|
||||||
|
|
||||||
conf_url = ENV["#{app_name}_AZURE_AD_CONF_URL"]
|
|
||||||
raise StandardError, "No CONF_URL for #{app_name} Azure app" unless conf_url
|
|
||||||
|
|
||||||
config.x.azure_ad_apps[value][:conf_url] = conf_url
|
|
||||||
|
|
||||||
provider = ENV["#{app_name}_AZURE_AD_PROVIDER_NAME"]
|
|
||||||
raise StandardError, "No PROVIDER_NAME for #{app_name} Azure app" unless provider
|
|
||||||
|
|
||||||
config.x.azure_ad_apps[value][:provider] = provider
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
24
config/initializers/azure_ad.rb
Normal file
24
config/initializers/azure_ad.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
Rails.application.configure do
|
||||||
|
vars = ENV.select { |name, _| name =~ /^[[:alnum:]]*_AZURE_AD_APP_ID/ }
|
||||||
|
vars.each do |name, value|
|
||||||
|
app_name = name.sub('_AZURE_AD_APP_ID', '')
|
||||||
|
config.x.azure_ad_apps[value] = {}
|
||||||
|
|
||||||
|
iss = ENV["#{app_name}_AZURE_AD_ISS"]
|
||||||
|
raise StandardError, "No ISS for #{app_name} Azure app" unless iss
|
||||||
|
|
||||||
|
config.x.azure_ad_apps[value][:iss] = iss
|
||||||
|
|
||||||
|
conf_url = ENV["#{app_name}_AZURE_AD_CONF_URL"]
|
||||||
|
raise StandardError, "No CONF_URL for #{app_name} Azure app" unless conf_url
|
||||||
|
|
||||||
|
config.x.azure_ad_apps[value][:conf_url] = conf_url
|
||||||
|
|
||||||
|
provider = ENV["#{app_name}_AZURE_AD_PROVIDER_NAME"]
|
||||||
|
raise StandardError, "No PROVIDER_NAME for #{app_name} Azure app" unless provider
|
||||||
|
|
||||||
|
config.x.azure_ad_apps[value][:provider] = provider
|
||||||
|
end
|
||||||
|
end
|
|
@ -1463,6 +1463,7 @@ en:
|
||||||
profile: "Profile"
|
profile: "Profile"
|
||||||
preferences: "Preferences"
|
preferences: "Preferences"
|
||||||
addons: "Add-ons"
|
addons: "Add-ons"
|
||||||
|
connected_accounts: "Connected Accounts"
|
||||||
account:
|
account:
|
||||||
preferences:
|
preferences:
|
||||||
head_title: "Settings | My preferences"
|
head_title: "Settings | My preferences"
|
||||||
|
@ -1483,6 +1484,19 @@ en:
|
||||||
head_title: "Settings | Add-ons"
|
head_title: "Settings | Add-ons"
|
||||||
title: "Add-ons"
|
title: "Add-ons"
|
||||||
no_addons: "You have no SciNote Add-ons."
|
no_addons: "You have no SciNote Add-ons."
|
||||||
|
connected_accounts:
|
||||||
|
head_title: "Settings | Connected Accounts"
|
||||||
|
title: "Connected Accounts"
|
||||||
|
not_connected: "You have no Connected accounts"
|
||||||
|
azure_ad:
|
||||||
|
title: "Your Azure AD Account"
|
||||||
|
connect_hint: "Allows you to sign in with your Azure AD account."
|
||||||
|
connected: "Connected"
|
||||||
|
unlink_button: "Unlink"
|
||||||
|
unlink_modal:
|
||||||
|
title: "Unlink Azure AD account?"
|
||||||
|
description_1: "Are you sure you would like unlink Azure AD and SciNote accounts?"
|
||||||
|
submit_button: "Submit"
|
||||||
teams:
|
teams:
|
||||||
head_title: "Settings | Teams"
|
head_title: "Settings | Teams"
|
||||||
breadcrumbs:
|
breadcrumbs:
|
||||||
|
|
|
@ -62,6 +62,12 @@ Rails.application.routes.draw do
|
||||||
get 'users/settings/account/addons',
|
get 'users/settings/account/addons',
|
||||||
to: 'users/settings/account/addons#index',
|
to: 'users/settings/account/addons#index',
|
||||||
as: 'addons'
|
as: 'addons'
|
||||||
|
get 'users/settings/account/connected_accounts',
|
||||||
|
to: 'users/settings/account/connected_accounts#index',
|
||||||
|
as: 'connected_accounts'
|
||||||
|
delete 'users/settings/account/connected_accounts',
|
||||||
|
to: 'users/settings/account/connected_accounts#destroy',
|
||||||
|
as: 'unlink_connected_account'
|
||||||
put 'users/settings/account/preferences',
|
put 'users/settings/account/preferences',
|
||||||
to: 'users/settings/account/preferences#update',
|
to: 'users/settings/account/preferences#update',
|
||||||
as: 'update_preferences'
|
as: 'update_preferences'
|
||||||
|
|
Loading…
Reference in a new issue