Skip to content

Commit

Permalink
Merge pull request #14721 from opf/feature/50266-conditionally-remove…
Browse files Browse the repository at this point in the history
…-shares-of-removed-project-members

Feature/50266 conditionally remove shares of removed project members
  • Loading branch information
ulferts committed Apr 8, 2024
2 parents 2ee809f + a365936 commit 2b6ac8d
Show file tree
Hide file tree
Showing 36 changed files with 2,368 additions and 605 deletions.
97 changes: 97 additions & 0 deletions app/components/members/delete_member_dialog_component.html.erb
@@ -0,0 +1,97 @@
<%#-- 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.
++#%>
<%= render(Primer::Alpha::Dialog.new(id:, title: scoped_t(:title), size: :large)) do |dialog| %>
<% dialog.with_header(variant: :large) %>
<% case %>
<% when can_delete_roles? && may_delete_shares? && shared_work_packages? %>
<% dialog.with_body do %>
<% if !can_delete? %>
<%= paragraph { scoped_t(:can_remove_direct_but_not_shared_roles) } %>
<%= paragraph { scoped_t(:also_work_packages_shared_with_user_html, shared_work_packages_link:, count: shared_work_packages_count) } %>
<%= paragraph do %>
<%= scoped_t(:remove_project_membership_or_work_package_shares_too) %>
<%= scoped_t(:will_not_affect_inherited_shares) if inherited_shared_work_packages_count? %>
<% end %>
<% elsif principal.is_a?(Group) %>
<%= paragraph do %>
<%= scoped_t(:will_remove_the_groups_role) %>
<%= scoped_t(:however_work_packages_shared_with_group_html, shared_work_packages_link:, count: shared_work_packages_count) %>
<% end %>
<%= paragraph do %>
<%= scoped_t(:remove_work_packages_shared_with_group_too) %>
<% end %>
<% else %>
<%= paragraph do %>
<%= scoped_t(:will_remove_the_users_role) %>
<%= scoped_t(:however_work_packages_shared_with_user_html, shared_work_packages_link:, count: shared_work_packages_count) %>
<% end %>
<%= paragraph do %>
<%= scoped_t(:remove_work_packages_shared_with_user_too) %>
<%= scoped_t(:will_not_affect_inherited_shares) if inherited_shared_work_packages_count? %>
<% end %>
<% end %>
<% end %>
<% dialog.with_footer do %>
<%= cancel_button %>
<%= button(scheme: :danger, tag: :a, href: delete_url(project: true), data: { method: :delete }) { t(:button_remove_member) } %>
<%= button(scheme: :danger, tag: :a, href: delete_url(project: true, work_package_shares_role_id: "all"), data: { method: :delete }) { t(:button_remove_member_and_shares) } %>
<% end %>
<% when can_delete_roles? %>
<% dialog.with_body do %>
<% if !can_delete? %>
<%= paragraph { scoped_t(:can_remove_direct_but_not_shared_roles) } %>
<% elsif principal.is_a?(Group) %>
<%= paragraph { scoped_t(:will_remove_all_group_access_priveleges) } %>
<% else %>
<%= paragraph { scoped_t(:will_remove_all_user_access_priveleges) } %>
<% end %>
<% end %>
<% dialog.with_footer do %>
<%= cancel_button %>
<%= button(scheme: :danger, tag: :a, href: delete_url(project: true), data: { method: :delete }) { t(:button_remove) } %>
<% end %>
<% else %>
<% dialog.with_body do %>
<%= paragraph { scoped_t(:cannot_delete_inherited_membership) } %>
<% if may_manage_user? %>
<%= paragraph { scoped_t(:cannot_delete_inherited_membership_note_admin_html, administration_settings_link:) } %>
<% else %>
<%= paragraph { scoped_t(:cannot_delete_inherited_membership_note_non_admin) } %>
<% end %>
<% end %>
<% dialog.with_footer do %>
<%= cancel_button %>
<% end %>
<% end %>
<% end %>
73 changes: 73 additions & 0 deletions app/components/members/delete_member_dialog_component.rb
@@ -0,0 +1,73 @@
# 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.
#++

module Members
class DeleteMemberDialogComponent < ::ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
options :row

delegate :shared_work_packages_count,
:shared_work_packages_link,
:administration_settings_link,
:can_delete?,
:can_delete_roles?,
:may_delete_shares?,
:shared_work_packages?,
:may_manage_user?,
to: :row

delegate :principal,
:inherited_shared_work_packages_count?,
to: :model

def paragraph(&) = render(Primer::Beta::Text.new(tag: "p"), &)
def button(**, &) = render(Primer::Beta::Button.new(**), &)

def cancel_button = button(data: { close_dialog_id: id }) { t(:button_cancel) }

def scoped_t(key, **)
t(key, scope: "members.delete_member_dialog", **)
end

def id
"principal-#{principal.id}-delete-member-dialog"
end

