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

Invite User Form uses strategy

Klaus Zanders218ee5bf82db
diff --git a/app/components/shares/invite_user_form_component.html.erb b/app/components/shares/invite_user_form_component.html.erb
index 5900c1a2ef4..6cfe10cc506 100644
--- a/app/components/shares/invite_user_form_component.html.erb
+++ b/app/components/shares/invite_user_form_component.html.erb
@@ -1,17 +1,15 @@
<%=
component_wrapper do
- if @sharing_manageable
+ if strategy.manageable?
primer_form_with(
model: new_share,
- url: url_for([@entity, Member]),
- data: { controller: 'user-limit ' \
- 'shares--user-selected',
+ url: url_for([entity, Member]),
+ data: { controller: 'user-limit shares--user-selected',
'application-target': 'dynamic',
'user-limit-open-seats-value': OpenProject::Enterprise.open_seats_count,
action: 'submit->shares--user-selected#ensureUsersSelected' }
) do |form|
- grid_layout('invite-user-form',
- tag: :div) do |invite_form|
+ grid_layout('invite-user-form', tag: :div) do |invite_form|
invite_form.with_area('invitee') do
render(Shares::Invitee.new(form))
end
@@ -19,7 +17,7 @@
invite_form.with_area('permission') do
render(Shares::PermissionButtonComponent.new(
share: new_share,
- available_roles: @available_roles,
+ available_roles: strategy.available_roles,
form_arguments: { builder: form, name: "role_id" },
data: { 'test-selector': 'op-share-dialog-invite-role' })
)
@@ -46,7 +44,7 @@
I18n.t(
"sharing.warning_user_limit_reached#{'_admin' if User.current.admin?}",
upgrade_url: OpenProject::Enterprise.upgrade_url,
- entity: @entity.model_name.human
+ entity: entity.model_name.human
).html_safe
end
end
@@ -65,7 +63,7 @@
no_selected_user_row.with_column do
render(Primer::Beta::Text.new(color: :danger)) do
- I18n.t("sharing.warning_no_selected_user", entity: @entity.model_name.human)
+ I18n.t("sharing.warning_no_selected_user", entity: entity.model_name.human)
end
end
end
@@ -96,7 +94,7 @@
end
end
else
- render(Primer::Alpha::Banner.new(icon: :info)) { I18n.t('sharing.denied', entities: @entity.model_name.human(count: 2)) }
+ render(Primer::Alpha::Banner.new(icon: :info)) { I18n.t('sharing.denied', entities: entity.model_name.human(count: 2)) }
end
end
%>
diff --git a/app/components/shares/invite_user_form_component.rb b/app/components/shares/invite_user_form_component.rb
index 48ae8e0715e..92cd7bf922b 100644
--- a/app/components/shares/invite_user_form_component.rb
+++ b/app/components/shares/invite_user_form_component.rb
@@ -32,26 +32,24 @@ module Shares
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
- def initialize(entity:,
- available_roles:,
- sharing_manageable:,
- errors: nil)
+ attr_reader :entity, :strategy, :errors
+
+ def initialize(strategy:, errors: nil)
super
- @entity = entity
- @available_roles = available_roles
- @sharing_manageable = sharing_manageable
+ @strategy = strategy
+ @entity = strategy.entity
@errors = errors
end
def new_share
- @new_share ||= Member.new(entity: @entity, roles: [Role.new(id: default_role[:value])])
+ @new_share ||= Member.new(entity:, roles: [Role.new(id: default_role[:value])])
end
private
def default_role
- @available_roles.find { |role_hash| role_hash[:default] } || @available_roles.first
+ strategy.available_roles.find { |role_hash| role_hash[:default] } || strategy.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 8f7252944dd..05cde3aef1d 100644
--- a/app/components/shares/modal_body_component.html.erb
+++ b/app/components/shares/modal_body_component.html.erb
@@ -2,10 +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(entity: @entity,
- available_roles: @available_roles,
- sharing_manageable: @sharing_manageable,
- errors: @errors))
+ render(Shares::InviteUserFormComponent.new(strategy: strategy, errors: errors))
end
modal_content.with_row(mt: 3,