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 `available_roles` and move everything to `entity`

Klaus Zanders2c64cef0308f
diff --git a/app/components/shares/bulk_permission_button_component.html.erb b/app/components/shares/bulk_permission_button_component.html.erb
index b1b0a5173f4..b0eacc5f312 100644
--- a/app/components/shares/bulk_permission_button_component.html.erb
+++ b/app/components/shares/bulk_permission_button_component.html.erb
@@ -9,20 +9,20 @@
'Placeholder'
end
- options.each do |option|
- menu.with_item(label: option[:label],
+ @available_roles.each do |role_hash|
+ menu.with_item(label: role_hash[:label],
href: update_path,
method: :patch,
active: false,
form_arguments: {
method: :patch,
name: 'role_ids[]',
- value: option[:value],
+ value: role_hash[:value],
data: { 'work-packages--share--bulk-selection-target': 'bulkForm bulkUpdateRoleForm',
- 'role-name': option[:label],
- 'test-selector': "op-share-wp-bulk-update-role-permission-#{option[:label]}" }
+ 'role-name': role_hash[:label],
+ 'test-selector': "op-share-wp-bulk-update-role-permission-#{role_hash[:label]}" }
}) do |item|
- item.with_description.with_content(option[:description])
+ item.with_description.with_content(role_hash[:description])
end
end
end
diff --git a/app/components/shares/bulk_permission_button_component.rb b/app/components/shares/bulk_permission_button_component.rb
index ce6679a72be..f9a89e18673 100644
--- a/app/components/shares/bulk_permission_button_component.rb
+++ b/app/components/shares/bulk_permission_button_component.rb
@@ -29,17 +29,16 @@
# ++
module Shares
- class BulkPermissionButtonComponent < ApplicationComponent
- include Shares::Concerns::DisplayableRoles
-
- def initialize(work_package:)
+ class BulkPermissionButtonComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ def initialize(entity:, available_roles:)
super
- @work_package = work_package
+ @entity = entity
+ @available_roles = available_roles
end
def update_path
- url_for([:bulk, @work_package, Member])
+ url_for([:bulk, @entity, Member])
end
end
end
diff --git a/app/components/shares/bulk_selection_counter_component.rb b/app/components/shares/bulk_selection_counter_component.rb
index 2196cc6dec4..fc56f453cde 100644
--- a/app/components/shares/bulk_selection_counter_component.rb
+++ b/app/components/shares/bulk_selection_counter_component.rb
@@ -29,7 +29,7 @@
# ++
module Shares
- class BulkSelectionCounterComponent < ApplicationComponent
+ class BulkSelectionCounterComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
def initialize(count:)
super
diff --git a/app/components/shares/concerns/authorization.rb b/app/components/shares/concerns/authorization.rb
index 862e07166a7..6c5041866a9 100644
--- a/app/components/shares/concerns/authorization.rb
+++ b/app/components/shares/concerns/authorization.rb
@@ -35,7 +35,8 @@ module Shares
included do
def sharing_manageable?
- User.current.allowed_in_project?(:share_work_packages, @work_package.project)
+ # TODO: Fix this to check based on the entity
+ User.current.allowed_in_project?(:share_work_packages, @entity.project)
end
end
end
diff --git a/app/components/shares/concerns/displayable_roles.rb b/app/components/shares/concerns/displayable_roles.rb
deleted file mode 100644
index 79b887a48b4..00000000000
--- a/app/components/shares/concerns/displayable_roles.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-# frozen_string_literal: true
-
-# -- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 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 Shares
- module Concerns
- module DisplayableRoles
- def options
- [
- { label: I18n.t("work_package.sharing.permissions.edit"),
- value: Role::BUILTIN_WORK_PACKAGE_EDITOR,
- description: I18n.t("work_package.sharing.permissions.edit_description") },
- { label: I18n.t("work_package.sharing.permissions.comment"),
- value: Role::BUILTIN_WORK_PACKAGE_COMMENTER,
- description: I18n.t("work_package.sharing.permissions.comment_description") },
- { label: I18n.t("work_package.sharing.permissions.view"),
- value: Role::BUILTIN_WORK_PACKAGE_VIEWER,
- description: I18n.t("work_package.sharing.permissions.view_description") }
- ]
- end
- end
- end
-end
diff --git a/app/components/shares/counter_component.rb b/app/components/shares/counter_component.rb
index 8da6c7f9cc1..5b22c7fa2b0 100644
--- a/app/components/shares/counter_component.rb
+++ b/app/components/shares/counter_component.rb
@@ -35,19 +35,19 @@ module Shares
include OpPrimer::ComponentHelpers
include Shares::Concerns::Authorization
- def initialize(work_package:, count:)
+ def initialize(entity:, count:)
super
- @work_package = work_package
+ @entity = entity
@count = count
end
private
- attr_reader :work_package, :count
+ attr_reader :entity, :count
def shared_with_anyone_else_other_than_myself?
- Member.of_work_package(@work_package)
+ Member.of_entity(@entity)
.where.not(principal: User.current)
.any?
end
diff --git a/app/components/shares/invite_user_form_component.html.erb b/app/components/shares/invite_user_form_component.html.erb
index 8a62c75fa4f..963065e9b2b 100644
--- a/app/components/shares/invite_user_form_component.html.erb
+++ b/app/components/shares/invite_user_form_component.html.erb
@@ -3,7 +3,7 @@
if sharing_manageable?
primer_form_with(
model: new_share,
- url: url_for([@work_package, Member]),
+ url: url_for([@entity, Member]),
data: { controller: 'user-limit ' \
'work-packages--share--user-selected',
'application-target': 'dynamic',
@@ -19,6 +19,7 @@
invite_form.with_area('permission') do
render(Shares::PermissionButtonComponent.new(
share: new_share,
+ available_roles: @available_roles,
form_arguments: { builder: form, name: "role_id" },
data: { 'test-selector': 'op-share-wp-invite-role' })
)
diff --git a/app/components/shares/invite_user_form_component.rb b/app/components/shares/invite_user_form_component.rb
index 1189f8b5762..abaca7db068 100644
--- a/app/components/shares/invite_user_form_component.rb
+++ b/app/components/shares/invite_user_form_component.rb
@@ -27,21 +27,28 @@
#++
module Shares
- class InviteUserFormComponent < ApplicationComponent
+ class InviteUserFormComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
include Shares::Concerns::Authorization
- def initialize(work_package:, errors: nil)
+ def initialize(entity:, available_roles:, errors: nil)
super
- @work_package = work_package
+ @entity = entity
@errors = errors
+ @available_roles = available_roles
end
def new_share
- @new_share ||= Member.new(entity: @work_package, roles: [Role.new(builtin: Role::BUILTIN_WORK_PACKAGE_VIEWER)])
+ @new_share ||= Member.new(entity: @entity, roles: [Role.new(id: default_role[:value])])
+ end
+
+ private
+
+ def default_role
+ @available_roles.find { |role_hash| role_hash[:default] } || @available_roles.first
end
end
end
diff --git a/app/components/shares/modal_body_component.html.erb b/app/components/shares/modal_body_component.html.erb
index 156ca7b249a..3e8d3ad558c 100644
--- a/app/components/shares/modal_body_component.html.erb
+++ b/app/components/shares/modal_body_component.html.erb
@@ -2,7 +2,7 @@
component_wrapper(tag: 'turbo-frame') do
flex_layout(data: { turbo: true }) do |modal_content|
modal_content.with_row do
- render(Shares::InviteUserFormComponent.new(work_package: @work_package, errors: @errors))
+ render(Shares::InviteUserFormComponent.new(entity: @entity, available_roles: @available_roles, errors: @errors))
end
modal_content.with_row(mt: 3,
@@ -13,7 +13,7 @@
border_box.with_header(color: :muted, data: { 'test-selector': 'op-share-wp-header' }) do
grid_layout('op-share-wp-modal-body--header', tag: :div, align_items: :center) do |header_grid|
header_grid.with_area(:counter, tag: :div) do
- render(Shares::CounterComponent.new(work_package: @work_package, count: @shares.size))
+ render(Shares::CounterComponent.new(entity: @entity, count: @shares.size))
end
header_grid.with_area(:actions,
@@ -53,12 +53,12 @@
button.with_trailing_action_icon(icon: "triangle-down")
I18n.t('work_package.sharing.filter.role')
end
- options.each do |option|
- menu.with_item(label: option[:label],
- href: filter_url(role_option: option),
+ @available_roles.each do |role_hash|
+ menu.with_item(label: role_hash[:label],
+ href: filter_url(role_option: role_hash),
method: :get,
tag: :a,
- active: role_filter_option_active?(option),
+ active: role_filter_option_active?(role_hash),
role: "menuitem")
end
end
@@ -72,11 +72,11 @@
data: { 'work-packages--share--bulk-selection-target': 'bulkActions' }) do
if sharing_manageable?
concat(
- render(Shares::BulkPermissionButtonComponent.new(work_package: @work_package))
+ render(Shares::BulkPermissionButtonComponent.new(entity: @entity, available_roles: @available_roles))
)
concat(
- form_with(url: url_for([:bulk, @work_package, Member]),
+ form_with(url: url_for([:bulk, @entity, Member]),
method: :delete,
data: { 'work-packages--share--bulk-selection-target': 'bulkForm' }) do
render(Primer::Beta::IconButton.new(icon: "trash",
@@ -107,7 +107,7 @@
end
else
@shares.each do |share|
- render(Shares::ShareRowComponent.new(share: share, container: border_box))
+ render(Shares::ShareRowComponent.new(share: share, available_roles: @available_roles, container: border_box))
end
end
end
diff --git a/app/components/shares/modal_body_component.rb b/app/components/shares/modal_body_component.rb
index b9b918a0a52..0df017788b0 100644
--- a/app/components/shares/modal_body_component.rb
+++ b/app/components/shares/modal_body_component.rb
@@ -27,20 +27,22 @@
#++
module Shares
- class ModalBodyComponent < ApplicationComponent
+ class ModalBodyComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include ApplicationHelper
include MemberHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
include Shares::Concerns::Authorization
- include Shares::Concerns::DisplayableRoles
- def initialize(work_package:, shares:, errors: nil)
+ attr_reader :entity, :shares, :errors, :available_roles
+
+ def initialize(entity:, shares:, available_roles:, errors: nil)
super
- @work_package = work_package
+ @entity = entity
@shares = shares
@errors = errors
+ @available_roles = available_roles
end
def self.wrapper_key
@@ -49,6 +51,10 @@ module Shares
private
+ def project_scoped_entity?
+ entity.respond_to?(:project)
+ end
+
def insert_target_modified?
true
end
@@ -72,16 +78,24 @@ module Shares
end
def type_filter_options
- [
- { label: I18n.t("work_package.sharing.filter.project_member"),
- value: { principal_type: "User", project_member: true } },
- { label: I18n.t("work_package.sharing.filter.not_project_member"),
- value: { principal_type: "User", project_member: false } },
- { label: I18n.t("work_package.sharing.filter.project_group"),
- value: { principal_type: "Group", project_member: true } },
- { label: I18n.t("work_package.sharing.filter.not_project_group"),
- value: { principal_type: "Group", project_member: false } }
- ]
+ if project_scoped_entity?
+ [
+ { label: I18n.t("work_package.sharing.filter.project_member"),
+ value: { principal_type: "User", project_member: true } },
+ { label: I18n.t("work_package.sharing.filter.not_project_member"),
+ value: { principal_type: "User", project_member: false } },
+ { label: I18n.t("work_package.sharing.filter.project_group"),
+ value: { principal_type: "Group", project_member: true } },
+ { label: I18n.t("work_package.sharing.filter.not_project_group"),
+ value: { principal_type: "Group", project_member: false } }
+ ]
+ else
+ [
+ { label: "User", value: { principal_type: "User" } },
+ { label: "Group", value: { principal_type: "Group" } }
+ ]
+
+ end
end
def type_filter_option_active?(_option)
@@ -107,7 +121,7 @@ module Shares
end
def filter_url(type_option: nil, role_option: nil)
- return url_for([@work_package, Member]) if type_option.nil? && role_option.nil?
+ return url_for([@entity, Member]) if type_option.nil? && role_option.nil?
args = {}
filter = []
@@ -117,26 +131,28 @@ module Shares
args[:filters] = filter.to_json unless filter.empty?
- url_for([@work_package, Member, **args])
+ url_for([@entity, Member, args])
end
- def apply_role_filter(_option)
+ def apply_role_filter(option)
current_role_filter_value = current_filter_value(params[:filters], "role_id")
filter = []
- if _option.nil? && current_role_filter_value.present?
+ if option.nil? && current_role_filter_value.present?
# When there is already a role filter set and no new value passed, we want to keep that filter
- filter = role_filter_for({ value: current_role_filter_value }, builtin_role: false)
- elsif _option.present? && !role_filter_option_active?(_option)
+ filter = role_filter_for({ value: current_role_filter_value })
+ elsif option.present? && !role_filter_option_active?(option)
# Only when the passed filter option is not the currently selected one, we apply the filter
- filter = role_filter_for(_option)
+ filter = role_filter_for(option)
end
filter
end
- def role_filter_for(_option, builtin_role: true)
- [{ role_id: { operator: "=", values: builtin_role ? find_role_ids(_option[:value]) : [_option[:value]] } }]
+ def role_filter_for(option)
+ [
+ { role_id: { operator: "=", values: [option[:value]] } }
+ ]
end
def apply_type_filter(_option)
diff --git a/app/components/shares/permission_button_component.html.erb b/app/components/shares/permission_button_component.html.erb
index 076976c73e1..f2610709166 100644
--- a/app/components/shares/permission_button_component.html.erb
+++ b/app/components/shares/permission_button_component.html.erb
@@ -6,21 +6,25 @@
color: :subtle }.deep_merge(@system_arguments))) do |menu|
menu.with_show_button(data: { 'work-packages--share--bulk-selection-target': 'userRowRole',
'share-id': share.id,
- 'active-role-name': permission_name(active_role.builtin)}) do |button|
+ 'active-role-name': permission_name(active_role.id)}) do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
- permission_name(active_role.builtin)
+ permission_name(active_role.id)
end
- options.each do |option|
- menu.with_item(label: option[:label],
+
+ puts "*"*100, @available_roles, "*"*100
+
+ @available_roles.each do |role_hash|
+ puts "### role_hash: #{role_hash} ###"
+ menu.with_item(label: role_hash[:label],
href: update_path,
method: :patch,
- active: option_active?(option),
- data: { value: option[:value] },
+ active: role_active?(role_hash),
+ data: { value: role_hash[:value] },
form_arguments: {
method: :patch,
- inputs: form_inputs(option[:value])
+ inputs: form_inputs(role_hash[:value])
}) do |item|
- item.with_description.with_content(option[:description])
+ item.with_description.with_content(role_hash[:description])
end
end
end
diff --git a/app/components/shares/permission_button_component.rb b/app/components/shares/permission_button_component.rb
index 6de62dfb553..2746241a157 100644
--- a/app/components/shares/permission_button_component.rb
+++ b/app/components/shares/permission_button_component.rb
@@ -27,15 +27,15 @@
#++
module Shares
- class PermissionButtonComponent < ApplicationComponent
+ class PermissionButtonComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- include Shares::Concerns::DisplayableRoles
- def initialize(share:, **system_arguments)
+ def initialize(share:, available_roles:, **system_arguments)
super
+ @available_roles = available_roles
@share = share
@system_arguments = system_arguments
end
@@ -48,8 +48,8 @@ module Shares
end
end
- def option_active?(option)
- option[:value] == active_role.builtin
+ def role_active?(role_hash)
+ role_hash[:value] == active_role.id
end
def wrapper_uniq_by
@@ -58,7 +58,7 @@ module Shares
private
- attr_reader :share
+ attr_reader :share, :available_roles
def active_role
if share.persisted?
@@ -71,7 +71,7 @@ module Shares
end
def permission_name(value)
- options.find { |option| option[:value] == value }[:label]
+ available_roles.find { |role_hash| role_hash[:value] == value }[:label]
end
def form_inputs(role_id)
diff --git a/app/components/shares/share_counter_component.rb b/app/components/shares/share_counter_component.rb
index f30bbf15bc6..094b0c74dc1 100644
--- a/app/components/shares/share_counter_component.rb
+++ b/app/components/shares/share_counter_component.rb
@@ -29,7 +29,7 @@
# ++
module Shares
- class ShareCounterComponent < ApplicationComponent
+ class ShareCounterComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
def initialize(count:)
super
diff --git a/app/components/shares/share_row_component.html.erb b/app/components/shares/share_row_component.html.erb
index 02737d53247..cb3eaba15cb 100644
--- a/app/components/shares/share_row_component.html.erb
+++ b/app/components/shares/share_row_component.html.erb
@@ -23,11 +23,12 @@
if share_editable?
user_row_grid.with_area(:button, tag: :div, color: :subtle) do
render(Shares::PermissionButtonComponent.new(share:,
- data: { 'test-selector': 'op-share-wp-update-role' }))
+ available_roles: @available_roles,
+ data: { 'test-selector': 'op-share-wp-update-role' }))
end
user_row_grid.with_area(:remove, tag: :div) do
- form_with url: url_for([work_package, share]), method: :delete do
+ form_with url: url_for([entity, share]), method: :delete do
render(Primer::Beta::IconButton.new(icon: "trash",
type: :submit,
scheme: :danger,
diff --git a/app/components/shares/share_row_component.rb b/app/components/shares/share_row_component.rb
index a5b376b8d0c..bb981e146ef 100644
--- a/app/components/shares/share_row_component.rb
+++ b/app/components/shares/share_row_component.rb
@@ -29,19 +29,21 @@
# ++
module Shares
- class ShareRowComponent < ApplicationComponent
+ class ShareRowComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
include Shares::Concerns::Authorization
def initialize(share:,
+ available_roles:,
container: nil)
super
@share = share
- @work_package = share.entity
+ @entity = share.entity
@principal = share.principal
+ @available_roles = available_roles
@container = container
end
@@ -51,7 +53,7 @@ module Shares
private
- attr_reader :share, :work_package, :principal, :container
+ attr_reader :share, :entity, :principal, :container, :available_roles
def share_editable?
@share_editable ||= User.current != share.principal && sharing_manageable?
diff --git a/app/components/shares/user_details_component.rb b/app/components/shares/user_details_component.rb
index 436d859e8c4..0003900998a 100644
--- a/app/components/shares/user_details_component.rb
+++ b/app/components/shares/user_details_component.rb
@@ -32,7 +32,6 @@ module Shares
class UserDetailsComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
- include Shares::Concerns::DisplayableRoles
def initialize(share:,
manager_mode: User.current.allowed_in_project?(:share_work_packages, share.project),
@@ -59,7 +58,7 @@ module Shares
def authoritative_work_package_role_name
@authoritative_work_package_role_name = options.find do |option|
- option[:value] == share.roles.first.builtin
+ option[:value] == share.roles.first.id
end[:label]
end
diff --git a/app/controllers/concerns/member_helper.rb b/app/controllers/concerns/member_helper.rb
index 70c7a09a556..8eb65831fd9 100644
--- a/app/controllers/concerns/member_helper.rb
+++ b/app/controllers/concerns/member_helper.rb
@@ -29,12 +29,6 @@
module MemberHelper
module_function
- def find_role_ids(builtin_value)
- # Role has a left join on permissions included leading to multiple ids being returned which
- # is why we unscope.
- WorkPackageRole.unscoped.where(builtin: builtin_value).pluck(:id)
- end
-
def find_or_create_users(send_notification: true)
@send_notification = send_notification
diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb
index 5459d374bdd..6464a16798f 100644
--- a/app/controllers/shares_controller.rb
+++ b/app/controllers/shares_controller.rb
@@ -41,7 +41,7 @@ class SharesController < ApplicationController
flash.now[:error] = query.errors.full_messages
end
- render Shares::ModalBodyComponent.new(work_package: @entity, shares: @shares, errors: @errors), layout: nil
+ render Shares::ModalBodyComponent.new(entity: @entity, shares: @shares, errors: @errors, available_roles:), layout: nil
end
def create
@@ -57,7 +57,7 @@ class SharesController < ApplicationController
.new(user: current_user)
.call(entity: @entity,
user_id: member_params[:user_id],
- role_ids: find_role_ids(params[:member][:role_id]))
+ role_ids: [params[:member][:role_id]])
overall_result.push(service_call)
end
@@ -81,7 +81,7 @@ class SharesController < ApplicationController
def update
WorkPackageMembers::UpdateService
.new(user: current_user, model: @share)
- .call(role_ids: find_role_ids(params[:role_ids]))
+ .call(role_ids: params[:role_ids])
load_shares
@@ -124,7 +124,8 @@ class SharesController < ApplicationController
def respond_with_replace_modal
replace_via_turbo_stream(
- component: Shares::ModalBodyComponent.new(work_package: @entity,
+ component: Shares::ModalBodyComponent.new(entity: @entity,
+ available_roles:,
shares: @new_shares || load_shares,
errors: @errors)
)
@@ -134,17 +135,18 @@ class SharesController < ApplicationController
def respond_with_prepend_shares
replace_via_turbo_stream(
- component: Shares::InviteUserFormComponent.new(work_package: @entity, errors: @errors)
+ component: Shares::InviteUserFormComponent.new(entity: @entity, available_roles:, errors: @errors)
)
update_via_turbo_stream(
- component: Shares::CounterComponent.new(work_package: @entity, count: current_visible_member_count)
+ component: Shares::CounterComponent.new(entity: @entity, count: current_visible_member_count)
)
@new_shares.each do |share|
prepend_via_turbo_stream(
- component: Shares::ShareRowComponent.new(share:),
- target_component: Shares::ModalBodyComponent.new(work_package: @entity,
+ component: Shares::ShareRowComponent.new(share:, available_roles:),
+ target_component: Shares::ModalBodyComponent.new(entity: @entity,
+ available_roles:,
shares: load_shares,
errors: @errors)
)
@@ -154,21 +156,24 @@ class SharesController < ApplicationController
end
def respond_with_new_invite_form
- replace_via_turbo_stream(component: Shares::InviteUserFormComponent.new(work_package: @entity, errors: @errors))
+ replace_via_turbo_stream(component: Shares::InviteUserFormComponent.new(entity: @entity,
+ available_roles:,
+ errors: @errors))
respond_with_turbo_streams
end
def respond_with_update_permission_button
replace_via_turbo_stream(component: Shares::PermissionButtonComponent.new(share: @share,
+ available_roles:,
data: { "test-selector": "op-share-wp-update-role" }))
respond_with_turbo_streams
end
def respond_with_remove_share
- remove_via_turbo_stream(component: Shares::ShareRowComponent.new(share: @share))
- update_via_turbo_stream(component: Shares::CounterComponent.new(work_package: @entity, count: current_visible_member_count))
+ remove_via_turbo_stream(component: Shares::ShareRowComponent.new(share: @share, available_roles:))
+ update_via_turbo_stream(component: Shares::CounterComponent.new(entity: @entity, count: current_visible_member_count))
respond_with_turbo_streams
end
@@ -228,4 +233,30 @@ class SharesController < ApplicationController
def load_shares
@shares = load_query.results
end
+
+ def load_selected_shares
+ @selected_shares = Member.includes(:principal)
+ .of_entity(@entity)
+ .where(id: params[:share_ids])
+ end
+
+ def available_roles
+ # TODO: Optimize loading of roles
+ if @entity.is_a?(WorkPackage)
+ [
+ { label: I18n.t("work_package.sharing.permissions.edit"),
+ value: WorkPackageRole.find_by(builtin: Role::BUILTIN_WORK_PACKAGE_EDITOR).id,
+ description: I18n.t("work_package.sharing.permissions.edit_description") },
+ { label: I18n.t("work_package.sharing.permissions.comment"),
+ value: WorkPackageRole.find_by(builtin: Role::BUILTIN_WORK_PACKAGE_COMMENTER).id,
+ description: I18n.t("work_package.sharing.permissions.comment_description") },
+ { label: I18n.t("work_package.sharing.permissions.view"),
+ value: WorkPackageRole.find_by(builtin: Role::BUILTIN_WORK_PACKAGE_VIEWER).id,
+ description: I18n.t("work_package.sharing.permissions.view_description"),
+ default: true }
+ ]
+ else
+ []
+ end
+ end
end