From 2ab5a49b0d5672f936d0ae226a251030e7971cd9 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 11 Feb 2015 16:58:40 +0000 Subject: [PATCH] env override for hidden menu items; + docs --- doc/CONFIGURATION.md | 76 ++++++++++++++++------- lib/open_project/configuration.rb | 4 +- lib/open_project/configuration/helpers.rb | 34 ++++++---- 3 files changed, 79 insertions(+), 35 deletions(-) diff --git a/doc/CONFIGURATION.md b/doc/CONFIGURATION.md index d158ae4a78..703fafb6f1 100644 --- a/doc/CONFIGURATION.md +++ b/doc/CONFIGURATION.md @@ -83,6 +83,8 @@ storage config above like this: * [`omniauth_direct_login_provider`](#omniauth-direct-login-provider) (default: nil) * [`disable_password_login`](#disable-password-login) (default: false) * [`attachments_storage`](#attachments-storage) (default: file) +* [`hidden_menu_items`](#hidden-menu-items) (default: {}) +* [`disabled_modules`](#disabled-modules) (default: []) ### disable password login @@ -147,34 +149,64 @@ In the case of fog you only have to configure everything under `fog`, however. D to `fog` just yet. Instead leave it as `file`. This is because the current attachments storage is used as the source for the migration. -#### Hide menu items +### hidden menu items -By default user may choose which menu items can be disabled, -they should be listed as an array in yml format. -More information regarding yml format you can find here: -http://symfony.com/doc/current/components/yaml/yaml_format.html +*default: {}* + +You can disable specific menu items in the menu sidebar for each main menu (such as Administration and Projects). +The following example disables all menu items except 'Users', 'Groups' and 'Custom fields' under 'Administration': + +``` +hidden_menu_items: + admin_menu: + - roles + - types + - statuses + - workflows + - enumerations + - settings + - ldap_authentication + - colors + - project_types + - export_card_configurations + - plugins + - info +``` + +The configuration can be overridden through environment variables. +You have to define one variable for each menu. +For instance 'Roles' and 'Types' under 'Administration' can be disabled by defining the following variable: + +``` +OPENPROJECT_HIDDEN__MENU__ITEMS_ADMIN__MENU='roles types' +``` + +### disabled modules + +*default: []* + +Modules may be disabled through the configuration. +Just give a list of the module names either as an array or as a string with values separated by spaces. + +**Array example:** ``` -production: - hidden_menu_items: - admin_menu: - - roles - - types - - statuses - - workflows - - enumerations - - settings - - ldap_authentication - - colors - - project_types - - export_card_configurations - - plugins - - info +disabled_modules: + - backlogs + - meetings ``` -Or it can be overridden by by an environment variable: +**String example:** - OPENPROJECT_HIDDEN__MENU__ITEMS_ADMIN__MENU='roles types' +``` +disabled_modules: backlogs meetings +``` + +The option to use a string is mostly relevant for when you want to override the disabled modules via ENV variables: + +``` +OPENPROJECT_DISABLED__MODULES='backlogs meetings' +``` ## Email configuration diff --git a/lib/open_project/configuration.rb b/lib/open_project/configuration.rb index 667d13368d..9fcd77ec26 100644 --- a/lib/open_project/configuration.rb +++ b/lib/open_project/configuration.rb @@ -75,8 +75,8 @@ module OpenProject 'omniauth_direct_login_provider' => nil, 'disable_password_choice' => false, - # allow to disable default modules - 'disabled_modules' => [], + + 'disabled_modules' => [], # allow to disable default modules 'hidden_menu_items' => {} } diff --git a/lib/open_project/configuration/helpers.rb b/lib/open_project/configuration/helpers.rb index 5aaa856c18..e54ee53da0 100644 --- a/lib/open_project/configuration/helpers.rb +++ b/lib/open_project/configuration/helpers.rb @@ -70,6 +70,18 @@ module OpenProject available_file_uploaders[OpenProject::Configuration.attachments_storage.to_sym] end + def hidden_menu_items + menus = self['hidden_menu_items'].map do |label, nodes| + [label, array(nodes)] + end + + Hash[menus] + end + + def disabled_modules + array self['disabled_modules'] + end + def available_file_uploaders { fog: ::FogFileUploader, @@ -77,20 +89,20 @@ module OpenProject } end - # overrides default getter in OpenProject::Configuration - def hidden_menu_items - menus = self['hidden_menu_items'].map do |label, nodes| - if nodes =~ / / - [label, nodes.split(' ')] - else - [label, nodes] - end + private + + ## + # Yields the given configuration value as an array. + # Either the value already is an array or a string with values separated by spaces. + # In the latter case the string will be split and the values returned as an array. + def array(value) + if value =~ / / + value.split ' ' + else + value end - Hash[menus] end - private - def true?(value) ['true', true].include? value # check string to accommodate ENV override end