OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[31045] Make auth plugins except developer ee-only
Oliver Günther2f54fe3a06c3
diff --git a/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb b/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rbindex f2e53e4ffb1..514bbe46951 100644--- a/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb+++ b/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb@@ -47,11 +47,22 @@ module OpenProject::Pluginsenddef self.providers_for(strategy)- strategies[strategy_key(strategy)].map(&:call).flatten.map(&:to_hash)+ filtered_strategies strategies[strategy_key(strategy)].map(&:call).flatten.map(&:to_hash)enddef self.providers- strategies.values.flatten.map(&:call).flatten.map(&:to_hash)+ filtered_strategies strategies.values.flatten.map(&:call).flatten.map(&:to_hash)+ end++ def self.filtered_strategies(options)+ options.select do |provider|+ name = provider[:name]&.to_s+ next true if !EnterpriseToken.show_banners? || name == 'developer'++ warn_unavailable(name)++ false+ endenddef self.strategy_key(strategy)@@ -66,11 +77,19 @@ module OpenProject::Plugins[camelization, name].compact.first.underscore.to_symend++ def self.warn_unavailable(name)+ RequestStore.fetch("warn_unavailable_auth_#{name}") do+ Rails.logger.warn { "OmniAuth SSO strategy #{name} is only available for Enterprise Editions." }+ true+ end+ endendclass ProviderBuilderdef strategy(strategy, &providers)key = AuthPlugin.strategy_key(strategy)+if AuthPlugin.strategies.include? keyAuthPlugin.strategies[key] << providerselsediff --git a/modules/auth_saml/lib/open_project/auth_saml/engine.rb b/modules/auth_saml/lib/open_project/auth_saml/engine.rbindex c352925d8fa..4c8d2396cb0 100644--- a/modules/auth_saml/lib/open_project/auth_saml/engine.rb+++ b/modules/auth_saml/lib/open_project/auth_saml/engine.rb@@ -33,6 +33,7 @@ module OpenProjectregister_auth_providers dosettings = Rails.root.join('config', 'plugins', 'auth_saml', 'settings.yml')if settings.exist?+ Rails.logger.info("[auth_saml] Registering saml integration from 'config/plugins/auth_saml/settings.yml'")providers = YAML::load(File.open(settings)).symbolize_keysstrategy :saml doproviders.values.map do |h|@@ -45,8 +46,6 @@ module OpenProjecth.symbolize_keysendend- else- Rails.logger.warn("[auth_saml] Missing settings from '#{settings}', skipping omniauth registration.")endendenddiff --git a/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb b/modules/openid_connect/app/controllers/openid_connect/providers_controller.rbindex 0fde558d8c4..fbd93b08442 100644--- a/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb+++ b/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb@@ -4,6 +4,7 @@ module OpenIDConnectmenu_item :plugin_openid_connectbefore_action :require_admin+ before_action :check_eebefore_action :find_provider, only: [:edit, :update, :destroy]def index; end@@ -53,6 +54,13 @@ module OpenIDConnectprivate+ def check_ee+ if EnterpriseToken.show_banners?+ render template: '/openid_connect/providers/upsale'+ return false+ end+ end+def create_paramsparams.require(:openid_connect_provider).permit(:name, :display_name, :identifier, :secret)enddiff --git a/modules/openid_connect/app/views/openid_connect/providers/upsale.html.erb b/modules/openid_connect/app/views/openid_connect/providers/upsale.html.erbnew file mode 100644index 00000000000..f946f8e78a1--- /dev/null+++ b/modules/openid_connect/app/views/openid_connect/providers/upsale.html.erb@@ -0,0 +1,31 @@+<% html_title(t(:label_administration), t('openid_connect.providers.plural')) -%>+++<%= breadcrumb_toolbar(t('openid_connect.providers.plural')) %>+<div class="notification-box upsale-notification">+ <div class="notification-box--content">+ <h3><%= t('admin.enterprise.upgrade_to_ee') %></h3>+ <%= image_tag "enterprise_edition.png", class: "widget-box--teaser-image" %>++ <p><%= t('homescreen.blocks.upsale.description') %></p>++ <ul class="">+ <li>+ <%= t('homescreen.blocks.upsale.additional_features') %>+ </li>+ <li>+ <%= t('homescreen.blocks.upsale.professional_support') %>+ </li>+ </ul>+ <p>+ <b><%= t('homescreen.blocks.upsale.become_hero') %></b> <%= t('homescreen.blocks.upsale.you_contribute') %>+ </p>+ <%= link_to( "#{OpenProject::Static::Links.links[:upsale][:href]}/?utm_source=unknown&utm_medium=community-edition&utm_campaign=enterprise-openid-connect",+ { class: 'button -alt-highlight',+ aria: {label: t('admin.enterprise.order')},+ title: t('admin.enterprise.order')}) do %>+ <%= op_icon('button--icon icon-add') %>+ <span class="button--text"><%= t('admin.enterprise.order') %></span>+ <% end %>+ </div>+</div>diff --git a/modules/openid_connect/spec/controllers/providers_controller_spec.rb b/modules/openid_connect/spec/controllers/providers_controller_spec.rbindex f67cd427c08..1db9b2a1935 100644--- a/modules/openid_connect/spec/controllers/providers_controller_spec.rb+++ b/modules/openid_connect/spec/controllers/providers_controller_spec.rb@@ -16,6 +16,7 @@ require 'spec_helper'describe ::OpenIDConnect::ProvidersController, type: :controller dolet(:user) { FactoryBot.build_stubbed :admin }+ let(:ee) { true }let(:valid_params) do{@@ -27,6 +28,17 @@ describe ::OpenIDConnect::ProvidersController, type: :controller dobefore dologin_as user+ allow(EnterpriseToken).to receive(:show_banners?).and_return(!ee)+ end++ context 'when not ee' do+ let(:ee) { false }++ it 'renders upsale' do+ get :index+ expect(response.status).to eq 200+ expect(response).to render_template 'openid_connect/providers/upsale'+ endendcontext 'when not admin' dodiff --git a/modules/openid_connect/spec/requests/openid_connect_spec.rb b/modules/openid_connect/spec/requests/openid_connect_spec.rbindex 5664049024c..cade98aa1b7 100644--- a/modules/openid_connect/spec/requests/openid_connect_spec.rb+++ b/modules/openid_connect/spec/requests/openid_connect_spec.rb@@ -46,6 +46,8 @@ describe 'OpenID Connect', type: :rails_request doendbefore do+ allow(EnterpriseToken).to receive(:show_banners?).and_return(false)+# The redirect will include an authorisation code.# Since we don't actually get a valid code in the test we will stub the resulting AccessToken.allow_any_instance_of(OpenIDConnect::Client).to receive(:access_token!) do@@ -137,7 +139,7 @@ describe 'OpenID Connect', type: :rails_request doendcontext 'provider configuration through the settings' do- it 'should make providers that have been configured through settings available without requiring a restart' do+ before doallow(Setting).to receive(:plugin_openproject_openid_connect).and_return('providers' => {'google' => {@@ -150,7 +152,16 @@ describe 'OpenID Connect', type: :rails_request do}})+ end+ it 'will show no option unless EE' do+ allow(EnterpriseToken).to receive(:show_banners?).and_return(true)+ get '/login'+ expect(response.body).not_to match /Google/i+ expect(response.body).not_to match /Azure/i+ end++ it 'should make providers that have been configured through settings available without requiring a restart' doget '/login'expect(response.body).to match /Google/iexpect(response.body).to match /Azure/i