Skip to content

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

Allow to permit additional parameters in `PermittedParams#settings`

Christophe Bliardb2f0a339a5b0
diff --git a/app/controllers/admin/settings/api_settings_controller.rb b/app/controllers/admin/settings/api_settings_controller.rb
index 249c390e3ce..f7aae0d4d18 100644
--- a/app/controllers/admin/settings/api_settings_controller.rb
+++ b/app/controllers/admin/settings/api_settings_controller.rb
@@ -39,5 +39,11 @@ module Admin::Settings
settings["apiv3_cors_origins"] = settings["apiv3_cors_origins"].split(/\r?\n/)
end
end
+
+ def extra_permitted_filters
+ # attachment_whitelist is normally permitted as an array parameter.
+ # Explicitly permit it as a string here.
+ [:apiv3_cors_origins]
+ end
end
end
diff --git a/app/controllers/admin/settings/attachments_settings_controller.rb b/app/controllers/admin/settings/attachments_settings_controller.rb
index 8ab3bb5e6f4..7929473435a 100644
--- a/app/controllers/admin/settings/attachments_settings_controller.rb
+++ b/app/controllers/admin/settings/attachments_settings_controller.rb
@@ -41,5 +41,11 @@ module Admin::Settings
settings["attachment_whitelist"] = settings["attachment_whitelist"].split(/\r?\n/)
end
end
+
+ def extra_permitted_filters
+ # attachment_whitelist is normally permitted as an array parameter.
+ # Explicitly permit it as a string here.
+ [:attachment_whitelist]
+ end
end
end
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
index 8d9823ced5a..c7daac6c37d 100644
--- a/app/controllers/admin/settings_controller.rb
+++ b/app/controllers/admin/settings_controller.rb
@@ -90,7 +90,17 @@ module Admin
end
def settings_params
- permitted_params.settings.to_h
+ permitted_params.settings(*extra_permitted_filters).to_h
+ end
+
+ # Override to allow additional permitted parameters.
+ #
+ # Useful when the format of the setting in the parameters is different from
+ # the expected format in the setting definition, for instance a setting is
+ # an array in the definition but is passed as a string to be split in the
+ # parameters.
+ def extra_permitted_filters
+ nil
end
def update_service
diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb
index 107ead67dfa..241c79b26db 100644
--- a/app/models/permitted_params.rb
+++ b/app/models/permitted_params.rb
@@ -179,8 +179,8 @@ class PermittedParams
params.require(:status).permit(*self.class.permitted_attributes[:status])
end
- def settings
- params.require(:settings).permit(*AllowedSettings.filters)
+ def settings(extra_permitted_filters = nil)
+ params.require(:settings).permit(*AllowedSettings.filters, *extra_permitted_filters)
end
def user(additional_params = [])