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
Services + Contracts
Oliver Günther69946a637c73
diff --git a/modules/auth_saml/app/constants/saml/defaults.rb b/modules/auth_saml/app/constants/saml/defaults.rbnew file mode 100644index 00000000000..c6e930816af--- /dev/null+++ b/modules/auth_saml/app/constants/saml/defaults.rb@@ -0,0 +1,64 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 Saml+ module Defaults+ NAME_IDENTIFIER_FORMAT = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'.freeze+ MAIL_MAPPING = %w[mail email Email emailAddress emailaddress+ urn:oid:0.9.2342.19200300.100.1.3 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress].freeze++ FIRSTNAME_MAPPING = %w[givenName givenname given_name given_name+ urn:oid:2.5.4.42 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname].freeze++ LASTNAME_MAPPING = %w[surname sur_name sn+ urn:oid:2.5.4.4 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname].freeze++ REQUESTED_ATTRIBUTES = [+ {+ "name" => "mail",+ "name_format" => "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",+ "friendly_name" => "Email address",+ "is_required" => true+ },+ {+ "name" => "givenName",+ "name_format" => "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",+ "friendly_name" => "Given name",+ "is_required" => true+ },+ {+ "name" => "sn",+ "name_format" => "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",+ "friendly_name" => "Family name",+ "is_required" => true+ }+ ].freeze+ end+enddiff --git a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb b/modules/auth_saml/app/contracts/saml/providers/base_contract.rbnew file mode 100644index 00000000000..63a5c164f0b--- /dev/null+++ b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb@@ -0,0 +1,40 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 Saml+ module Providers+ class BaseContract < ModelContract+ include RequiresAdminGuard++ def self.model+ Saml::Provider+ end++ attribute :display_name+ end+ end+enddiff --git a/modules/auth_saml/app/contracts/saml/providers/create_contract.rb b/modules/auth_saml/app/contracts/saml/providers/create_contract.rbnew file mode 100644index 00000000000..555aeac3604--- /dev/null+++ b/modules/auth_saml/app/contracts/saml/providers/create_contract.rb@@ -0,0 +1,33 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 Saml+ module Providers+ class CreateContract < BaseContract+ end+ end+enddiff --git a/modules/auth_saml/app/contracts/saml/providers/delete_contract.rb b/modules/auth_saml/app/contracts/saml/providers/delete_contract.rbnew file mode 100644index 00000000000..aae9539da9f--- /dev/null+++ b/modules/auth_saml/app/contracts/saml/providers/delete_contract.rb@@ -0,0 +1,35 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 Saml+ module Providers+ class DeleteContract < ::DeleteContract+ delete_permission :admin+ end+ end+enddiff --git a/modules/auth_saml/app/contracts/saml/providers/update_contract.rb b/modules/auth_saml/app/contracts/saml/providers/update_contract.rbnew file mode 100644index 00000000000..90e4bf6fd0f--- /dev/null+++ b/modules/auth_saml/app/contracts/saml/providers/update_contract.rb@@ -0,0 +1,34 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 Saml+ module Providers+ class UpdateContract < News::BaseContract+ end+ end+enddiff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rbindex 2e9e42b006d..5a1086bd237 100644--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb@@ -29,12 +29,15 @@ module Samlenddef create- @provider = ::Saml::Provider.new(**create_params)+ call = ::Saml::Providers::CreateService+ .new(user: User.current)+ .call(**create_params)- if @provider.save+ if call.success?flash[:notice] = I18n.t(:notice_successful_create)- redirect_to saml_provider_path(@provider)+ redirect_to saml_provider_path(call.result)else+ @provider = call.resultrender action: :newendend@@ -52,7 +55,10 @@ module Samlenddef destroy- if @provider.destroy+ call = ::Saml::Providers::DeleteService+ .new(model: @provider, user: User.current)++ if call.success?flash[:notice] = I18n.t(:notice_successful_delete)elseflash[:error] = I18n.t(:error_failed_to_delete_entry)@@ -100,7 +106,7 @@ module Samlenddef create_params- params.require(:saml_provider).permit(:name, :display_name, :identifier, :secret, :limit_self_registration)+ params.require(:saml_provider).permit(:display_name)enddef update_params@@ -108,15 +114,9 @@ module Samlenddef find_provider- @provider = providers.find { |provider| provider.id.to_s == params[:id].to_s }- if @provider.nil?- render_404- end- end-- def providers- @providers ||= OpenProject::AuthSaml.providers+ @provider = Saml::Provider.find(params[:id])+ rescue ActiveRecord::RecordNotFound+ render_404end- helper_method :providersendenddiff --git a/modules/auth_saml/app/models/saml/provider.rb b/modules/auth_saml/app/models/saml/provider.rbindex b4166f4b6bf..abc2e786405 100644--- a/modules/auth_saml/app/models/saml/provider.rb+++ b/modules/auth_saml/app/models/saml/provider.rb@@ -2,49 +2,20 @@ module Samlclass Provider < ApplicationRecordself.table_name = "saml_providers"- DEFAULT_NAME_IDENTIFIER_FORMAT = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'.freeze- DEFAULT_MAIL_MAPPING = %w[mail email Email emailAddress emailaddress- urn:oid:0.9.2342.19200300.100.1.3 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress].freeze+ belongs_to :creator, class_name: "User"- DEFAULT_FIRSTNAME_MAPPING = %w[givenName givenname given_name given_name- urn:oid:2.5.4.42 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname].freeze-- DEFAULT_LASTNAME_MAPPING = %w[surname sur_name sn- urn:oid:2.5.4.4 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname].freeze-- DEFAULT_REQUESTED_ATTRIBUTES = [- {- "name" => "mail",- "name_format" => "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",- "friendly_name" => "Email address",- "is_required" => true- },- {- "name" => "givenName",- "name_format" => "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",- "friendly_name" => "Given name",- "is_required" => true- },- {- "name" => "sn",- "name_format" => "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",- "friendly_name" => "Family name",- "is_required" => true- }- ].freeze-- store_attribute :options, :sp_entity_id, :string, default: -> { OpenProject::StaticRouting::StaticUrlHelpers.new.root_url }- store_attribute :options, :name_identifier_format, :string, default: -> { DEFAULT_NAME_IDENTIFIER_FORMAT }+ store_attribute :options, :sp_entity_id, :string+ store_attribute :options, :name_identifier_format, :stringstore_attribute :options, :metadata_url, :stringstore_attribute :options, :metadata_xml, :string- store_attribute :options, :mapping_login, :json, default: -> { DEFAULT_MAIL_MAPPING }- store_attribute :options, :mapping_mail, :json, default: -> { DEFAULT_MAIL_MAPPING }- store_attribute :options, :mapping_firstname, :json, default: -> { DEFAULT_FIRSTNAME_MAPPING }- store_attribute :options, :mapping_lastname, :json, default: -> { DEFAULT_LASTNAME_MAPPING }+ store_attribute :options, :mapping_login, :json+ store_attribute :options, :mapping_mail, :json+ store_attribute :options, :mapping_firstname, :json+ store_attribute :options, :mapping_lastname, :jsonstore_attribute :options, :mapping_uid, :json- store_attribute :options, :request_attributes, :json, default: -> { DEFAULT_REQUESTED_ATTRIBUTES }+ store_attribute :options, :request_attributes, :jsonattr_accessor :readonlyvalidates_presence_of :display_namediff --git a/modules/auth_saml/app/services/saml/providers/create_service.rb b/modules/auth_saml/app/services/saml/providers/create_service.rbnew file mode 100644index 00000000000..45edbfdcf92--- /dev/null+++ b/modules/auth_saml/app/services/saml/providers/create_service.rb@@ -0,0 +1,34 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 Saml+ module Providers+ class CreateService < BaseServices::Create+ end+ end+enddiff --git a/modules/auth_saml/app/services/saml/providers/delete_service.rb b/modules/auth_saml/app/services/saml/providers/delete_service.rbnew file mode 100644index 00000000000..ea5bae1a445--- /dev/null+++ b/modules/auth_saml/app/services/saml/providers/delete_service.rb@@ -0,0 +1,33 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 Saml+ module Providers+ class DeleteService < BaseServices::Delete+ end+ end+enddiff --git a/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb b/modules/auth_saml/app/services/saml/providers/set_attributes_service.rbnew file mode 100644index 00000000000..3ecb58d06df--- /dev/null+++ b/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb@@ -0,0 +1,66 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 Saml+ module Providers+ class SetAttributesService < BaseServices::SetAttributes+ include Attachments::SetReplacements++ private++ def set_default_attributes(*)+ model.change_by_system do+ set_default_creator+ set_attribute_mapping+ set_issuer+ set_name_identifier_format+ end+ end++ def set_name_identifier_format+ model.name_identifier_format ||= Saml::Defaults::NAME_IDENTIFIER_FORMAT+ end++ def set_default_creator+ model.creator = user+ end++ def set_attribute_mapping+ model.mapping_login ||= Saml::Defaults::MAIL_MAPPING+ model.mapping_mail ||= Saml::Defaults::MAIL_MAPPING+ model.mapping_firstname ||= Saml::Defaults::FIRSTNAME_MAPPING+ model.mapping_lastname ||= Saml::Defaults::LASTNAME_MAPPING+ model.request_attributes ||= Saml::Defaults::REQUESTED_ATTRIBUTES+ end++ def set_issuer+ model.sp_entity_id ||= OpenProject::StaticRouting::StaticUrlHelpers.new.root_url+ end+ end+ end+enddiff --git a/modules/auth_saml/app/services/saml/providers/update_service.rb b/modules/auth_saml/app/services/saml/providers/update_service.rbnew file mode 100644index 00000000000..558bd3cb02a--- /dev/null+++ b/modules/auth_saml/app/services/saml/providers/update_service.rb@@ -0,0 +1,34 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 Saml+ module Providers+ class UpdateService < BaseServices::Update+ end+ end+end