Skip to content

Commit

Permalink
Release OpenProject 14.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed May 8, 2024
2 parents aa7a72a + ba6f50e commit 05595ff
Show file tree
Hide file tree
Showing 370 changed files with 4,076 additions and 3,289 deletions.
2 changes: 1 addition & 1 deletion app/controllers/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def apply_status_p_complete_change
return unless WorkPackage.use_status_for_done_ratio?
return unless @status.default_done_ratio_previously_changed?

WorkPackages::ApplyStatusesPCompleteJob
WorkPackages::Progress::ApplyStatusesPCompleteJob
.perform_later(cause_type: "status_p_complete_changed",
status_name: @status.name,
status_id: @status.id,
Expand Down
1 change: 1 addition & 0 deletions app/forms/work_packages/progress_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def default_field_options(name)
data = { "work-packages--progress--preview-progress-target": "progressInput",
"work-packages--progress--touched-field-marker-target": "progressInput",
action: "input->work-packages--progress--touched-field-marker#markFieldAsTouched" }

if @focused_field == name
data[:"work-packages--progress--focus-field-target"] = "fieldToFocus"
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/announcement_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def announce(user, subject:, body:, body_header: nil, body_subheader: nil)
with_locale_for(user) do
localized_subject = localized(subject)

mail to: user.mail,
mail to: user,
subject: localized_subject do |format|
locals = {
body: localized(body),
Expand Down
25 changes: 19 additions & 6 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ def default_url_options
end
end

def mail(headers = {}, &block)
block ||= method(:default_formats_for_setting)
super(headers, &block)
end

# Sets a Message-ID header.
#
# While the value is set in here, email gateways such as postmark, unless instructed explicitly will assign
Expand Down Expand Up @@ -120,10 +115,28 @@ def default_formats_for_setting(format)
format.text
end

##
# Overwrite mailer method to prevent sending mails to locked users.
def mail(headers = {}, &block)
block ||= method(:default_formats_for_setting)
to = headers[:to]

if to
raise ArgumentError, "Recipient needs to be instance of User" unless to.is_a?(User)

if to.locked?
Rails.logger.info "Not sending #{action_name} mail to locked user #{to.id} (#{to.login})"
return
end
end

super(headers.merge(to: to.mail), &block)
end

def send_localized_mail(user)
with_locale_for(user) do
subject = yield
mail to: user.mail, subject:
mail to: user, subject:
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/mailers/member_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def send_mail(current_user, member, subject, message)

yield if block_given?

mail to: member.principal.mail,
mail to: member.principal,
subject:
end
end
Expand Down
1 change: 1 addition & 0 deletions app/models/journal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Journal < ApplicationRecord
store_accessor :cause,
%i[
type
feature
work_package_id
changed_days
status_name
Expand Down
2 changes: 1 addition & 1 deletion app/services/settings/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def set_setting_value(name, value)
new_value = derive_value(value)
Setting[name] = new_value
if name == :work_package_done_ratio && old_value != "status" && new_value == "status"
WorkPackages::ApplyStatusesPCompleteJob.perform_later(cause_type: "progress_mode_changed_to_status_based")
WorkPackages::Progress::ApplyStatusesPCompleteJob.perform_later(cause_type: "progress_mode_changed_to_status_based")
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 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.
#++

class WorkPackages::Progress::ApplyStatusesPCompleteJob < WorkPackages::Progress::Job
VALID_CAUSE_TYPES = %w[
progress_mode_changed_to_status_based
status_p_complete_changed
].freeze

# Updates % complete and remaining work of all work packages after a status %
# complete value has been changed or the progress calculation mode was set to
# status-based.
#
# It creates a journal entry with the System user describing the change.
#
# @param status_name [String] The cause of the update to be put in the journal
# entry. Must be one of `VALID_CAUSE_TYPES`.
# @param status_name [String] The name of the status to apply.
# @param status_id [Integer] The ID of the status to apply. Not used
# currently, but here in case we need it in a later version.
# @param change [Object] The change object containing an array of [old, new]
# values of the change.
# @return [void]
def perform(cause_type:, status_name: nil, status_id: nil, change: nil)
return if WorkPackage.use_field_for_done_ratio?

journal_cause = journal_cause_from(cause_type, status_name:, status_id:, change:)

with_temporary_progress_table do
set_p_complete_from_status
derive_remaining_work_from_work_and_p_complete
update_totals

copy_progress_values_to_work_packages_and_update_journals(journal_cause)
end
end

private

def journal_cause_from(cause_type, status_name:, status_id:, change:)
if VALID_CAUSE_TYPES.exclude?(cause_type)
raise ArgumentError, "Invalid cause type #{cause_type.inspect}. " \
"Valid values are #{VALID_CAUSE_TYPES.inspect}"
end

case cause_type
when "progress_mode_changed_to_status_based"
{ type: cause_type }
when "status_p_complete_changed"
raise ArgumentError, "status_name must be provided" if status_name.blank?
raise ArgumentError, "status_id must be provided" if status_id.nil?
raise ArgumentError, "change must be provided" if change.nil?

{ type: cause_type, status_name:, status_id:, status_p_complete_change: change }
else
raise "Unable to handle cause type #{cause_type.inspect}"
end
end
end
42 changes: 42 additions & 0 deletions app/workers/work_packages/progress/job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#-- 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.
#++

# Base class for jobs updating work packages progress values.
#
# Handles concurrency so that only one progress job is performed at a time.
class WorkPackages::Progress::Job < ApplicationJob
include GoodJob::ActiveJobExtensions::Concurrency
include WorkPackages::Progress::SqlCommands

queue_with_priority :default

good_job_control_concurrency_with(
perform_limit: 1,
key: -> { "WorkPackagesProgressJob" }
)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#-- 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.
#++

class WorkPackages::Progress::MigrateRemoveTotalsFromChildlessWorkPackagesJob < WorkPackages::Progress::Job
def perform
updated_work_package_ids = remove_totals_from_childless_work_packages
create_journals_for_updated_work_packages(updated_work_package_ids, cause: journal_cause)
end

private

def journal_cause
{ type: "system_update", feature: "totals_removed_from_childless_work_packages" }
end

def remove_totals_from_childless_work_packages
results = execute(<<~SQL.squish)
UPDATE work_packages
SET derived_estimated_hours = NULL,
derived_remaining_hours = NULL,
derived_done_ratio = NULL
WHERE work_packages.id IN (
SELECT ancestor_id AS id
FROM work_package_hierarchies
GROUP BY id
HAVING MAX(generations) = 0
)
AND (
work_packages.derived_estimated_hours IS NOT NULL
OR work_packages.derived_remaining_hours IS NOT NULL
OR work_packages.derived_done_ratio IS NOT NULL
)
RETURNING work_packages.id
SQL
results.column_values(0)
end
end

0 comments on commit 05595ff

Please sign in to comment.