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
Warn about self registration and public projects
Oliver Günther816b74bff55f
diff --git a/app/components/projects/settings/index_page_header_component.html.erb b/app/components/projects/settings/index_page_header_component.html.erbindex 0afbca8cedc..508c6416192 100644--- a/app/components/projects/settings/index_page_header_component.html.erb+++ b/app/components/projects/settings/index_page_header_component.html.erb@@ -61,6 +61,20 @@endend+ if User.current.allowed_in_project?(:edit_project, @project)+ menu.with_item(+ tag: :a,+ label: public? ? t(:button_unpublish) : t(:button_publish),+ href: toggle_public_dialog_project_settings_general_path(@project),+ content_arguments: {+ data: { turbo_stream: true },+ test_selector: "project-settings--toggle-public"+ }+ ) do |item|+ item.with_leading_visual_icon(icon: public? ? :lock : :unlock)+ end+ end+if User.current.allowed_in_project?(:archive_project, @project)menu.with_item(tag: :a,@@ -74,6 +88,7 @@item.with_leading_visual_icon(icon: "lock")endend+if User.current.admin?label = @project.templated ? "remove_from_templates" : "make_template"menu.with_item(diff --git a/app/components/projects/settings/index_page_header_component.rb b/app/components/projects/settings/index_page_header_component.rbindex a57128ce4f0..2a3c3827d82 100644--- a/app/components/projects/settings/index_page_header_component.rb+++ b/app/components/projects/settings/index_page_header_component.rb@@ -36,4 +36,8 @@ class Projects::Settings::IndexPageHeaderComponent < ApplicationComponent@project = projectend++ attr_reader :project++ delegate :public?, to: :projectenddiff --git a/app/components/projects/settings/toggle_public_dialog_component.html.erb b/app/components/projects/settings/toggle_public_dialog_component.html.erbnew file mode 100644index 00000000000..e3808251e22--- /dev/null+++ b/app/components/projects/settings/toggle_public_dialog_component.html.erb@@ -0,0 +1,49 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 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 COPYRIGHT and LICENSE files for more details.++++#%>++<%=+ render(+ Primer::OpenProject::DangerDialog.new(+ id: "projects_toggle_public_confirmation",+ title: t(:title, scope: i18n_scope),+ confirm_button_text: t(:'js.button_confirm'),+ form_arguments: {+ action: toggle_public_project_settings_general_path(@project),+ method: :post,+ data: { turbo: true }+ }+ )+ ) do |dialog|+ dialog.with_confirmation_message do |message|+ message.with_heading(tag: :h2) { t(:title, scope: i18n_scope) }+ message.with_description_content(t(:description, scope: i18n_scope))+ end+ dialog.with_confirmation_check_box_content(t(:checkbox, scope: i18n_scope))+ end+%>diff --git a/app/components/projects/settings/toggle_public_dialog_component.rb b/app/components/projects/settings/toggle_public_dialog_component.rbnew file mode 100644index 00000000000..f4a7f7df795--- /dev/null+++ b/app/components/projects/settings/toggle_public_dialog_component.rb@@ -0,0 +1,51 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 COPYRIGHT and LICENSE files for more details.+#++++module Projects::Settings+ class TogglePublicDialogComponent < ApplicationComponent+ include ApplicationHelper+ include OpTurbo::Streamable++ def initialize(project, back_url: nil)+ super++ @project = project+ @back_url = back_url+ end++ def i18n_scope+ if @project.public?+ "projects.settings.private_confirmation"+ else+ "projects.settings.public_confirmation"+ end+ end+ end+enddiff --git a/app/controllers/projects/settings/general_controller.rb b/app/controllers/projects/settings/general_controller.rbindex e485054f49c..e2c56b3e2a6 100644--- a/app/controllers/projects/settings/general_controller.rb+++ b/app/controllers/projects/settings/general_controller.rb@@ -27,5 +27,23 @@#++class Projects::Settings::GeneralController < Projects::SettingsController+ include OpTurbo::DialogStreamHelper+menu_item :settings_general++ def toggle_public_dialog+ respond_with_dialog Projects::Settings::TogglePublicDialogComponent.new(@project)+ end++ def toggle_public+ call = Projects::UpdateService+ .new(model: @project, user: current_user)+ .call(public: [email protected]?)++ call.on_failure do+ flash[:error] = call.message+ end++ redirect_to action: :show, status: :see_other+ endenddiff --git a/app/models/setting/self_registration.rb b/app/models/setting/self_registration.rbindex d41b3191201..cfe39da6295 100644--- a/app/models/setting/self_registration.rb+++ b/app/models/setting/self_registration.rb@@ -85,5 +85,9 @@ class Settingdef self.automatic?key(value: Setting.self_registration) == :automatic_activationend++ def self.unsupervised_registration?+ by_email? || automatic?+ endendenddiff --git a/app/views/admin/settings/authentication_settings/show.html.erb b/app/views/admin/settings/authentication_settings/show.html.erbindex 78e6914591b..2b4ba182dc7 100644--- a/app/views/admin/settings/authentication_settings/show.html.erb+++ b/app/views/admin/settings/authentication_settings/show.html.erb@@ -45,13 +45,28 @@ See COPYRIGHT and LICENSE files for more details.<legend class="form--fieldset-legend"><%= I18n.t("settings.general") %></legend><div class="form--field"><%= setting_check_box :login_required %></div>- <div class="form--field"><%= setting_select :self_registration, [[t(:label_disabled), Setting::SelfRegistration.disabled.to_s],- [t(:label_registration_activation_by_email), Setting::SelfRegistration.by_email.to_s],- [t(:label_registration_manual_activation), Setting::SelfRegistration.manual.to_s],- [t(:label_registration_automatic_activation), Setting::SelfRegistration.automatic.to_s]],- container_class: "-middle" %>+ <div class="form--field">+ <%= setting_select :self_registration, [[t(:label_disabled), Setting::SelfRegistration.disabled.to_s],+ [t(:label_registration_activation_by_email), Setting::SelfRegistration.by_email.to_s],+ [t(:label_registration_manual_activation), Setting::SelfRegistration.manual.to_s],+ [t(:label_registration_automatic_activation), Setting::SelfRegistration.automatic.to_s]],+ container_class: "-middle" %>+ <div class="form--field-instructions">+ <% if Setting::SelfRegistration.unsupervised_registration? %>+ <%=+ render Primer::Alpha::Banner.new(+ scheme: :warning,+ icon: :alert,+ my: 2+ ) do+ I18n.t(:setting_self_registration_warning)+ end+ %>+ <% end %>+ </div></div>+<div class="form--field"><%= setting_check_box :email_login, title: I18n.t("tooltip.setting_email_login") %></div>@@ -93,8 +108,8 @@ See COPYRIGHT and LICENSE files for more details.<div class="form--field -wide-label"><%= setting_text_field :password_min_length, size: 6, container_class: "-xslim" %></div><div class="form--field -wide-label"><% rules = OpenProject::Passwords::Evaluator.known_rules.map do |rule|- [t("label_password_rule_#{rule}"), rule]- end %>+ [t("label_password_rule_#{rule}"), rule]+ end %><%= setting_multiselect :password_active_rules, rules %></div><div class="form--field -wide-label"><%= setting_text_field :password_min_adhered_rules, size: 6, container_class: "-xslim" %></div>diff --git a/app/views/projects/settings/general/show.html.erb b/app/views/projects/settings/general/show.html.erbindex a52a028bcaa..96de36125da 100644--- a/app/views/projects/settings/general/show.html.erb+++ b/app/views/projects/settings/general/show.html.erb@@ -28,4 +28,24 @@ See COPYRIGHT and LICENSE files for more details.++#%><%= render Projects::Settings::IndexPageHeaderComponent.new(project: @project) %>+<%=+ if @project.public?+ render Primer::Alpha::Banner.new(+ scheme: :warning,+ icon: :alert,+ mb: 2,+ test_selector: "op-projects-public-warning"+ ) do |banner|+ banner.with_action_button(+ tag: :a,+ href: toggle_public_dialog_project_settings_general_path(@project),+ data: { turbo_stream: true },+ size: :medium,+ ) { @project.public? ? t(:button_unpublish) : t(:button_publish) }++ I18n.t("projects.settings.public_warning")+ end+ end+%>+<%= angular_component_tag "opce-project-settings" %>diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex f6fea4b05ef..c27d3c3e540 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -98,7 +98,7 @@ Rails.application.reloader.to_prepare domap.permission :edit_project,{- "projects/settings/general": %i[show],+ "projects/settings/general": %i[show toggle_public toggle_public_dialog],"projects/settings/storage": %i[show],"projects/settings/work_packages": %i[show],"projects/settings/work_packages/activities": %i[show update],diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 1af40bacc6d..f86feed9ca5 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -379,6 +379,22 @@ en:heading: "Delete this project list?"text: "This action will not delete any project the list contains. Are you sure you want to delete this project list?"settings:+ public_warning: >+ This project is public.+ Anyone who has access to this instance will be able to view and interact with this project depending on their role and associated permissions.+ Sub-projects are not affected and have their own settings.+ public_confirmation:+ checkbox: "I understand that this will make the previously private content public"+ title: "Make this project public?"+ description: >+ Anyone who has access to this instance will be able to view and interact with this project depending on their role and authentication settings.+ Sub-projects are not affected and have their own settings.+ private_confirmation:+ checkbox: "I understand that this will make the previously public content private."+ title: "Make this project private?"+ description: >+ The project will only be visible to project members depending on their role and associated permissions.+ Sub-projects are not affected and have their own settings.change_identifier: Change identifieractions:label_enable_all: "Enable all"@@ -3885,6 +3901,10 @@ en:setting_repository_truncate_at: "Maximum number of files displayed in the repository browser"setting_rest_api_enabled: "Enable REST web service"setting_self_registration: "Self-registration"+ setting_self_registration_warning: >+ The user will be able to activate their own accounts.+ Please note that this will give them access to all public projects and their content.+ Please make sure that no sensitive or private data is exposed in public projects.setting_session_ttl: "Session expiry time after inactivity"setting_session_ttl_hint: "Value below 5 works like disabled"setting_session_ttl_enabled: "Session expires"diff --git a/config/routes.rb b/config/routes.rbindex 0c6b8047890..88005a270f4 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -252,7 +252,10 @@ Rails.application.routes.draw doresources :projects, except: %i[show edit create update] doscope module: "projects" donamespace "settings" do- resource :general, only: %i[show], controller: "general"+ resource :general, only: %i[show], controller: "general" do+ get :toggle_public_dialog+ post :toggle_public+ endresource :modules, only: %i[show update]resource :project_custom_fields, only: %i[show] domember dodiff --git a/spec/features/projects/settings/toggle_public_spec.rb b/spec/features/projects/settings/toggle_public_spec.rbnew file mode 100644index 00000000000..54666770906--- /dev/null+++ b/spec/features/projects/settings/toggle_public_spec.rb@@ -0,0 +1,76 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 COPYRIGHT and LICENSE files for more details.+#+++require "spec_helper"++RSpec.describe "Project public/private toggle", :js do+ let(:permissions) { %i[edit_project] }+ let(:project) { create(:project, public: false) }+ let(:general_settings_page) { Pages::Projects::Settings::General.new(project) }++ current_user { create(:user, member_with_permissions: { project => permissions }) }++ it "allows toggling project visibility with confirmation" do+ expect(project).not_to be_public+ general_settings_page.visit!++ page.find_test_selector("project-settings-more-menu").click+ page.find_test_selector("project-settings--toggle-public").click++ expect(page).to have_text I18n.t("projects.settings.public_confirmation.title")++ retry_block do+ check I18n.t("projects.settings.public_confirmation.checkbox")+ click_button "Confirm"+ end++ expect(page).to have_test_selector("op-projects-public-warning")+ expect(page).to have_text(I18n.t("projects.settings.public_warning"))++ project.reload+ expect(project).to be_public++ # Toggle back to private+ page.find_test_selector("project-settings-more-menu").click+ page.find_test_selector("project-settings--toggle-public").click+ expect(page).to have_text I18n.t("projects.settings.private_confirmation.title")++ retry_block do+ check I18n.t("projects.settings.private_confirmation.checkbox")+ click_button "Confirm"+ end++ expect(page).not_to have_test_selector("op-projects-public-warning")+ expect(page).to have_no_text(I18n.t("projects.settings.public_warning"))++ # Verify project is now private+ project.reload+ expect(project).not_to be_public+ end+end