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
Fix: Always allow custom styles when in BIM edition (#8813)
Wieland Lindenthal5b084dccd72f
diff --git a/app/helpers/custom_styles_helper.rb b/app/helpers/custom_styles_helper.rbnew file mode 100644index 00000000000..5967b7c8780--- /dev/null+++ b/app/helpers/custom_styles_helper.rb@@ -0,0 +1,47 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++module CustomStylesHelper+ def apply_custom_styles?(skip_ee_check: OpenProject::Configuration.bim?)+ # Apply custom styles either if EE allows OR we are on a BIM edition with the BIM theme active.+ CustomStyle.current.present? &&+ (EnterpriseToken.allows_to?(:define_custom_style) || skip_ee_check)+ end++ # The default favicon and touch icons are both the same for normal OP and BIM.+ def apply_custom_favicon?+ apply_custom_styles?(skip_ee_check: false) && CustomStyle.current.favicon.present?+ end++ # The default favicon and touch icons are both the same for normal OP and BIM.+ def apply_custom_touch_icon?+ apply_custom_styles?(skip_ee_check: false) && CustomStyle.current.touch_icon.present?+ end+enddiff --git a/app/views/common/_favicons.html.erb b/app/views/common/_favicons.html.erbindex 27faad36db4..9470c2ca1db 100644--- a/app/views/common/_favicons.html.erb+++ b/app/views/common/_favicons.html.erb@@ -1,10 +1,10 @@<% begin %>-<% unless (EnterpriseToken.allows_to?(:define_custom_style) && CustomStyle.try(:current).present? && CustomStyle.current.favicon.present?) %>+<% unless apply_custom_favicon? %><%= favicon_link_tag OpenProject::CustomStyles::Design.favicon_asset_path %><% end %>-<% unless (EnterpriseToken.allows_to?(:define_custom_style) && CustomStyle.try(:current).present? && CustomStyle.current.touch_icon.present?) %>+<% unless apply_custom_touch_icon? %><%# In the future we can add more sizes should we see 404 errors in the logs. %><%= favicon_link_tag "apple-touch-icon-120x120.png", rel: 'apple-touch-icon',type: 'image/png',diff --git a/app/views/custom_styles/_inline_css_logo.erb b/app/views/custom_styles/_inline_css_logo.erbindex 3269ada6a19..17c8633e8e1 100644--- a/app/views/custom_styles/_inline_css_logo.erb+++ b/app/views/custom_styles/_inline_css_logo.erb@@ -30,7 +30,7 @@ See docs/COPYRIGHT.rdoc for more details.<% cache(CustomStyle.current) do %><style type="text/css"><% logo_url = asset_path("logo_openproject_white_big.png") %>- <% if EnterpriseToken.allows_to?(:define_custom_style) && CustomStyle.try(:current).present? %>+ <% if apply_custom_styles? %><%if CustomStyle.current.logo.present?logo_url = custom_style_logo_path(digest: CustomStyle.current.digest, filename: CustomStyle.current.logo_identifier)diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erbindex fa461197188..d76bfbdf84e 100644--- a/app/views/layouts/base.html.erb+++ b/app/views/layouts/base.html.erb@@ -85,7 +85,7 @@ See docs/COPYRIGHT.rdoc for more details.<!-- page specific tags --><%= content_for(:header_tags) if content_for?(:header_tags) %><%= render partial: "custom_styles/inline_css_logo" %>- <% if EnterpriseToken.allows_to?(:define_custom_style) && CustomStyle.try(:current).present? %>+ <% if apply_custom_styles? %><% cache(CustomStyle.current) do %><%= render partial: "custom_styles/inline_css" %><% if CustomStyle.current.favicon.present? %>diff --git a/modules/bim/app/seeders/bim/basic_data/theme_seeder.rb b/modules/bim/app/seeders/bim/basic_data/theme_seeder.rbindex 5e6cee40a0a..f7b6e13fbd1 100644--- a/modules/bim/app/seeders/bim/basic_data/theme_seeder.rb+++ b/modules/bim/app/seeders/bim/basic_data/theme_seeder.rb@@ -30,7 +30,7 @@ module Bimmodule BasicDataclass ThemeSeeder < Seederdef seed_data!- theme = OpenProject::CustomStyles::ColorThemes.themes.find { |t| t[:theme] == 'OpenProject BIM' }+ theme = OpenProject::CustomStyles::ColorThemes.themes.find { |t| t[:theme] == OpenProject::CustomStyles::ColorThemes::BIM_THEME_NAME }::Design::UpdateDesignService.new(theme)diff --git a/modules/bim/lib/open_project/bim/patches/color_themes_patch.rb b/modules/bim/lib/open_project/bim/patches/color_themes_patch.rbindex 5fd5f194e76..ea311df10b5 100644--- a/modules/bim/lib/open_project/bim/patches/color_themes_patch.rb+++ b/modules/bim/lib/open_project/bim/patches/color_themes_patch.rb@@ -1,5 +1,7 @@require 'open_project/custom_styles/design'+OpenProject::CustomStyles::ColorThemes::BIM_THEME_NAME = 'OpenProject BIM'.freeze+module OpenProject::Bimmodule Patchesmodule ColorThemesPatch@@ -20,7 +22,7 @@ module OpenProject::Bimdef bim_theme{- theme: 'OpenProject BIM',+ theme: OpenProject::CustomStyles::ColorThemes::BIM_THEME_NAME,colors: {'primary-color' => "#3270DB",'primary-color-dark' => "#163473",diff --git a/spec/helpers/custom_styles_helper_spec.rb b/spec/helpers/custom_styles_helper_spec.rbnew file mode 100644index 00000000000..99e0187a15d--- /dev/null+++ b/spec/helpers/custom_styles_helper_spec.rb@@ -0,0 +1,143 @@++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'++describe CustomStylesHelper, type: :helper do+ let(:current_theme) { nil }+ let(:bim_edition?) { false }++ before do+ allow(CustomStyle).to receive(:current).and_return(current_theme)+ allow(OpenProject::Configuration).to receive(:bim?).and_return(bim_edition?)+ end++ describe '.apply_custom_styles?' do+ subject { helper.apply_custom_styles? }++ context 'no CustomStyle present' do+ it 'is falsey' do+ is_expected.to be_falsey+ end+ end++ context 'CustomStyle present' do+ let(:current_theme) { FactoryBot.build_stubbed(:custom_style) }++ context 'without EE' do+ before do+ without_enterprise_token+ end++ context 'no BIM edition' do+ it 'is falsey' do+ is_expected.to be_falsey+ end+ end++ context 'BIM edition' do+ let(:bim_edition?) { true }++ it 'is truthy' do+ is_expected.to be_truthy+ end+ end+ end++ context 'with EE' do+ before do+ with_enterprise_token(:define_custom_style)+ end++ context 'no BIM edition' do+ it 'is truthy' do+ is_expected.to be_truthy+ end+ end++ context 'BIM edition' do+ let(:bim_edition?) { true }++ it 'is truthy' do+ is_expected.to be_truthy+ end+ end+ end+ end+ end++ shared_examples(:apply_when_ee_present) do+ context 'no CustomStyle present' do+ it 'is falsey' do+ is_expected.to be_falsey+ end+ end++ context 'CustomStyle present' do+ let(:current_theme) { FactoryBot.build_stubbed(:custom_style) }++ before do+ allow(current_theme).to receive(:favicon).and_return(true)+ allow(current_theme).to receive(:touch_icon).and_return(true)+ end++ context 'without EE' do+ before do+ without_enterprise_token+ end++ it 'is falsey' do+ is_expected.to be_falsey+ end+ end++ context 'with EE' do+ before do+ with_enterprise_token(:define_custom_style)+ end++ it 'is truthy' do+ is_expected.to be_truthy+ end+ end+ end+ end++ describe '.apply_custom_favicon?' do+ subject { helper.apply_custom_favicon? }++ it_behaves_like :apply_when_ee_present+ end++ describe '.apply_custom_touch_icon?' do+ subject { helper.apply_custom_touch_icon? }++ it_behaves_like :apply_when_ee_present+ end+enddiff --git a/spec/support/enterprise_token_helper.rb b/spec/support/enterprise_token_helper.rbindex 0bf0acbac4e..e8df2072797 100644--- a/spec/support/enterprise_token_helper.rb+++ b/spec/support/enterprise_token_helper.rb@@ -47,6 +47,11 @@ module AuthenticationHelpersallow(OpenProject::Configuration).to receive(:ee_manager_visible?).and_return(false)end++ def without_enterprise_token+ # Calling without params means no EE features are allowed.+ with_enterprise_token+ endendRSpec.configure do |config|