Skip to content

Commit

Permalink
Render sharing modal for project lists
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-contreras committed Jun 27, 2024
1 parent 6dafc14 commit 5fb4649
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 34 deletions.
16 changes: 10 additions & 6 deletions app/components/projects/index_page_header_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
)
end

header.with_action_icon_button(
icon: "share-android",
mobile_icon: "share-android",
label: t(:label_share),
data: { show_dialog_id: Projects::ExportListModalComponent::MODAL_ID }
)
if query.persisted?
header.with_action_icon_button(
tag: :a,
href: dialog_project_query_members_path(query),
icon: "share-android",
mobile_icon: "share-android",
label: t(:label_share),
data: { controller: "async-dialog" }
)
end

header.with_action_menu(menu_arguments: {
anchor_align: :end
Expand Down
26 changes: 19 additions & 7 deletions app/controllers/shares_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def create_or_update_share(user_id, role_ids)
create_contract_class: sharing_contract_scope::CreateContract,
update_contract_class: sharing_contract_scope::UpdateContract
)
.call(entity: @entity, user_id:, role_ids:)
.call(entity: @entity, user_id:, role_ids:)
end

def respond_with_replace_modal
Expand Down Expand Up @@ -306,9 +306,8 @@ def respond_with_bulk_removed_shares
def load_entity
@entity = if params["work_package_id"]
WorkPackage.visible.find(params["work_package_id"])
# TODO: Add support for other entities
elsif params["query_id"] && request.path.starts_with?("/projects/queries")
Queries::Projects::ProjectQuery.visible.find(params["query_id"])
elsif params["project_query_id"]
ProjectQuery.visible.find(params["project_query_id"])
else
raise ArgumentError, <<~ERROR
Nested the SharesController under an entity controller that is not yet configured to support sharing.
Expand Down Expand Up @@ -336,8 +335,8 @@ def load_query
return @query if defined?(@query)

@query = ParamsToQueryService
.new(Member, current_user, query_class: Queries::Members::EntityMemberQuery)
.call(params)
.new(Member, current_user, query_class: Queries::Members::EntityMemberQuery)
.call(params)

# Set default filter on the entity
@query.where("entity_id", "=", @entity.id)
Expand Down Expand Up @@ -377,7 +376,20 @@ def available_roles
description: I18n.t("work_package.permissions.view_description"),
default: true }
]
elsif @entity.is_a?(ProjectQuery)
role_mapping = ProjectQueryRole.unscoped.pluck(:builtin, :id).to_h

[
{ label: I18n.t("work_package.permissions.edit"),
value: role_mapping[Role::BUILTIN_PROJECT_QUERY_EDIT],
description: I18n.t("work_package.permissions.edit_description") },
{ label: I18n.t("work_package.permissions.view"),
value: role_mapping[Role::BUILTIN_PROJECT_QUERY_VIEW],
description: I18n.t("work_package.permissions.view_description"),
default: true }
]
else

[]
end
end

Check notice on line 395 in app/controllers/shares_controller.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/controllers/shares_controller.rb#L363-L395 <Metrics/AbcSize>

Assignment Branch Condition size for available_roles is too high. [<3, 23, 4> 23.54/17]
Raw output
app/controllers/shares_controller.rb:363:3: C: Metrics/AbcSize: Assignment Branch Condition size for available_roles is too high. [<3, 23, 4> 23.54/17]
Expand All @@ -393,7 +405,7 @@ def sharing_manageable?
case @entity
when WorkPackage
User.current.allowed_in_project?(:share_work_packages, @entity.project)
when Queries::Projects::ProjectQuery
when ProjectQuery
@entity.editable?
else
raise ArgumentError, <<~ERROR
Expand Down
11 changes: 0 additions & 11 deletions app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ See COPYRIGHT and LICENSE files for more details.
)
%>
<%= render(Projects::IndexSubHeaderComponent.new(query:, current_user:, disable_buttons: state === :rename)) %>
<%# TODO: Temporary %>
<%- if @query.persisted? %>
<%= render(Primer::Beta::Button.new(
tag: :a,
href: dialog_projects_query_members_path(@query),
data: { controller: "async-dialog" }
)) do |button|
"TEMP: SHARE"
end
%>
<%- end%>
<%= render Projects::TableComponent.new(
query:,
current_user: current_user,
Expand Down
15 changes: 15 additions & 0 deletions app/views/shares/dialog.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= turbo_stream.dialog do
render(Primer::Alpha::Dialog.new(title: t(:label_sharing),
id: 'share_list',
size: :xlarge)) do |d|
d.with_header(variant: :large)
d.with_body do
render(Shares::ModalBodyComponent.new(entity: @entity,
shares: @shares,
errors: @errors,
sharing_manageable: @sharing_manageable,
available_roles: @available_roles))
end
end
end
%>
10 changes: 0 additions & 10 deletions app/views/sharing/dialog.turbo_stream.erb

This file was deleted.

2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@
end

resources :project_queries, only: %i[show new create update destroy], controller: "projects/queries" do
concerns :shareable

member do
get :rename

Expand Down

0 comments on commit 5fb4649

Please sign in to comment.