def delete_url(project: nil, work_package_shares_role_id: nil)
url_for(
controller: "/members",
action: "destroy_by_principal",
project_id: row.project,
principal_id: row.principal,
project:,
work_package_shares_role_id:
)
end
end
end
@@ -0,0 +1,107 @@
<%#-- 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.
++#%>
<%= render(Primer::Alpha::Dialog.new(id:, title: scoped_t(:title), size: :large)) do |dialog| %>
<% dialog.with_header(variant: :large) %>
<% case %>
<% when direct_shared_work_packages_count? && other_shared_work_packages_count? %>
<% dialog.with_body do %>
<% if inherited_shared_work_packages_count? %>
<%= paragraph do %>
<%= scoped_t(:shared_with_this_user_html, all_shared_work_packages_link:, count: all_shared_work_packages_count) %>
<%= scoped_t(:shared_with_permission_html, shared_work_packages_link:, count: shared_work_packages_count, shared_role_name:) %>
<% end %>
<%= paragraph do %>
<%= scoped_t(:revoke_all_or_with_role, shared_role_name:) %>
<%= scoped_t(:will_not_affect_inherited_shares) %>
<% end %>
<% elsif principal.is_a?(Group) %>
<%= paragraph do %>
<%= scoped_t(:shared_with_this_group_html, all_shared_work_packages_link:, count: all_shared_work_packages_count) %>
<%= scoped_t(:shared_with_permission_html, shared_work_packages_link:, count: shared_work_packages_count, shared_role_name:) %>
<% end %>
<%= paragraph { scoped_t(:revoke_all_or_with_role, shared_role_name:) } %>
<% else %>
<%= paragraph do %>
<%= scoped_t(:shared_with_this_user_html, all_shared_work_packages_link:, count: all_shared_work_packages_count) %>
<%= scoped_t(:shared_with_permission_html, shared_work_packages_link:, count: shared_work_packages_count, shared_role_name:) %>
<% end %>
<%= paragraph { scoped_t(:revoke_all_or_with_role, shared_role_name:) } %>
<% end %>
<% end %>
<% dialog.with_footer do %>
<%= cancel_button %>
<%= button(scheme: :danger, tag: :a, href: delete_url(work_package_shares_role_id: "all"), data: { method: :delete }) { t(:button_revoke_all) } %>
<%= button(scheme: :danger, tag: :a, href: delete_url(work_package_shares_role_id: shared_role_id), data: { method: :delete }) { t(:button_revoke_only, shared_role_name:) } %>
<% end %>
<% when direct_shared_work_packages_count? %>
<% dialog.with_body do %>
<% if inherited_shared_work_packages_count? %>
<%= paragraph do %>
<%= scoped_t(:shared_with_this_user_html, all_shared_work_packages_link:, count: all_shared_work_packages_count) %>
<%= scoped_t(:will_revoke_directly_granted_access) %>
<% end %>
<% elsif principal.is_a?(Group) %>
<%= paragraph do %>
<%= scoped_t(:shared_with_this_group_html, all_shared_work_packages_link:, count: all_shared_work_packages_count) %>
<%= scoped_t(:will_revoke_access_to_all) %>
<% end %>
<% else %>
<%= paragraph do %>
<%= scoped_t(:shared_with_this_user_html, all_shared_work_packages_link:, count: all_shared_work_packages_count) %>
<%= scoped_t(:will_revoke_access_to_all) %>
<% end %>
<% end %>
<% end %>
<% dialog.with_footer do %>
<%= cancel_button %>
<%= button(scheme: :danger, tag: :a, href: delete_url(work_package_shares_role_id: "all"), data: { method: :delete }) { t(:button_revoke_access) } %>
<% end %>
<% else %>
<% dialog.with_body do %>
<% if other_shared_work_packages_count? %>
<%= paragraph { scoped_t(:cannot_remove_inherited_with_role, shared_role_name:) } %>
<% else %>
<%= paragraph { scoped_t(:cannot_remove_inherited, shared_role_name:) } %>
<% end %>
<% if may_manage_user? %>
<%= paragraph { scoped_t(:cannot_remove_inherited_note_admin_html, administration_settings_link:) } %>
<% else %>
<%= paragraph { scoped_t(:cannot_remove_inherited_note_non_admin) } %>
<% end %>
<% end %>
<% dialog.with_footer do %>
<%= cancel_button %>
<% end %>
<% end %>
<% end %>
@@ -0,0 +1,77 @@
# 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.
#++

module Members
class DeleteWorkPackageSharesDialogComponent < ::ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
options :row

delegate :table,
:shared_work_packages_count,
:all_shared_work_packages_count,
:shared_work_packages_link,
:all_shared_work_packages_link,
:administration_settings_link,
:may_manage_user?,
to: :row

delegate :shared_role_id,
:shared_role_name,
to: :table

delegate :principal,
:other_shared_work_packages_count?,
:direct_shared_work_packages_count?,
:inherited_shared_work_packages_count?,
to: :model

def paragraph(&) = render(Primer::Beta::Text.new(tag: "p"), &)
def button(**, &) = render(Primer::Beta::Button.new(**), &)

def cancel_button = button(data: { close_dialog_id: id }) { t(:button_cancel) }

def scoped_t(key, **)
t(key, scope: "members.delete_work_package_shares_dialog", **)
end

def id
"principal-#{principal.id}-delete-work-package-shares-dialog"
end

def delete_url(work_package_shares_role_id: nil)
url_for(
controller: "/members",
action: "destroy_by_principal",
project_id: row.project,
principal_id: row.principal,
work_package_shares_role_id:
)
end
end
end

0 comments on commit 2b6ac8d

Please sign in to comment.