-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Op#57662]: Trigger AMPF Sync Job when folder mode is switched from/t…
…o "automatic" mode (#16637) https://community.openproject.org/wp/57662
- Loading branch information
Showing
9 changed files
with
184 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
modules/storages/app/services/storages/project_storages/notifications_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#-- 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 Storages::ProjectStorages::NotificationsService | ||
module_function | ||
|
||
%i[created updated destroyed].each do |event| | ||
define_method :"broadcast_project_storage_#{event}" do |project_storage:| | ||
broadcast(event:, project_storage:) | ||
end | ||
end | ||
|
||
def broadcast(event:, project_storage:) | ||
broadcast_raw event:, project_folder_mode: project_storage.project_folder_mode.to_sym, | ||
project_folder_mode_previously_was: project_storage.project_folder_mode_previously_was&.to_sym, | ||
storage: project_storage.storage | ||
end | ||
|
||
def broadcast_raw(event:, project_folder_mode:, project_folder_mode_previously_was:, storage:) | ||
OpenProject::Notifications.send( | ||
"OpenProject::Events::PROJECT_STORAGE_#{event.to_s.upcase}".constantize, | ||
project_folder_mode:, | ||
project_folder_mode_previously_was:, | ||
storage: | ||
) | ||
end | ||
|
||
def automatic_folder_mode_broadcast?(broadcasted_payload) | ||
folder_modes = broadcasted_payload.values_at(:project_folder_mode, :project_folder_mode_previously_was).compact | ||
folder_modes.map { |mode| mode&.to_sym }.any?(:automatic) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
modules/storages/spec/services/storages/project_storages/notifications_service_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#-- 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" | ||
require_module_spec_helper | ||
|
||
RSpec.describe Storages::ProjectStorages::NotificationsService do | ||
shared_let(:project_storage) { create(:project_storage, :as_automatically_managed) } | ||
|
||
before do | ||
allow(OpenProject::Notifications).to receive(:send) | ||
end | ||
|
||
shared_examples "broadcasts the project storage event" do |event| | ||
it "broadcasts the project storage event #{event}" do | ||
expect(OpenProject::Notifications).to have_received(:send) | ||
.with(event, project_folder_mode: project_storage.project_folder_mode.to_sym, | ||
project_folder_mode_previously_was: project_storage.project_folder_mode_previously_was&.to_sym, | ||
storage: project_storage.storage) | ||
end | ||
end | ||
|
||
%i[created destroyed].each do |event| | ||
describe ".broadcast_project_storage_#{event}" do | ||
before { described_class.public_send(:"broadcast_project_storage_#{event}", project_storage:) } | ||
|
||
it_behaves_like "broadcasts the project storage event", | ||
OpenProject::Events.const_get("PROJECT_STORAGE_#{event.to_s.upcase}") | ||
end | ||
end | ||
|
||
describe ".broadcast_project_storage_updated" do | ||
before do | ||
project_storage.update(project_folder_mode: "inactive") | ||
described_class.broadcast_project_storage_updated(project_storage:) | ||
end | ||
|
||
after { project_storage.update(project_folder_mode: :automatic) } | ||
|
||
it "broadcasts the project storage event" do | ||
expect(OpenProject::Notifications).to have_received(:send) | ||
.with(OpenProject::Events::PROJECT_STORAGE_UPDATED, | ||
project_folder_mode: :inactive, | ||
project_folder_mode_previously_was: :automatic, | ||
storage: project_storage.storage) | ||
end | ||
end | ||
|
||
describe ".automatic_folder_mode_broadcast?" do | ||
subject { described_class.automatic_folder_mode_broadcast?(broadcasted_payload) } | ||
|
||
context "when project_folder_mode is automatic" do | ||
let(:broadcasted_payload) { { project_folder_mode: "automatic" } } | ||
|
||
it { is_expected.to be(true) } | ||
end | ||
|
||
context "when project_folder_mode_previously_was is automatic" do | ||
let(:broadcasted_payload) { { project_folder_mode_previously_was: "automatic" } } | ||
|
||
it { is_expected.to be(true) } | ||
end | ||
|
||
context "when only one of project_folder_mode and project_folder_mode_previously_was is automatic" do | ||
let(:broadcasted_payload) { { project_folder_mode: "inactive", project_folder_mode_previously_was: "automatic" } } | ||
|
||
it { is_expected.to be(true) } | ||
end | ||
|
||
context "when both project_folder_mode and project_folder_mode_previously_was are not automatic" do | ||
let(:broadcasted_payload) { { project_folder_mode: "inactive", project_folder_mode_previously_was: "inactive" } } | ||
|
||
it { is_expected.to be(false) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters