Skip to content

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

add share deletion

ulfertsc912940edd6b
diff --git a/app/components/work_packages/share/modal_component.html.erb b/app/components/work_packages/share/modal_component.html.erb
index 5e71bed6d9f..ade00370916 100644
--- a/app/components/work_packages/share/modal_component.html.erb
+++ b/app/components/work_packages/share/modal_component.html.erb
@@ -15,12 +15,12 @@
else
modal_content.with_row(mt: 3, data: { 'test-selector': 'op-share-wp-active-list'}) do
render(Primer::Beta::BorderBox.new) do |invited_user_list|
- invited_user_list.with_header(color: :subtle, data: { 'test-selector': 'op-share-wp-active-count'}) do
+ invited_user_list.with_header(color: :subtle, data: { 'test-selector': 'op-share-wp-active-count' }) do
I18n.t('work_package.sharing.count', count: shared_users.count)
end
shared_users.each do |user|
- invited_user_list.with_row do
+ invited_user_list.with_row(data: { 'test-selector': "op-share-wp-active-user-#{user.id}" }) do
flex_layout(align_items: :center) do |user_row_container|
user_row_container.with_column(flex: :auto) do
render(Users::AvatarComponent.new(user: user, size: :medium))
@@ -32,7 +32,9 @@
end
user_row_container.with_column(text_align: :right, style: "width: 100px;") do
- render(Primer::Beta::Button.new(scheme: :invisible)) { I18n.t('work_package.sharing.remove') }
+ form_with url: work_packages_share_path(user.memberships.first), method: :delete do
+ render(Primer::Beta::Button.new(type: :submit, scheme: :invisible)) { I18n.t('work_package.sharing.remove') }
+ end
end
end
end
diff --git a/app/contracts/work_package_members/delete_contract.rb b/app/contracts/work_package_members/delete_contract.rb
new file mode 100644
index 00000000000..f1d7ccfb069
--- /dev/null
+++ b/app/contracts/work_package_members/delete_contract.rb
@@ -0,0 +1,33 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-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 WorkPackageMembers
+ class DeleteContract < ::DeleteContract
+ delete_permission -> { user.allowed_to?(:share_work_packages, model.entity.project) }
+ end
+end
diff --git a/app/controllers/work_packages/shares_controller.rb b/app/controllers/work_packages/shares_controller.rb
index a3c2c930c61..15a9c538d98 100644
--- a/app/controllers/work_packages/shares_controller.rb
+++ b/app/controllers/work_packages/shares_controller.rb
@@ -29,7 +29,8 @@
class WorkPackages::SharesController < ApplicationController
include OpTurbo::ComponentStream
- before_action :find_work_package
+ before_action :find_work_package, only: %i[index create]
+ before_action :find_share, only: %i[destroy]
# Todo: access control
@@ -45,6 +46,24 @@ class WorkPackages::SharesController < ApplicationController
user_id: params[:member][:user_id],
roles: Role.where(builtin: Role::BUILTIN_WORK_PACKAGE_VIEWER))
+ respond_with_update_modal
+ end
+
+ def destroy
+ # TODO: handle having an non existing id
+ # error handling
+ WorkPackageMembers::DeleteService
+ .new(user: current_user, model: @share)
+ .call
+
+ respond_with_update_modal
+ end
+
+ # Todo: Update
+
+ private
+
+ def respond_with_update_modal
replace_via_turbo_stream(
component: WorkPackages::Share::ModalComponent.new(work_package: @work_package)
)
@@ -52,11 +71,13 @@ class WorkPackages::SharesController < ApplicationController
respond_with_turbo_streams
end
- # Todo: Delete
-
- private
-
def find_work_package
@work_package = WorkPackage.find(params[:work_package_id])
end
+
+ def find_share
+ # TODO: move into scope
+ @share = Member.where(entity_type: WorkPackage.name).find(params[:id])
+ @work_package = @share.entity
+ end
end
diff --git a/app/services/work_package_members/delete_service.rb b/app/services/work_package_members/delete_service.rb
new file mode 100644
index 00000000000..0f52468c696
--- /dev/null
+++ b/app/services/work_package_members/delete_service.rb
@@ -0,0 +1,30 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-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.
+# ++
+
+class WorkPackageMembers::DeleteService < BaseServices::Delete
+end
diff --git a/config/routes.rb b/config/routes.rb
index d5ec96c4d69..11f5a692236 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -445,6 +445,8 @@ OpenProject::Application.routes.draw do
# FIXME: this is kind of evil!! We need to remove this soonest and
# cover the functionality. Route is being used in work-package-service.js:331
get '/bulk' => 'bulk#destroy'
+
+ resources :shares, only: %i[destroy]
end
resources :work_packages, only: [:index] do
diff --git a/spec/features/work_packages/share_spec.rb b/spec/features/work_packages/share_spec.rb
index 848e0890a73..012503810e2 100644
--- a/spec/features/work_packages/share_spec.rb
+++ b/spec/features/work_packages/share_spec.rb
@@ -73,7 +73,6 @@ RSpec.describe 'Work package sharing', :js do
# TODO:
# - Check title
# - Check roles
- # - Delete case
it 'allows seeing and administrating sharing' do
work_package_page.visit!
@@ -99,5 +98,12 @@ RSpec.describe 'Work package sharing', :js do
share_modal.expect_shared_with(not_shared_yet_with_user)
share_modal.expect_shared_count_of(5)
+
+ # Removing a share will lead to that user being removed from the list of shared with users.
+ share_modal.remove_user(edit_user)
+
+ share_modal.expect_not_shared_with(edit_user)
+
+ share_modal.expect_shared_count_of(4)
end
end
diff --git a/spec/routing/work_package/shares_spec.rb b/spec/routing/work_package/shares_spec.rb
new file mode 100644
index 00000000000..2a3ab1e6f18
--- /dev/null
+++ b/spec/routing/work_package/shares_spec.rb
@@ -0,0 +1,37 @@
+#-- 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.
+#++
+
+require 'spec_helper'
+
+RSpec.describe 'work package share routes' do
+ it 'connects DELETE /work_packages/shares/:id to work_packages/shares#delete' do
+ expect(delete('/work_packages/shares/5')).to route_to(controller: 'work_packages/shares',
+ action: 'destroy',
+ id: '5')
+ end
+end
diff --git a/spec/support/components/work_packages/share_modal.rb b/spec/support/components/work_packages/share_modal.rb
index 9b4a00cf7a6..bf98cd8929b 100644
--- a/spec/support/components/work_packages/share_modal.rb
+++ b/spec/support/components/work_packages/share_modal.rb
@@ -58,6 +58,12 @@ module Components
end
end
+ def remove_user(user)
+ within user_row(user) do
+ click_button 'Remove'
+ end
+ end
+
def expect_shared_with(user)
within active_list do
expect(page)
@@ -77,6 +83,11 @@ module Components
.to have_selector('[data-test-selector="op-share-wp-active-count"]', text: "#{count} members")
end
+ def user_row(user)
+ modal_element
+ .find("[data-test-selector=\"op-share-wp-active-user-#{user.id}\"]")
+ end
+
def active_list
modal_element
.find('[data-test-selector="op-share-wp-active-list"]')