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

Add setting for whitelist

Oliver Günther84cafdbe072b
diff --git a/app/controllers/admin/settings/attachments_settings_controller.rb b/app/controllers/admin/settings/attachments_settings_controller.rb
new file mode 100644
index 00000000000..fcd768575d0
--- /dev/null
+++ b/app/controllers/admin/settings/attachments_settings_controller.rb
@@ -0,0 +1,47 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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-2013 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 Admin::Settings
+ class AttachmentsSettingsController < ::Admin::SettingsController
+ menu_item :settings_attachments
+
+ def default_breadcrumb
+ t(:'attributes.attachments')
+ end
+
+ private
+
+ def settings_params
+ super.tap do |settings|
+ settings["attachment_whitelist"] = settings["attachment_whitelist"].split(/\r?\n/)
+ end
+ end
+ end
+end
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb
index 94cca1dbbdb..ff50fb10352 100644
--- a/app/helpers/settings_helper.rb
+++ b/app/helpers/settings_helper.rb
@@ -51,6 +51,11 @@ module SettingsHelper
controller: '/admin/settings/projects_settings',
label: :label_project_plural
},
+ {
+ name: 'attachments',
+ controller: '/admin/settings/attachments_settings',
+ label: :'attributes.attachments'
+ },
{
name: 'api',
controller: '/admin/settings/api_settings',
diff --git a/app/views/admin/settings/attachments_settings/show.html.erb b/app/views/admin/settings/attachments_settings/show.html.erb
new file mode 100644
index 00000000000..f31ac9d4994
--- /dev/null
+++ b/app/views/admin/settings/attachments_settings/show.html.erb
@@ -0,0 +1,48 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-2021 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-2013 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.
+
+++#%>
+<%= toolbar title: t(:'attributes.attachments') %>
+
+<%= styled_form_tag(admin_settings_update_attachments_path, method: :patch) do %>
+ <section class="form--section">
+ <div class="form--field">
+ <%= setting_text_field :attachment_max_size, size: 6, unit: t(:"number.human.storage_units.units.kb"), container_class: '-slim' %>
+ </div>
+ <div class="form--field">
+ <%= setting_text_area :attachment_whitelist, rows: 5, container_class: '-wide' %>
+ <div class="form--field-instructions">
+ <%= t('settings.attachments.whitelist_text_html',
+ ext_example: '*.jpg',
+ mime_example: 'image/jpeg',
+ ) %>
+ </div>
+ </div>
+ </section>
+
+ <%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %>
+<% end %>
diff --git a/app/views/admin/settings/general_settings/show.html.erb b/app/views/admin/settings/general_settings/show.html.erb
index 2f14fed50cb..a55b99690c9 100644
--- a/app/views/admin/settings/general_settings/show.html.erb
+++ b/app/views/admin/settings/general_settings/show.html.erb
@@ -31,9 +31,6 @@ See docs/COPYRIGHT.rdoc for more details.
<%= styled_form_tag(admin_settings_update_general_path, method: :patch) do %>
<section class="form--section">
<div class="form--field"><%= setting_text_field :app_title, size: 30, container_class: '-middle' %></div>
- <div class="form--field">
- <%= setting_text_field :attachment_max_size, size: 6, unit: t(:"number.human.storage_units.units.kb"), container_class: '-slim' %>
- </div>
<div class="form--field">
<%= setting_text_field :per_page_options, size: 20, container_class: '-slim' %>
<span class="form--field-instructions">
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 55359632079..0d039307f17 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2328,6 +2328,7 @@ en:
If CORS is enabled, these are the origins that are allowed to access OpenProject API.
<br/>
Please check the <a href="%{origin_link}" target="_blank">Documentation on the Origin header</a> on how to specify the expected values.
+ setting_attachment_whitelist: "Attachment upload whitelist"
setting_email_delivery_method: "Email delivery method"
setting_sendmail_location: "Location of the sendmail executable"
setting_smtp_enable_starttls_auto: "Automatically use STARTTLS if available"
@@ -2443,6 +2444,19 @@ en:
passwords: "Passwords"
session: "Session"
brute_force_prevention: "Automated user blocking"
+ attachments:
+ whitelist_text_html: >
+ Define a list of valid file extensions and/or mime types for uploaded files.
+ <br/>
+ Enter file extensions (e.g., <code>%{ext_example}</code>) or mime types (e.g., <code>%{mime_example}</code>).
+ <br/>
+ Leave empty to allow any file type to be uploaded.
+ Multiple values allowed (one line for each value).
+ notifications:
+ retention_text: >
+ Set the number of days notification events for users (the source for in-app notifications)
+ will be kept in the system. Any events older than this time will be deleted.
+ delay_minutes_explanation: "Email sending can be delayed to allow users with configured in app notification to confirm the notification within the application before a mail is sent out. Users who read a notification within the application will not receive an email for the already read notification."
display:
first_date_of_week_and_year_set: >
If either options "%{day_of_week_setting_name}" or "%{first_week_setting_name}" are set,
diff --git a/config/settings.yml b/config/settings.yml
index 3a46d7cd541..c5fcedbf9e9 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -326,8 +326,6 @@ session_ttl_enabled:
session_ttl:
format: int
default: 120
-default_notification_option:
- default: 'only_my_events'
emails_header:
serialized: true
default:
@@ -381,3 +379,6 @@ apiv3_cors_enabled:
apiv3_cors_origins:
serialized: true
default: []
+attachment_whitelist:
+ serialized: true
+ default: []
diff --git a/lib/api/v3/attachments/attachment_metadata_representer.rb b/lib/api/v3/attachments/attachment_parsing_representer.rb
similarity index 100%
rename from lib/api/v3/attachments/attachment_metadata_representer.rb
rename to lib/api/v3/attachments/attachment_parsing_representer.rb