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
Merge remote-tracking branch 'origin/dev' into implementation/50256-add-invite-functionality-on-sharing-2
Henriette Darge50801c3aecee
diff --cc app/controllers/concerns/member_creation.rbindex f5f9e27232e,00000000000..3a1f0411a72mode 100644,000000..100644--- a/app/controllers/concerns/member_creation.rb+++ b/app/controllers/concerns/member_creation.rb@@@ -1,115 -1,0 +1,115 @@@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 MemberCreation+ module_function++ def create_members+ overall_result = nil++ each_new_member_param do |member_params|+ service_call = Members::CreateService+ .new(user: current_user)+ .call(member_params)++ if overall_result+ overall_result.merge!(service_call)+ else+ overall_result = service_call+ end+ end++ overall_result+ end++ def each_new_member_param+ user_ids = user_ids_for_new_members(params[:member])++ group_ids = Group.where(id: user_ids).pluck(:id)++ user_ids.sort_by! { |id| group_ids.include?(id) ? 1 : -1 }++ user_ids.each do |id|+ yield permitted_params.member.merge(user_id: id, project: @project)+ end+ end++ def user_ids_for_new_members(member_params)+ invite_new_users possibly_separated_ids_for_entity(member_params, :user)+ end++ def invite_new_users(user_ids)+ user_ids.filter_map do |id|+ if id.to_i == 0 && id.present? # we've got an email - invite that user+ # Only users with the create_user permission can add users.- if current_user.allowed_to_globally?(:create_user) && enterprise_allow_new_users?++ if current_user.allowed_globally?(:create_user) && enterprise_allow_new_users?+ # The invitation can pretty much only fail due to the user already+ # having been invited. So look them up if it does.+ user = UserInvitation.invite_new_user(email: id) ||+ User.find_by_mail(id)++ user&.id+ end+ else+ id+ end+ end+ end++ def enterprise_allow_new_users?+ !OpenProject::Enterprise.user_limit_reached? || !OpenProject::Enterprise.fail_fast?+ end++ def each_comma_separated(array, &block)+ array.map do |e|+ if e.to_s.match? /\d(,\d)*/+ block.call(e)+ else+ e+ end+ end.flatten+ end++ def transform_array_of_comma_separated_ids(array)+ return array if array.blank?++ each_comma_separated(array) do |elem|+ elem.to_s.split(',')+ end+ end++ def possibly_separated_ids_for_entity(array, entity = :user)+ if !array[:"#{entity}_ids"].nil?+ transform_array_of_comma_separated_ids(array[:"#{entity}_ids"])+ elsif !array[:"#{entity}_id"].nil? && (id = array[:"#{entity}_id"]).present?+ [id]+ else+ []+ end+ end+enddiff --cc app/forms/work_packages/share/invitee.rbindex 8c93ae6995c,736fe88d568..b6b1abba4b1--- a/app/forms/work_packages/share/invitee.rb+++ b/app/forms/work_packages/share/invitee.rb@@@ -42,8 -45,6 +42,8 @@@ module WorkPackages::Sharfilters: [{ name: 'type', operator: '=', values: %w[User Group] },{ name: 'id', operator: '!', values: [::Queries::Filters::MeValue::KEY] }],searchKey: 'any_name_attribute',- addTag: User.current.allowed_to_globally?(:create_user),++ addTag: User.current.allowed_globally?(:create_user),+ addTagText: I18n.t('members.send_invite_to'),focusDirectly: true,appendTo: 'body',disabled: @disabled