Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tests for sharing project queries #16032

Merged
merged 41 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
079ec2d
Start SharesController specs
klaustopher Jul 3, 2024
58492a7
Fix rubocop complaints
aaron-contreras Jul 3, 2024
1bd18ad
Add project query tests for entity specific behavior
aaron-contreras Jul 3, 2024
7fc207f
Add tests for shares_controller#dialog
aaron-contreras Jul 3, 2024
26176bd
Merge branch 'implementation/55163-build-sharing-modal' into sharing-…
aaron-contreras Jul 3, 2024
e485994
Merge branch 'release/14.3' into sharing-tests
klaustopher Jul 4, 2024
8e2f323
Add specs for checking a permission on a standalone (non project scop…
klaustopher Jul 4, 2024
429f881
More tests
klaustopher Jul 4, 2024
a8204fe
Test access granted by sharing in feature spec
aaron-contreras Jul 4, 2024
1513a10
Merge branch 'release/14.3' into sharing-tests
aaron-contreras Jul 5, 2024
e33e7b8
Add tests for sharing with a user with edit permissions
aaron-contreras Jul 5, 2024
c8c361b
Allow users to edit project queries who have the edit permissions
aaron-contreras Jul 5, 2024
8c0113a
Remove pending example now that it's fixed
aaron-contreras Jul 5, 2024
2017065
Merge branch 'release/14.3' into sharing-tests
aaron-contreras Jul 5, 2024
a6d38f1
Remove feature decision from system spec
aaron-contreras Jul 5, 2024
24ddf90
Merge branch 'release/14.3' into sharing-tests
klaustopher Jul 8, 2024
c67542e
Add a hint
klaustopher Jul 8, 2024
c6373cf
Fix duplicated let
klaustopher Jul 8, 2024
d7c133f
Test ability to make a query public
aaron-contreras Jul 8, 2024
6396682
Test public project list owner can't edit without global permission
aaron-contreras Jul 8, 2024
b843c8f
Test managing a public project query when shared with me with an edit…
aaron-contreras Jul 8, 2024
b98e0f1
Merge branch 'release/14.3' into sharing-tests
aaron-contreras Jul 8, 2024
31d2e8c
Write tests for index action
aaron-contreras Jul 9, 2024
8d04a83
Merge branch 'release/14.3' into sharing-tests
aaron-contreras Jul 9, 2024
5c4ca10
Write tests for create action
aaron-contreras Jul 9, 2024
70652ed
Add specs for update action
aaron-contreras Jul 9, 2024
d496638
Merge branch 'release/14.3' into sharing-tests
aaron-contreras Jul 10, 2024
edd42a9
Adjust specs after refactor
aaron-contreras Jul 10, 2024
ce5d00b
Add specs for the destroy action
aaron-contreras Jul 10, 2024
c8cf6bc
Add specs for the resend_invite action
aaron-contreras Jul 10, 2024
da5cd7b
Add specs for the bulk actions
aaron-contreras Jul 10, 2024
6a5eae1
Fix feature specs after bug fixes
aaron-contreras Jul 10, 2024
625d431
Merge branch 'release/14.3' into sharing-tests
klaustopher Jul 11, 2024
2934ebd
Only send custom invite message when sharing work packages
klaustopher Jul 11, 2024
852a832
Merge branch 'release/14.3' into sharing-tests
klaustopher Jul 11, 2024
8f9e0af
Add an open paramter to the ShareDialog so we can open it in Lookbook
klaustopher Jul 11, 2024
299ed3a
Make the title configurable in the share strategy
klaustopher Jul 11, 2024
69a10ff
Add ProjectQueryStrategy specs
aaron-contreras Jul 11, 2024
cf3ebd4
Add specs for WorkPackageStrategy
aaron-contreras Jul 11, 2024
0c19c23
Adapt specs with new rendering logic
aaron-contreras Jul 11, 2024
3df9566
Add enterprise edition scenarios to feature specs
aaron-contreras Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
icon: "share-android",
mobile_icon: "share-android",
label: t(:label_share),
data: { controller: "async-dialog" }
data: { controller: "async-dialog", test_selector: "toggle-share-dialog-button" }
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/components/shares/invite_user_form_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%=
component_wrapper do
component_wrapper(data_test_selector: 'invite-user-form') do
primer_form_with(
model: new_share,
url: url_for([entity, Member]),
Expand Down
2 changes: 1 addition & 1 deletion app/components/shares/share_dialog_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%=
render(Primer::Alpha::Dialog.new(title: t(:label_share_project_list), id: 'sharing-modal', data: { 'keep-open-on-submit': true }, size: :xlarge)) do |d|
render(Primer::Alpha::Dialog.new(title: strategy.title, id: 'sharing-modal', data: { 'keep-open-on-submit': true }, size: :xlarge, open: open)) do |d|
d.with_header(variant: :large, mb: 3)
d.with_body do
render(strategy.modal_body_component(errors))
Expand Down
5 changes: 3 additions & 2 deletions app/components/shares/share_dialog_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ class ShareDialogComponent < ApplicationComponent
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers

def initialize(strategy:, errors:)
def initialize(strategy:, errors:, open: false)
super

@strategy = strategy
@errors = errors
@open = open
end

private

attr_reader :strategy, :errors
attr_reader :strategy, :errors, :open
end
end
2 changes: 1 addition & 1 deletion app/components/shares/share_row_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
grid_layout(grid_css_classes, tag: :div, align_items: :center, classes: 'ellipsis') do |user_row_grid|
user_row_grid.with_area(:selection, tag: :div) do
if share_editable?
render(Primer::Alpha::CheckBox.new(name: "share_ids", value: share.id, label: principal.name,
render(Primer::Alpha::CheckBox.new(name: "share_ids", value: (share.id || VIRTUAL_SHARE_ID), label: principal.name,
visually_hide_label: true, scheme: :array,
data: {
'shares--bulk-selection-target': 'shareCheckbox',
Expand Down
2 changes: 2 additions & 0 deletions app/components/shares/share_row_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

module Shares
class ShareRowComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
VIRTUAL_SHARE_ID = "virtual-share-id"

include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/shares_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity

visible_shares_before_adding = sharing_strategy.shares.present?

find_or_create_users(send_notification: false) do |member_params|
find_or_create_users(send_notification: send_notification?) do |member_params|
user = User.find_by(id: member_params[:user_id])
if user.present? && user.locked?
@errors.add(:base, I18n.t("sharing.warning_locked_user", user: user.name))
Expand Down Expand Up @@ -279,6 +279,12 @@ def respond_with_bulk_removed_shares(selected_shares)
respond_with_turbo_streams
end

def send_notification?
return false if @entity.is_a?(WorkPackage) # For WorkPackages we have a custom notification

true
end

def load_entity # rubocop:disable Metrics/AbcSize
if params["work_package_id"]
@entity = WorkPackage.visible.find(params["work_package_id"])
Expand Down
4 changes: 4 additions & 0 deletions app/models/sharing_strategies/base_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def share_description(share)
raise NotImplementedError, "Override in a subclass and return a description for the shared user"
end

def title
raise NotImplementedError, "Override in a subclass and return a title for the sharing dialog"
end

def custom_body_components?
!additional_body_components.empty?
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/sharing_strategies/project_query_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def manage_shares_component(modal_content:, errors:)
end
end

def title
I18n.t(:label_share_project_list)
end

private

def virtual_owner_share
Expand Down
4 changes: 4 additions & 0 deletions app/models/sharing_strategies/work_package_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def modal_body_component(errors)
end
end

def title
I18n.t(:label_share_work_package)
end

private

def project_member?(share)
Expand Down
3 changes: 2 additions & 1 deletion app/services/shares/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def add_group_memberships(share)
end

def send_notification(share)
# TODO: We should select what sort of notification is sent out based on the shared entity
return unless share.entity.is_a?(WorkPackage)

OpenProject::Notifications.send(OpenProject::Events::WORK_PACKAGE_SHARED,
work_package_member: share,
send_notifications: true)
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,7 @@ en:
label_invite_user: "Invite user"
label_share: "Share"
label_share_project_list: "Share project list"
label_share_work_package: "Share work package"
label_show_hide: "Show/hide"
label_show_hide_n_items: "Show/hide %{count} items"
label_show_all_registered_users: "Show all registered users"
Expand Down
11 changes: 5 additions & 6 deletions lookbook/previews/shares/share_dialog_component_preview.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
module Shares
# @logical_path OpenProject/Shares
class ShareDialogComponentPreview < Lookbook::Preview
def project_query
user = FactoryBot.build_stubbed(:admin)
query = FactoryBot.build_stubbed(:project_query, user:)
strategy = SharingStrategies::ProjectQueryStrategy.new(query, user:)
strategy = SharingStrategies::ProjectQueryStrategy.new(query, user:, query_params: {})
errors = []
shares = []

render(Shares::ShareDialogComponent.new(strategy:, shares:, errors:))
render(Shares::ShareDialogComponent.new(strategy:, errors:, open: true))
end

def work_package
user = FactoryBot.build_stubbed(:admin)
work_package = FactoryBot.build_stubbed(:work_package)
strategy = SharingStrategies::WorkPackageStrategy.new(work_package, user:)
strategy = SharingStrategies::WorkPackageStrategy.new(work_package, user:, query_params: {})
errors = []
shares = []

render(Shares::ShareDialogComponent.new(strategy:, shares:, errors:))
render(Shares::ShareDialogComponent.new(strategy:, errors:, open: true))
end
end
end
Loading
Loading