Skip to content

Commit

Permalink
Merge branch 'release/14.5' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Sep 6, 2024
2 parents 1d37cad + 7ea5acd commit 141b3b4
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 26 deletions.
5 changes: 4 additions & 1 deletion app/views/layouts/only_logo.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ See COPYRIGHT and LICENSE files for more details.
<head>
<%= render partial: 'layouts/common_head' %>
</head>
<body>
<body
class="<%= body_css_classes %>"
<%= user_theme_data_attributes %>
>
<div id="wrapper">
<header class="op-app-header<%= ' op-app-header_development' if OpenProject::Configuration.development_highlight_enabled? %>">
<div class="op-app-header--center op-logo">
Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class Application < Rails::Application
# http://stackoverflow.com/questions/4590229
config.middleware.use Rack::TempfileReaper

# Move secure_headers middleware to after the ShowExceptions
config.middleware.move_after ActionDispatch::ShowExceptions, SecureHeaders::Middleware

# Add lookbook preview paths when enabled
if OpenProject::Configuration.lookbook_enabled?
config.paths.add Primer::ViewComponents::Engine.root.join("app/components").to_s, eager_load: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ def create_last_project_folders(service_call, params)
end

def broadcast_project_storages_created(params)
OpenProject::Notifications.send(
OpenProject::Events::PROJECT_STORAGE_CREATED,
::Storages::ProjectStorages::NotificationsService.broadcast_raw(
event: :created,
project_folder_mode: params[:project_folder_mode],
project_folder_mode_previously_was: nil,
storage: @storage
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ def after_perform(service_call)
project_storage = service_call.result
project_folder_mode = project_storage.project_folder_mode.to_sym
add_historical_data(service_call) if project_folder_mode != :inactive
OpenProject::Notifications.send(
OpenProject::Events::PROJECT_STORAGE_CREATED,
project_folder_mode:,
storage: project_storage.storage
)
::Storages::ProjectStorages::NotificationsService.broadcast_project_storage_created(project_storage:)

service_call
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ def persist(service_result)
super.tap do |deletion_result|
if deletion_result.success?
delete_associated_file_links
OpenProject::Notifications.send(
OpenProject::Events::PROJECT_STORAGE_DESTROYED,
project_folder_mode: deletion_result.result.project_folder_mode.to_sym,
storage: deletion_result.result.storage
::Storages::ProjectStorages::NotificationsService.broadcast_project_storage_destroyed(
project_storage: deletion_result.result
)
end
end
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ def after_perform(service_call)
project_storage = service_call.result
project_folder_mode = project_storage.project_folder_mode.to_sym
add_historical_data(service_call) if project_folder_mode != :inactive
OpenProject::Notifications.send(
OpenProject::Events::PROJECT_STORAGE_UPDATED,
project_folder_mode:,
storage: project_storage.storage
)
::Storages::ProjectStorages::NotificationsService.broadcast_project_storage_updated(project_storage:)

service_call
end
Expand Down
2 changes: 1 addition & 1 deletion modules/storages/lib/open_project/storages/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def self.external_file_permissions
OpenProject::Events::PROJECT_STORAGE_DESTROYED
].each do |event|
OpenProject::Notifications.subscribe(event) do |payload|
if payload[:project_folder_mode]&.to_sym == :automatic
if ::Storages::ProjectStorages::NotificationsService.automatic_folder_mode_broadcast?(payload)
::Storages::AutomaticallyManagedStorageSyncJob.debounce(payload[:storage])
::Storages::ManageStorageIntegrationsJob.disable_cron_job_if_needed
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@

aggregate_failures "broadcasts projects storages created event" do
expect(OpenProject::Notifications).to have_received(:send)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:, storage:)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:,
project_folder_mode_previously_was: nil, storage:)
end
end
end
Expand All @@ -79,7 +80,8 @@

aggregate_failures "broadcasts projects storages created event" do
expect(OpenProject::Notifications).to have_received(:send)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:, storage:)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:,
project_folder_mode_previously_was: nil, storage:)
end
end
end
Expand All @@ -101,7 +103,8 @@

aggregate_failures "broadcasts projects storages created event" do
expect(OpenProject::Notifications).to have_received(:send)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:, storage:)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:,
project_folder_mode_previously_was: nil, storage:)
end
end
end
Expand All @@ -122,7 +125,8 @@

aggregate_failures "broadcasts projects storages created event" do
expect(OpenProject::Notifications).to have_received(:send)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:, storage:)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:,
project_folder_mode_previously_was: nil, storage:)
end
end
end
Expand Down Expand Up @@ -153,7 +157,8 @@

aggregate_failures "broadcasts projects storages created event" do
expect(OpenProject::Notifications).to have_received(:send)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:, storage:)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:,
project_folder_mode_previously_was: nil, storage:)
end
end
end
Expand All @@ -174,7 +179,8 @@
expect { instance.call(project_folder_mode:) }.not_to change(Storages::ProjectStorage, :count)
expect(instance.call).to be_failure
expect(OpenProject::Notifications).not_to have_received(:send)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:, storage:)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:,
project_folder_mode_previously_was: nil, storage:)
end
end

Expand Down Expand Up @@ -205,7 +211,8 @@

aggregate_failures "broadcasts projects storages created event" do
expect(OpenProject::Notifications).to have_received(:send)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:, storage:)
.with(OpenProject::Events::PROJECT_STORAGE_CREATED, project_folder_mode:,
project_folder_mode_previously_was: nil, storage:)
end
end
end
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
subject

expect(OpenProject::Notifications).to(
have_received(:send).with(event, project_folder_mode: mode, storage: model_instance.storage)
have_received(:send)
.with(event, project_folder_mode: mode,
project_folder_mode_previously_was: model_instance.project_folder_mode_previously_was,
storage: model_instance.storage)
)
end
end
Expand Down

0 comments on commit 141b3b4

Please sign in to comment.