From 842dc2eb3e2ac32d6bf4391969107c25e9e56d85 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 12 Nov 2024 10:10:42 +0100 Subject: [PATCH 01/53] Issue CollaboraOnline/collabora-drupal#52: Add links to operations. --- collabora_online.views.inc | 24 ++++++++++++++++ src/Plugin/views/field/CollaboraEdit.php | 32 +++++++++++++++++++++ src/Plugin/views/field/CollaboraPreview.php | 32 +++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 collabora_online.views.inc create mode 100644 src/Plugin/views/field/CollaboraEdit.php create mode 100644 src/Plugin/views/field/CollaboraPreview.php diff --git a/collabora_online.views.inc b/collabora_online.views.inc new file mode 100644 index 00000000..b19e22b3 --- /dev/null +++ b/collabora_online.views.inc @@ -0,0 +1,24 @@ + t('Preview operation in collabora'), + 'group' => t('Media'), + 'field' => [ + 'title' => t('Media preview in collabora'), + 'id' => 'media_collabora_preview', + ], + ]; + $data['media']['collabora_edit'] = [ + 'title' => t('Edit operation in collabora'), + 'group' => t('Media'), + 'field' => [ + 'title' => t('Media edit in collabora'), + 'id' => 'media_collabora_edit', + ], + ]; +} diff --git a/src/Plugin/views/field/CollaboraEdit.php b/src/Plugin/views/field/CollaboraEdit.php new file mode 100644 index 00000000..26add133 --- /dev/null +++ b/src/Plugin/views/field/CollaboraEdit.php @@ -0,0 +1,32 @@ +getEntity($row); + + if ($entity === NULL) { + return NULL; + } + + return CoolUtils::getEditorUrl($entity, TRUE); + } + +} diff --git a/src/Plugin/views/field/CollaboraPreview.php b/src/Plugin/views/field/CollaboraPreview.php new file mode 100644 index 00000000..1b0e4cb3 --- /dev/null +++ b/src/Plugin/views/field/CollaboraPreview.php @@ -0,0 +1,32 @@ +getEntity($row); + + if ($entity === NULL) { + return NULL; + } + + return CoolUtils::getEditorUrl($entity, FALSE); + } + +} From a89fb0d2578d21cf1c375e909a63199b4476d6fb Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 12 Nov 2024 17:10:49 +0100 Subject: [PATCH 02/53] Issue CollaboraOnline/collabora-drupal#52: Add view field links test. --- collabora_online.views.inc | 5 +- config/schema/collabora_online.schema.yml | 12 + .../views.view.test_collabora_links.yml | 272 ++++++++++++++++++ tests/src/Kernel/ViewsLinkFieldsTest.php | 149 ++++++++++ 4 files changed, 436 insertions(+), 2 deletions(-) create mode 100644 tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml create mode 100644 tests/src/Kernel/ViewsLinkFieldsTest.php diff --git a/collabora_online.views.inc b/collabora_online.views.inc index b19e22b3..956ca91c 100644 --- a/collabora_online.views.inc +++ b/collabora_online.views.inc @@ -1,10 +1,11 @@ t('Preview operation in collabora'), 'group' => t('Media'), diff --git a/config/schema/collabora_online.schema.yml b/config/schema/collabora_online.schema.yml index 963dd305..6d16d9de 100644 --- a/config/schema/collabora_online.schema.yml +++ b/config/schema/collabora_online.schema.yml @@ -24,3 +24,15 @@ collabora_online.settings: allowfullscreen: type: boolean label: 'Allow full-screen.' + +views.field.media_collabora_preview: + type: views_field + label: 'Collabora preview link' + mapping: + text: + type: label + label: 'Text to display' + +views.field.media_collabora_edit: + type: views.field.media_collabora_preview + label: 'Collabora edit link' diff --git a/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml b/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml new file mode 100644 index 00000000..e5c96ff1 --- /dev/null +++ b/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml @@ -0,0 +1,272 @@ +langcode: en +status: true +dependencies: + module: + - collabora_online + - media + - user +id: test_collabora_links +label: "Test collabora links" +module: views +description: "" +tag: "" +base_table: media_field_data +base_field: mid +display: + default: + id: default + display_title: Default + display_plugin: default + position: 0 + display_options: + fields: + name: + id: name + table: media_field_data + field: name + relationship: none + group_type: group + admin_label: "" + entity_type: media + entity_field: media + plugin_id: field + label: "" + exclude: false + alter: + alter_text: false + make_link: false + absolute: false + word_boundary: false + ellipsis: false + strip_tags: false + trim: false + html: false + element_type: "" + element_class: "" + element_label_type: "" + element_label_class: "" + element_label_colon: true + element_wrapper_type: "" + element_wrapper_class: "" + element_default_classes: true + empty: "" + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: true + group_column: value + group_columns: {} + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ", " + field_api_classes: false + collabora_preview: + id: collabora_preview + table: media + field: collabora_preview + relationship: none + group_type: group + admin_label: "" + entity_type: media + plugin_id: media_collabora_preview + label: "" + exclude: false + alter: + alter_text: false + text: "" + make_link: false + path: "" + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: "" + rel: "" + link_class: "" + prefix: "" + suffix: "" + target: "" + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: "" + more_link_path: "" + strip_tags: false + trim: false + preserve_tags: "" + html: false + element_type: "" + element_class: "" + element_label_type: "" + element_label_class: "" + element_label_colon: false + element_wrapper_type: "" + element_wrapper_class: "" + element_default_classes: true + empty: "" + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: "Preview in Collabora" + collabora_edit: + id: collabora_edit + table: media + field: collabora_edit + relationship: none + group_type: group + admin_label: "" + entity_type: media + plugin_id: media_collabora_edit + label: "" + exclude: false + alter: + alter_text: false + text: "" + make_link: false + path: "" + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: "" + rel: "" + link_class: "" + prefix: "" + suffix: "" + target: "" + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: "" + more_link_path: "" + strip_tags: false + trim: false + preserve_tags: "" + html: false + element_type: "" + element_class: "" + element_label_type: "" + element_label_class: "" + element_label_colon: false + element_wrapper_type: "" + element_wrapper_class: "" + element_default_classes: true + empty: "" + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: "Edit in Collabora" + pager: + type: mini + options: + offset: 0 + pagination_heading_level: h4 + items_per_page: 10 + total_pages: null + id: 0 + tags: + next: ›› + previous: ‹‹ + expose: + items_per_page: false + items_per_page_label: "Items per page" + items_per_page_options: "5, 10, 25, 50" + items_per_page_options_all: false + items_per_page_options_all_label: "- All -" + offset: false + offset_label: Offset + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: "Sort by" + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + access: + type: perm + options: + perm: "view media" + cache: + type: tag + options: {} + empty: {} + sorts: {} + arguments: {} + filters: + status: + id: status + table: media_field_data + field: status + entity_type: media + entity_field: status + plugin_id: boolean + value: "1" + group: 1 + expose: + operator: "" + style: + type: default + options: + grouping: {} + row_class: "" + default_row_class: true + uses_fields: false + row: + type: fields + options: + default_field_elements: true + inline: {} + separator: "" + hide_empty: false + query: + type: views_query + options: + query_comment: "" + disable_sql_rewrite: false + distinct: false + replica: false + query_tags: {} + relationships: {} + header: {} + footer: {} + display_extenders: {} + cache_metadata: + max-age: -1 + contexts: + - "languages:language_content" + - "languages:language_interface" + - url.query_args + - user.permissions + tags: {} + page_1: + id: page_1 + display_title: Page + display_plugin: page + position: 1 + display_options: + display_extenders: {} + path: test_collabora_links + cache_metadata: + max-age: -1 + contexts: + - "languages:language_content" + - "languages:language_interface" + - url.query_args + - user.permissions + tags: {} diff --git a/tests/src/Kernel/ViewsLinkFieldsTest.php b/tests/src/Kernel/ViewsLinkFieldsTest.php new file mode 100644 index 00000000..5ccdbf08 --- /dev/null +++ b/tests/src/Kernel/ViewsLinkFieldsTest.php @@ -0,0 +1,149 @@ +installEntitySchema('file'); + $this->installEntitySchema('media'); + $this->installEntitySchema('user'); + $this->installConfig(['user', 'views', 'collabora_online_test']); + $this->installSchema('file', ['file_usage']); + // Install user module avoid user 1 permissions bypass. + \Drupal::moduleHandler()->loadInclude('user', 'install'); + user_install(); + + // Create two medias to check access with different scopes, 'any' and 'own'. + $this->createMediaEntity('document'); + $this->ownMedia = $this->createMediaEntity('document');; + } + + /** + * Tests link fields. + */ + public function testLinks(): void { + // User without permissions can't see links. + $this->doTestLinks([ + 'preview' => [FALSE, FALSE], + 'edit' => [FALSE, FALSE], + ], + $this->createUser([])); + // User with 'Preview' permission can see preview link. + $this->doTestLinks([ + 'preview' => [TRUE, TRUE], + 'edit' => [FALSE, FALSE], + ], + $this->createUser([ + 'preview document in collabora' + ])); + // User with 'Edit any' permission can see edit link. + $this->doTestLinks([ + 'preview' => [FALSE, FALSE], + 'edit' => [TRUE, TRUE], + ], + $this->createUser([ + 'edit any document in collabora' + ])); + // User with 'Edit own' permission can see edit link for entities they own. + $this->doTestLinks([ + 'preview' => [FALSE, FALSE], + 'edit' => [FALSE, TRUE], + ], + $this->createUser([ + 'edit own document in collabora' + ])); + } + + /** + * Tests that links behave as expected. + * + * @param [] $expected_results + * An associative array of expected results keyed by operation. + * @param \Drupal\Core\Session\AccountInterface $account + * The user account to be used to run the test; + */ + protected function doTestLinks(array $expected_results, AccountInterface $account) { + $this->setCurrentUser(account: $account); + // Set the current user as the owner to check 'edit own' access. + $this->ownMedia->setOwnerId($account->id())->save(); + $view = Views::getView('test_collabora_links'); + $view->preview(); + + $info = [ + 'preview' => [ + 'label' => 'Preview in Collabora', + 'field_id' => 'collabora_preview', + 'route' => 'collabora-online.view' + ], + 'edit' => [ + 'label' => 'Edit in Collabora', + 'field_id' => 'collabora_edit', + 'route' => 'collabora-online.edit' + ], + ]; + + $i = 0; + // Check each expected results for every media. + foreach(Media::loadMultiple() as $media) { + foreach ($expected_results as $operation => $expected_result) { + $expected_link = ''; + // The operation array contains results for each of the entities. + if ($expected_result[$i]) { + $path = Url::fromRoute($info[$operation]['route'], ['media' => $media->id()])->toString(); + $expected_link = '' . $info[$operation]['label'] . ''; + } + // We check the output, whether it is a link or is empty (access denied). + $link = $view->style_plugin->getField($i, $info[$operation]['field_id']); + $this->assertEquals($expected_link, (string) $link); + } + $i++; + } + } + +} From 15aa98815dbf613d12f2fbf57793fea0b7d1a96a Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 15 Nov 2024 14:50:46 +0100 Subject: [PATCH 03/53] Issue CollaboraOnline/collabora-drupal#52: Override groupmedia view. --- .../collabora_online_group.install | 22 + .../override/views.view.group_media.yml | 1014 +++++++++++++++++ .../{SmokeTest.php => InstallationTest.php} | 7 +- 3 files changed, 1039 insertions(+), 4 deletions(-) create mode 100644 modules/collabora_online_group/collabora_online_group.install create mode 100644 modules/collabora_online_group/config/override/views.view.group_media.yml rename modules/collabora_online_group/tests/src/Functional/{SmokeTest.php => InstallationTest.php} (77%) diff --git a/modules/collabora_online_group/collabora_online_group.install b/modules/collabora_online_group/collabora_online_group.install new file mode 100644 index 00000000..8ff48a95 --- /dev/null +++ b/modules/collabora_online_group/collabora_online_group.install @@ -0,0 +1,22 @@ +moduleExists('views') && + \Drupal::entityTypeManager()->getStorage('view')->load('group_media') + ) { + // Update view with module configuration. + $name = 'views.view.group_media'; + $module_path = Drupal::moduleHandler()->getModule('collabora_online_group')->getPath(); + $source = new FileStorage($module_path . '/config/override'); + /** @var \Drupal\Core\Config\StorageInterface $active_storage */ + $active_storage = \Drupal::service('config.storage'); + $config = $source->read( $name); + $active_storage->write($name, $config); + } +} diff --git a/modules/collabora_online_group/config/override/views.view.group_media.yml b/modules/collabora_online_group/config/override/views.view.group_media.yml new file mode 100644 index 00000000..4082e523 --- /dev/null +++ b/modules/collabora_online_group/config/override/views.view.group_media.yml @@ -0,0 +1,1014 @@ +status: true +dependencies: + module: + - collabora_online + - group + - media + enforced: + module: + - groupmedia +id: group_media +label: 'Group Media' +module: views +description: '' +tag: '' +base_table: media_field_data +base_field: mid +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + title: 'Group Media' + fields: + name: + id: name + table: media_field_data + field: name + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: media + plugin_id: field + label: 'Media name' + exclude: false + alter: + alter_text: false + make_link: false + absolute: false + word_boundary: false + ellipsis: false + strip_tags: false + trim: false + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: true + group_column: value + group_columns: {} + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + bundle: + id: bundle + table: media_field_data + field: bundle + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: bundle + plugin_id: field + label: Bundle + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: target_id + type: entity_reference_label + settings: + link: false + group_column: target_id + group_columns: {} + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + status: + id: status + table: media_field_data + field: status + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: status + plugin_id: field + label: Status + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: boolean + settings: + format: yes-no + format_custom_false: '' + format_custom_true: '' + group_column: value + group_columns: {} + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + uid: + id: uid + table: media_field_data + field: uid + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: uid + plugin_id: field + label: Publisher + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: target_id + type: entity_reference_label + settings: + link: false + group_column: target_id + group_columns: {} + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + collabora_preview: + id: collabora_preview + table: media + field: collabora_preview + relationship: none + group_type: group + admin_label: '' + entity_type: media + plugin_id: media_collabora_preview + label: '' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Preview in Collabora' + collabora_edit: + id: collabora_edit + table: media + field: collabora_edit + relationship: none + group_type: group + admin_label: '' + entity_type: media + plugin_id: media_collabora_edit + label: '' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Edit in Collabora' + view_group_content: + id: view_group_content + table: group_relationship + field: view_group_content + relationship: group_content + group_type: group + admin_label: '' + entity_type: group_content + plugin_id: entity_link + label: 'View relation link' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'View relation' + output_url_as_text: false + absolute: false + edit_group_content: + id: edit_group_content + table: group_relationship + field: edit_group_content + relationship: group_content + group_type: group + admin_label: '' + entity_type: group_content + plugin_id: entity_link_edit + label: 'Edit relation link' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Edit relation' + delete_group_content: + id: delete_group_content + table: group_relationship + field: delete_group_content + relationship: group_content + group_type: group + admin_label: '' + entity_type: group_content + plugin_id: entity_link_delete + label: 'Delete relation link' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Delete relation' + edit_media: + id: edit_media + table: media + field: edit_media + relationship: none + group_type: group + admin_label: '' + entity_type: media + plugin_id: entity_link_edit + label: 'Edit media' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: Edit + delete_media: + id: delete_media + table: media + field: delete_media + relationship: none + group_type: group + admin_label: '' + entity_type: media + plugin_id: entity_link_delete + label: 'Delete Media' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: Delete + dropbutton: + id: dropbutton + table: views + field: dropbutton + relationship: none + group_type: group + admin_label: '' + plugin_id: dropbutton + label: Dropbutton + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + destination: true + fields: + collabora_preview: collabora_preview + collabora_edit: collabora_edit + view_group_content: view_group_content + edit_group_content: edit_group_content + delete_group_content: delete_group_content + edit_media: edit_media + delete_media: delete_media + name: '0' + bundle: '0' + status: '0' + pager: + type: mini + options: + offset: 0 + items_per_page: 50 + total_pages: null + id: 0 + tags: + next: ›› + previous: ‹‹ + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + access: + type: group_permission + options: + group_permission: 'access group_media overview' + cache: + type: tag + options: {} + empty: {} + sorts: {} + arguments: + gid: + id: gid + table: group_relationship_field_data + field: gid + relationship: group_content + group_type: group + admin_label: '' + entity_type: group_content + entity_field: gid + plugin_id: group_id + default_action: ignore + exception: + value: all + title_enable: false + title: All + title_enable: true + title: '{{ arguments.gid|placeholder }} media items' + default_argument_type: fixed + default_argument_options: + argument: '' + default_argument_skip_url: false + summary_options: + base_path: '' + count: true + override: false + items_per_page: 25 + summary: + sort_order: asc + number_of_records: 0 + format: default_summary + specify_validation: false + validate: + type: none + fail: 'not found' + validate_options: {} + break_phrase: false + not: false + filters: + status: + id: status + table: media_field_data + field: status + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: status + plugin_id: boolean + operator: '=' + value: '1' + group: 1 + exposed: true + expose: + operator_id: '' + label: Status + description: null + use_operator: false + operator: status_op + identifier: status + required: true + remember: false + multiple: false + remember_roles: + authenticated: authenticated + is_grouped: true + group_info: + label: Status + description: '' + identifier: status + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: {} + group_items: + 1: + title: Published + operator: '=' + value: '1' + 2: + title: Unpublished + operator: '=' + value: '0' + bundle: + id: bundle + table: media_field_data + field: bundle + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: bundle + plugin_id: bundle + operator: in + value: {} + group: 1 + exposed: true + expose: + operator_id: bundle_op + label: 'Media type' + description: '' + use_operator: false + operator: bundle_op + identifier: bundle + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + anonymous: '0' + administrator: '0' + reduce: false + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: {} + group_items: {} + style: + type: table + options: + grouping: {} + row_class: '' + default_row_class: true + columns: + name: name + bundle: bundle + status: status + uid: uid + view_group_content: view_group_content + edit_group_content: edit_group_content + delete_group_content: delete_group_content + edit_media: edit_media + delete_media: delete_media + dropbutton: dropbutton + default: '-1' + info: + name: + sortable: true + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + bundle: + sortable: true + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + status: + sortable: true + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + uid: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + view_group_content: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + edit_group_content: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + delete_group_content: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + edit_media: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + delete_media: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + dropbutton: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + override: true + sticky: false + summary: '' + empty_table: false + caption: '' + description: '' + row: + type: fields + query: + type: views_query + options: + query_comment: '' + disable_sql_rewrite: false + distinct: false + replica: false + query_tags: {} + relationships: + group_content: + id: group_content + table: media_field_data + field: group_content + relationship: none + group_type: group + admin_label: 'Media group content' + entity_type: media + plugin_id: group_content_to_entity_reverse + required: false + group_content_plugins: + 'group_media:audio': '0' + 'group_media:file': '0' + 'group_media:image': '0' + 'group_media:remote_video': '0' + 'group_media:video': '0' + header: {} + footer: {} + display_extenders: {} + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - route.group + - url + - url.query_args + - user.group_permissions + tags: {} + page_1: + id: page_1 + display_title: Page + display_plugin: page + position: 1 + display_options: + display_extenders: {} + path: group/%group/media + menu: + type: tab + title: Media + description: '' + weight: 0 + expanded: false + menu_name: main + parent: '' + context: '0' + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - route.group + - url + - url.query_args + - user.group_permissions + tags: {} diff --git a/modules/collabora_online_group/tests/src/Functional/SmokeTest.php b/modules/collabora_online_group/tests/src/Functional/InstallationTest.php similarity index 77% rename from modules/collabora_online_group/tests/src/Functional/SmokeTest.php rename to modules/collabora_online_group/tests/src/Functional/InstallationTest.php index 95a22e47..b5dce8f2 100644 --- a/modules/collabora_online_group/tests/src/Functional/SmokeTest.php +++ b/modules/collabora_online_group/tests/src/Functional/InstallationTest.php @@ -7,15 +7,16 @@ use Drupal\Tests\BrowserTestBase; /** - * Smoke test to check that CI is working. + * Test module installation with groupmedia view override. */ -class SmokeTest extends BrowserTestBase { +class InstallationTest extends BrowserTestBase { /** * {@inheritdoc} */ protected static $modules = [ 'collabora_online_group', + 'views', ]; /** @@ -25,8 +26,6 @@ class SmokeTest extends BrowserTestBase { /** * Tests that the module install correctly. - * - * To be removed when other tests are implemented. */ public function testModuleInstallation(): void { $this->drupalGet(''); From 81e8f54cfd1468781f872dbe4d538332f756279d Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Mon, 18 Nov 2024 11:40:53 +0100 Subject: [PATCH 04/53] Issue CollaboraOnline/collabora-drupal#52: Add test to check changes on view. --- .../override/views.view.group_media.yml | 284 +----------------- .../tests/src/Functional/InstallationTest.php | 35 --- .../tests/src/Functional/ViewTest.php | 142 +++++++++ 3 files changed, 156 insertions(+), 305 deletions(-) delete mode 100644 modules/collabora_online_group/tests/src/Functional/InstallationTest.php create mode 100644 modules/collabora_online_group/tests/src/Functional/ViewTest.php diff --git a/modules/collabora_online_group/config/override/views.view.group_media.yml b/modules/collabora_online_group/config/override/views.view.group_media.yml index 4082e523..0db5c082 100644 --- a/modules/collabora_online_group/config/override/views.view.group_media.yml +++ b/modules/collabora_online_group/config/override/views.view.group_media.yml @@ -369,263 +369,6 @@ display: empty_zero: false hide_alter_empty: true text: 'Edit in Collabora' - view_group_content: - id: view_group_content - table: group_relationship - field: view_group_content - relationship: group_content - group_type: group - admin_label: '' - entity_type: group_content - plugin_id: entity_link - label: 'View relation link' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: 'View relation' - output_url_as_text: false - absolute: false - edit_group_content: - id: edit_group_content - table: group_relationship - field: edit_group_content - relationship: group_content - group_type: group - admin_label: '' - entity_type: group_content - plugin_id: entity_link_edit - label: 'Edit relation link' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: 'Edit relation' - delete_group_content: - id: delete_group_content - table: group_relationship - field: delete_group_content - relationship: group_content - group_type: group - admin_label: '' - entity_type: group_content - plugin_id: entity_link_delete - label: 'Delete relation link' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: 'Delete relation' - edit_media: - id: edit_media - table: media - field: edit_media - relationship: none - group_type: group - admin_label: '' - entity_type: media - plugin_id: entity_link_edit - label: 'Edit media' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: Edit - delete_media: - id: delete_media - table: media - field: delete_media - relationship: none - group_type: group - admin_label: '' - entity_type: media - plugin_id: entity_link_delete - label: 'Delete Media' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: Delete dropbutton: id: dropbutton table: views @@ -634,7 +377,7 @@ display: group_type: group admin_label: '' plugin_id: dropbutton - label: Dropbutton + label: Operations exclude: false alter: alter_text: false @@ -679,14 +422,15 @@ display: fields: collabora_preview: collabora_preview collabora_edit: collabora_edit - view_group_content: view_group_content - edit_group_content: edit_group_content - delete_group_content: delete_group_content edit_media: edit_media delete_media: delete_media + edit_group_relationship: edit_group_relationship + delete_group_relationship: delete_group_relationship + view_group_relationship: view_group_relationship name: '0' bundle: '0' status: '0' + uid: '0' pager: type: mini options: @@ -729,10 +473,10 @@ display: id: gid table: group_relationship_field_data field: gid - relationship: group_content + relationship: group_relationship group_type: group admin_label: '' - entity_type: group_content + entity_type: group_relationship entity_field: gid plugin_id: group_id default_action: ignore @@ -956,19 +700,19 @@ display: replica: false query_tags: {} relationships: - group_content: - id: group_content + group_relationship: + id: group_relationship table: media_field_data - field: group_content + field: group_relationship relationship: none group_type: group - admin_label: 'Media group content' + admin_label: 'Media group relationship' entity_type: media - plugin_id: group_content_to_entity_reverse + plugin_id: group_relationship_to_entity_reverse required: false - group_content_plugins: + group_relation_plugins: 'group_media:audio': '0' - 'group_media:file': '0' + 'group_media:document': '0' 'group_media:image': '0' 'group_media:remote_video': '0' 'group_media:video': '0' diff --git a/modules/collabora_online_group/tests/src/Functional/InstallationTest.php b/modules/collabora_online_group/tests/src/Functional/InstallationTest.php deleted file mode 100644 index b5dce8f2..00000000 --- a/modules/collabora_online_group/tests/src/Functional/InstallationTest.php +++ /dev/null @@ -1,35 +0,0 @@ -drupalGet(''); - $this->assertSession()->statusCodeEquals(200); - } - -} diff --git a/modules/collabora_online_group/tests/src/Functional/ViewTest.php b/modules/collabora_online_group/tests/src/Functional/ViewTest.php new file mode 100644 index 00000000..58f75b2f --- /dev/null +++ b/modules/collabora_online_group/tests/src/Functional/ViewTest.php @@ -0,0 +1,142 @@ +createGroupType(['id' => 'group_type_1']); + $media_type = $this->createMediaType('file', ['id' => 'document']); + $this->createGroupRole([ + 'group_type' => 'group_type_1', + 'scope' => PermissionScopeInterface::INSIDER_ID, + 'global_role' => RoleInterface::AUTHENTICATED_ID, + 'permissions' => [ + 'view group', + 'access group_media overview', + 'view group_media:document entity', + 'edit any group_media:document in collabora', + 'preview group_media:document in collabora', + ], + ]); + $this->createPluginRelation($group_type, 'group_media:document', [ + 'group_cardinality' => 0, + 'entity_cardinality' => 1, + 'use_creation_wizard' => FALSE, + ]); + + // Create content. + $group = $this->createGroup(['type' => 'group_type_1']); + for ($i = 1;$i < 4;$i++) { + $media = $this->createMediaEntity('document', [ + 'id' => 'media_' . $i, + 'name' => 'Media ' . $i, + ]); + $group->addRelationship($media, 'group_media:document'); + } + $user = $this->createUser([ + 'view the administration theme', + 'access administration pages', + 'access group overview', + ]); + $group->addMember($user); + + // Go to the page and check the links added to the view. + $this->drupalLogin($user); + $this->drupalGet("group/{$group->id()}/media"); + $assert_session = $this->assertSession(); + + // Check table header. + $table = $assert_session->elementExists('css', 'table'); + $table_header = $assert_session->elementExists('css', 'thead', $table); + $rows = $table_header->findAll('css', 'tr'); + $cols = $rows[0]->findAll('css', 'th'); + $this->assertEquals('Media name', $cols[0]->getText()); + $this->assertEquals('Bundle', $cols[1]->getText()); + $this->assertEquals('Status', $cols[2]->getText()); + $this->assertEquals('Publisher', $cols[3]->getText()); + $this->assertEquals('Operations', $cols[4]->getText()); + + // Check that rows contain new links for operations in Collabora. + $table_body = $assert_session->elementExists('css', 'tbody', $table); + $rows = $table_body->findAll('css', 'tr'); + $i = 0; + foreach(Media::loadMultiple() as $media) { + $cols = $rows[$i]->findAll('css', 'td'); + $this->assertEquals($media->getName(), $cols[0]->getText()); + $this->assertEquals($media_type->label(), $cols[1]->getText()); + $this->assertEquals('Yes', $cols[2]->getText()); + $this->assertEquals('Anonymous', $cols[3]->getText()); + $operation_links = $cols[4]->findAll('css', 'a'); + $this->assertEquals('Preview in Collabora', $operation_links[0]->getText()); + $this->assertEquals( + Url::fromRoute( + 'collabora-online.view', + [ + 'media' => $media->id() + ], + [ + 'query' => [ + 'destination' => "/group/{$group->id()}/media", + ] + ] + )->toString(), + $operation_links[0]->getAttribute('href') + ); + $this->assertEquals('Edit in Collabora', $operation_links[1]->getText()); + $this->assertEquals( + Url::fromRoute( + 'collabora-online.edit', + [ + 'media' => $media->id() + ], + [ + 'query' => [ + 'destination' => "/group/{$group->id()}/media", + ] + ] + )->toString(), + $operation_links[1]->getAttribute('href') + ); + $i++; + } + } + +} From 6c8fb2e83abb49ef08385035e7ab266fc476a187 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 7 Nov 2024 16:30:11 +0100 Subject: [PATCH 05/53] Issue CollaboraOnline/collabora-drupal#52: Add services. --- .../collabora_online_group.services.yml | 9 ++ .../CollaboraAccessControl.php | 43 +++++++++ .../CollaboraPermissionProvider.php | 92 +++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 modules/collabora_online_group/collabora_online_group.services.yml create mode 100644 modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php create mode 100644 modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php diff --git a/modules/collabora_online_group/collabora_online_group.services.yml b/modules/collabora_online_group/collabora_online_group.services.yml new file mode 100644 index 00000000..7cb176b0 --- /dev/null +++ b/modules/collabora_online_group/collabora_online_group.services.yml @@ -0,0 +1,9 @@ +services: + group.relation_handler.permission_provider.collabora_group_media: + class: 'Drupal\collabora_online_group\Plugin\Group\RelationHandler\CollaboraPermissionProvider' + decorates: group.relation_handler.permission_provider.group_media + arguments: [ '@group.relation_handler.permission_provider.collabora_group_media.inner', '@group.relation_handler.permission_provider' ] + + group.relation_handler.access_control.group_media: + class: 'Drupal\collabora_online_group\Plugin\Group\RelationHandler\CollaboraAccessControl' + arguments: ['@group.relation_handler.access_control'] diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php new file mode 100644 index 00000000..4dd7a168 --- /dev/null +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php @@ -0,0 +1,43 @@ +parent = $parent; + } + + /** + * {@inheritdoc} + */ + public function supportsOperation($operation, $target): bool { + $allowed_operations = [ + 'edit in collabora', + 'preview in collabora' + ]; + + if (in_array($operation, $allowed_operations) && $target === 'entity') { + return TRUE; + } + + return $this->parent->supportsOperation($operation, $target); + } + +} diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php new file mode 100644 index 00000000..f89cbc45 --- /dev/null +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php @@ -0,0 +1,92 @@ +parent->buildPermissions(); + + /** @see \Drupal\group\Plugin\Group\RelationHandlerDefault\PermissionProvider::buildPermissions() */ + $provider_chain = $this->groupRelationTypeManager()->getPermissionProvider($this->pluginId); + + // Add Collabora permissions. + $prefix = 'Entity:'; + if ($name = $provider_chain->getPermission('preview in collabora', 'entity')) { + $permissions[$name] = $this->buildPermission("$prefix Preview %entity_type in collabora"); + } + if ($name = $provider_chain->getPermission('edit in collabora', 'entity')) { + $permissions[$name] = $this->buildPermission("$prefix Edit any %entity_type in collabora"); + } + if ($name = $provider_chain->getPermission('edit in collabora', 'entity', 'own')) { + $permissions[$name] = $this->buildPermission("$prefix Edit own %entity_type in collabora"); + } + + return $permissions; + } + + /** + * {@inheritdoc} + */ + public function getPermission($operation, $target, $scope = 'any'): bool|string { + if ($target === 'entity') { + switch ($operation) { + case 'preview in collabora': + return "preview $this->pluginId in collabora"; + + case 'edit in collabora': + return $this->getCollaboraEditPermission($scope); + } + } + + // Since we are overriding decorated service method, we call the original + // method too. + return $this->groupMediaPermissionProvider->getPermission($operation, $target, $scope); + } + + /** + * Gets the name of the edit permission in Collabora. + * + * @param string $scope + * (optional) Whether the 'any' or 'own' permission name should be returned. + * Defaults to 'any'. + * + * @return string|false + * The permission name or FALSE if it does not apply. + */ + protected function getCollaboraEditPermission($scope = 'any'): bool|string { + if ($this->definesEntityPermissions) { + if ($this->implementsOwnerInterface || $scope === 'any') { + return "edit $scope $this->pluginId in collabora"; + } + } + + return FALSE; + } +} From 81ff14d980b923fe6678c518fabb39f967ab9f80 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Mon, 18 Nov 2024 09:34:11 +0100 Subject: [PATCH 06/53] Issue CollaboraOnline/collabora-drupal#52: Support for groupmedia 3 and 4. --- .../collabora_online_group.install | 8 +- .../override/views.view.group_media-3.yml | 1017 +++++++++++++++++ 2 files changed, 1024 insertions(+), 1 deletion(-) create mode 100644 modules/collabora_online_group/config/override/views.view.group_media-3.yml diff --git a/modules/collabora_online_group/collabora_online_group.install b/modules/collabora_online_group/collabora_online_group.install index 8ff48a95..04f14000 100644 --- a/modules/collabora_online_group/collabora_online_group.install +++ b/modules/collabora_online_group/collabora_online_group.install @@ -12,11 +12,17 @@ function collabora_online_group_install(): void { ) { // Update view with module configuration. $name = 'views.view.group_media'; + + // Fallback for older versions. + if (\Drupal::entityTypeManager()->getDefinition('group_relationship_type', FALSE) === NULL) { + $name = 'views.view.group_media-3'; + } + $module_path = Drupal::moduleHandler()->getModule('collabora_online_group')->getPath(); $source = new FileStorage($module_path . '/config/override'); /** @var \Drupal\Core\Config\StorageInterface $active_storage */ $active_storage = \Drupal::service('config.storage'); $config = $source->read( $name); - $active_storage->write($name, $config); + $active_storage->write('views.view.group_media', $config); } } diff --git a/modules/collabora_online_group/config/override/views.view.group_media-3.yml b/modules/collabora_online_group/config/override/views.view.group_media-3.yml new file mode 100644 index 00000000..4bed5cad --- /dev/null +++ b/modules/collabora_online_group/config/override/views.view.group_media-3.yml @@ -0,0 +1,1017 @@ +uuid: null +langcode: en +status: true +dependencies: + module: + - collabora_online + - group + - media + enforced: + module: + - groupmedia +id: group_media +label: 'Group Media' +module: views +description: '' +tag: '' +base_table: media_field_data +base_field: mid +display: + default: + id: default + display_title: Master + display_plugin: default + position: 0 + display_options: + title: 'Group Media' + fields: + name: + id: name + table: media_field_data + field: name + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: media + plugin_id: field + label: 'Media name' + exclude: false + alter: + alter_text: false + make_link: false + absolute: false + word_boundary: false + ellipsis: false + strip_tags: false + trim: false + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: true + group_column: value + group_columns: {} + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + bundle: + id: bundle + table: media_field_data + field: bundle + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: bundle + plugin_id: field + label: Bundle + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: target_id + type: entity_reference_label + settings: + link: false + group_column: target_id + group_columns: {} + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + status: + id: status + table: media_field_data + field: status + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: status + plugin_id: field + label: Status + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: boolean + settings: + format: yes-no + format_custom_false: '' + format_custom_true: '' + group_column: value + group_columns: {} + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + uid: + id: uid + table: media_field_data + field: uid + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: uid + plugin_id: field + label: Publisher + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: target_id + type: entity_reference_label + settings: + link: false + group_column: target_id + group_columns: {} + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + view_group_content: + id: view_group_content + table: group_relationship + field: view_group_content + relationship: group_content + group_type: group + admin_label: '' + entity_type: group_content + plugin_id: entity_link + label: 'View relation link' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'View relation' + output_url_as_text: false + absolute: false + edit_group_content: + id: edit_group_content + table: group_relationship + field: edit_group_content + relationship: group_content + group_type: group + admin_label: '' + entity_type: group_content + plugin_id: entity_link_edit + label: 'Edit relation link' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Edit relation' + delete_group_content: + id: delete_group_content + table: group_relationship + field: delete_group_content + relationship: group_content + group_type: group + admin_label: '' + entity_type: group_content + plugin_id: entity_link_delete + label: 'Delete relation link' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Delete relation' + collabora_preview: + id: collabora_preview + table: media + field: collabora_preview + relationship: none + group_type: group + admin_label: '' + entity_type: media + plugin_id: media_collabora_preview + label: '' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Preview in Collabora' + collabora_edit: + id: collabora_edit + table: media + field: collabora_edit + relationship: none + group_type: group + admin_label: '' + entity_type: media + plugin_id: media_collabora_edit + label: '' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Edit in Collabora' + edit_media: + id: edit_media + table: media + field: edit_media + relationship: none + group_type: group + admin_label: '' + entity_type: media + plugin_id: entity_link_edit + label: 'Edit media' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: Edit + delete_media: + id: delete_media + table: media + field: delete_media + relationship: none + group_type: group + admin_label: '' + entity_type: media + plugin_id: entity_link_delete + label: 'Delete Media' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: Delete + dropbutton: + id: dropbutton + table: views + field: dropbutton + relationship: none + group_type: group + admin_label: '' + plugin_id: dropbutton + label: Operations + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + destination: true + fields: + view_group_content: view_group_content + edit_group_content: edit_group_content + delete_group_content: delete_group_content + collabora_preview: collabora_preview + collabora_edit: collabora_edit + edit_media: edit_media + delete_media: delete_media + name: '0' + bundle: '0' + status: '0' + uid: '0' + pager: + type: mini + options: + offset: 0 + pagination_heading_level: h4 + items_per_page: 50 + total_pages: null + id: 0 + tags: + next: ›› + previous: ‹‹ + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + access: + type: group_permission + options: + group_permission: 'access group_media overview' + cache: + type: tag + options: {} + empty: {} + sorts: {} + arguments: + gid: + id: gid + table: group_relationship_field_data + field: gid + relationship: group_content + group_type: group + admin_label: '' + entity_type: group_content + entity_field: gid + plugin_id: group_id + default_action: ignore + exception: + value: all + title_enable: false + title: All + title_enable: true + title: '{{ arguments.gid|placeholder }} media items' + default_argument_type: fixed + default_argument_options: + argument: '' + summary_options: + base_path: '' + count: true + override: false + items_per_page: 25 + summary: + sort_order: asc + number_of_records: 0 + format: default_summary + specify_validation: false + validate: + type: none + fail: 'not found' + validate_options: {} + break_phrase: false + not: false + filters: + status: + id: status + table: media_field_data + field: status + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: status + plugin_id: boolean + operator: '=' + value: '1' + group: 1 + exposed: true + expose: + operator_id: '' + label: Status + description: null + use_operator: false + operator: status_op + identifier: status + required: true + remember: false + multiple: false + remember_roles: + authenticated: authenticated + is_grouped: true + group_info: + label: Status + description: '' + identifier: status + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: {} + group_items: + 1: + title: Published + operator: '=' + value: '1' + 2: + title: Unpublished + operator: '=' + value: '0' + bundle: + id: bundle + table: media_field_data + field: bundle + relationship: none + group_type: group + admin_label: '' + entity_type: media + entity_field: bundle + plugin_id: bundle + operator: in + value: {} + group: 1 + exposed: true + expose: + operator_id: bundle_op + label: 'Media type' + description: '' + use_operator: false + operator: bundle_op + identifier: bundle + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + anonymous: '0' + administrator: '0' + reduce: false + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: {} + group_items: {} + style: + type: table + options: + grouping: {} + row_class: '' + default_row_class: true + columns: + name: name + bundle: bundle + status: status + uid: uid + view_group_content: view_group_content + edit_group_content: edit_group_content + delete_group_content: delete_group_content + edit_media: edit_media + delete_media: delete_media + dropbutton: dropbutton + default: '-1' + info: + name: + sortable: true + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + bundle: + sortable: true + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + status: + sortable: true + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + uid: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + view_group_content: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + edit_group_content: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + delete_group_content: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + edit_media: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + delete_media: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + dropbutton: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + override: true + sticky: false + summary: '' + empty_table: false + caption: '' + description: '' + row: + type: fields + query: + type: views_query + options: + query_comment: '' + disable_sql_rewrite: false + distinct: false + replica: false + query_tags: {} + relationships: + group_content: + id: group_content + table: media_field_data + field: group_content + relationship: none + group_type: group + admin_label: 'Media group content' + entity_type: media + plugin_id: group_content_to_entity_reverse + required: false + group_content_plugins: + 'group_media:audio': '0' + 'group_media:file': '0' + 'group_media:image': '0' + 'group_media:remote_video': '0' + 'group_media:video': '0' + header: {} + footer: {} + display_extenders: {} + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - route.group + - url + - url.query_args + - user.group_permissions + tags: {} + page_1: + id: page_1 + display_title: Page + display_plugin: page + position: 1 + display_options: + display_extenders: {} + path: group/%group/media + menu: + type: tab + title: Media + description: '' + weight: 0 + expanded: false + menu_name: main + parent: '' + context: '0' + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - route.group + - url + - url.query_args + - user.group_permissions + tags: {} From ae542b7d93b92152205407ba501a14537314f0f1 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 14 Nov 2024 08:57:59 +0100 Subject: [PATCH 07/53] Issue CollaboraOnline/collabora-drupal#52: Add permissions test. --- .../tests/src/Kernel/PermissionTest.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 modules/collabora_online_group/tests/src/Kernel/PermissionTest.php diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php new file mode 100644 index 00000000..599fd9a3 --- /dev/null +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -0,0 +1,80 @@ +createGroupType(); + $group_type_2 = $this->createGroupType(); + $media_type_1 = $this->createMediaType('file'); + $media_type_2 = $this->createMediaType('file'); + + // Enable relation plugins in groups. + $this->entityTypeManager()->getStorage('group_relationship_type') + ->createFromPlugin($group_type_1, 'group_media:' . $media_type_1->id(), [ + 'group_cardinality' => 0, + 'entity_cardinality' => 1, + 'use_creation_wizard' => FALSE, + ]) + ->save(); + $this->entityTypeManager()->getStorage('group_relationship_type') + ->createFromPlugin($group_type_2, 'group_media:' . $media_type_1->id(), [ + 'group_cardinality' => 0, + 'entity_cardinality' => 1, + 'use_creation_wizard' => FALSE, + ]) + ->save(); + $this->entityTypeManager()->getStorage('group_relationship_type') + ->createFromPlugin($group_type_2, 'group_media:' . $media_type_2->id(), [ + 'group_cardinality' => 0, + 'entity_cardinality' => 1, + 'use_creation_wizard' => FALSE, + ]) + ->save(); + + // Check that permissions are generated for the groups. + // The 'group_1' has only 'media_type_1' permissions. + $permissions_group_1 = \Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_1); + $this->assertArrayHasKey("preview group_media:{$media_type_1->id()} in collabora", $permissions_group_1); + $this->assertArrayHasKey("edit any group_media:{$media_type_1->id()} in collabora", $permissions_group_1); + $this->assertArrayHasKey("edit own group_media:{$media_type_1->id()} in collabora", $permissions_group_1); + $this->assertArrayNotHasKey("preview group_media:{$media_type_2->id()} in collabora", $permissions_group_1); + $this->assertArrayNotHasKey("edit any group_media:{$media_type_2->id()} in collabora", $permissions_group_1); + $this->assertArrayNotHasKey("edit own group_media:{$media_type_2->id()} in collabora", $permissions_group_1); + // The 'group_2' has 'media_type_1' and 'media_type_2' permissions. + $permissions_group_2 = \Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_2); + $this->assertArrayHasKey("preview group_media:{$media_type_1->id()} in collabora", $permissions_group_1); + $this->assertArrayHasKey("edit any group_media:{$media_type_1->id()} in collabora", $permissions_group_1); + $this->assertArrayHasKey("edit own group_media:{$media_type_1->id()} in collabora", $permissions_group_1); + $this->assertArrayHasKey("preview group_media:{$media_type_2->id()} in collabora", $permissions_group_2); + $this->assertArrayHasKey("edit any group_media:{$media_type_2->id()} in collabora", $permissions_group_2); + $this->assertArrayHasKey("edit own group_media:{$media_type_2->id()} in collabora", $permissions_group_2); + } + +} From aa891bbafc11213a509e3b03c4e730746d014084 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Mon, 18 Nov 2024 11:38:13 +0100 Subject: [PATCH 08/53] Issue CollaboraOnline/collabora-drupal#52: Replace config with view display modification. --- .../collabora_online_group.install | 51 +- .../override/views.view.group_media-3.yml | 1017 ----------------- .../override/views.view.group_media.yml | 758 ------------ 3 files changed, 37 insertions(+), 1789 deletions(-) delete mode 100644 modules/collabora_online_group/config/override/views.view.group_media-3.yml delete mode 100644 modules/collabora_online_group/config/override/views.view.group_media.yml diff --git a/modules/collabora_online_group/collabora_online_group.install b/modules/collabora_online_group/collabora_online_group.install index 04f14000..ae540a8d 100644 --- a/modules/collabora_online_group/collabora_online_group.install +++ b/modules/collabora_online_group/collabora_online_group.install @@ -1,6 +1,6 @@ moduleExists('views') && - \Drupal::entityTypeManager()->getStorage('view')->load('group_media') + $view = View::load('group_media') ) { - // Update view with module configuration. - $name = 'views.view.group_media'; - - // Fallback for older versions. - if (\Drupal::entityTypeManager()->getDefinition('group_relationship_type', FALSE) === NULL) { - $name = 'views.view.group_media-3'; + // Load display and apply changes. + $display = &$view->getDisplay('default'); + if ($display === NULL) { + return; } - $module_path = Drupal::moduleHandler()->getModule('collabora_online_group')->getPath(); - $source = new FileStorage($module_path . '/config/override'); - /** @var \Drupal\Core\Config\StorageInterface $active_storage */ - $active_storage = \Drupal::service('config.storage'); - $config = $source->read( $name); - $active_storage->write('views.view.group_media', $config); + // Add new fields to the display. + $display['display_options']['fields'] += [ + 'collabora_preview' => [ + 'id' => 'collabora_preview', + 'table' => 'media', + 'field'=> 'collabora_preview', + 'plugin_id' => 'media_collabora_preview', + 'label' => '', + 'exclude' => TRUE, + 'text' => t('Preview in Collabora'), + ]]; + $display['display_options']['fields'] += [ + 'collabora_edit' => [ + 'id' => 'collabora_edit', + 'table' => 'media', + 'field'=> 'collabora_edit', + 'plugin_id' => 'media_collabora_edit', + 'label' => '', + 'exclude' => TRUE, + 'text' => t('Edit in Collabora'), + ]]; + // Add new fields as options for the dropbutton and move the element to the end. + $dropbutton = $display['display_options']['fields']['dropbutton']; + $dropbutton['fields'] += [ + 'collabora_preview' => 'collabora_preview', + 'collabora_edit' => 'collabora_edit', + ]; + unset($display['display_options']['fields']['dropbutton']); + $display['display_options']['fields']['dropbutton'] = $dropbutton; + + $view->save(); } } diff --git a/modules/collabora_online_group/config/override/views.view.group_media-3.yml b/modules/collabora_online_group/config/override/views.view.group_media-3.yml deleted file mode 100644 index 4bed5cad..00000000 --- a/modules/collabora_online_group/config/override/views.view.group_media-3.yml +++ /dev/null @@ -1,1017 +0,0 @@ -uuid: null -langcode: en -status: true -dependencies: - module: - - collabora_online - - group - - media - enforced: - module: - - groupmedia -id: group_media -label: 'Group Media' -module: views -description: '' -tag: '' -base_table: media_field_data -base_field: mid -display: - default: - id: default - display_title: Master - display_plugin: default - position: 0 - display_options: - title: 'Group Media' - fields: - name: - id: name - table: media_field_data - field: name - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: media - plugin_id: field - label: 'Media name' - exclude: false - alter: - alter_text: false - make_link: false - absolute: false - word_boundary: false - ellipsis: false - strip_tags: false - trim: false - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: value - type: string - settings: - link_to_entity: true - group_column: value - group_columns: {} - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - bundle: - id: bundle - table: media_field_data - field: bundle - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: bundle - plugin_id: field - label: Bundle - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: target_id - type: entity_reference_label - settings: - link: false - group_column: target_id - group_columns: {} - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - status: - id: status - table: media_field_data - field: status - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: status - plugin_id: field - label: Status - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: value - type: boolean - settings: - format: yes-no - format_custom_false: '' - format_custom_true: '' - group_column: value - group_columns: {} - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - uid: - id: uid - table: media_field_data - field: uid - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: uid - plugin_id: field - label: Publisher - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: target_id - type: entity_reference_label - settings: - link: false - group_column: target_id - group_columns: {} - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - view_group_content: - id: view_group_content - table: group_relationship - field: view_group_content - relationship: group_content - group_type: group - admin_label: '' - entity_type: group_content - plugin_id: entity_link - label: 'View relation link' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: 'View relation' - output_url_as_text: false - absolute: false - edit_group_content: - id: edit_group_content - table: group_relationship - field: edit_group_content - relationship: group_content - group_type: group - admin_label: '' - entity_type: group_content - plugin_id: entity_link_edit - label: 'Edit relation link' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: 'Edit relation' - delete_group_content: - id: delete_group_content - table: group_relationship - field: delete_group_content - relationship: group_content - group_type: group - admin_label: '' - entity_type: group_content - plugin_id: entity_link_delete - label: 'Delete relation link' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: 'Delete relation' - collabora_preview: - id: collabora_preview - table: media - field: collabora_preview - relationship: none - group_type: group - admin_label: '' - entity_type: media - plugin_id: media_collabora_preview - label: '' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: false - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: 'Preview in Collabora' - collabora_edit: - id: collabora_edit - table: media - field: collabora_edit - relationship: none - group_type: group - admin_label: '' - entity_type: media - plugin_id: media_collabora_edit - label: '' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: false - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: 'Edit in Collabora' - edit_media: - id: edit_media - table: media - field: edit_media - relationship: none - group_type: group - admin_label: '' - entity_type: media - plugin_id: entity_link_edit - label: 'Edit media' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: Edit - delete_media: - id: delete_media - table: media - field: delete_media - relationship: none - group_type: group - admin_label: '' - entity_type: media - plugin_id: entity_link_delete - label: 'Delete Media' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: Delete - dropbutton: - id: dropbutton - table: views - field: dropbutton - relationship: none - group_type: group - admin_label: '' - plugin_id: dropbutton - label: Operations - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - destination: true - fields: - view_group_content: view_group_content - edit_group_content: edit_group_content - delete_group_content: delete_group_content - collabora_preview: collabora_preview - collabora_edit: collabora_edit - edit_media: edit_media - delete_media: delete_media - name: '0' - bundle: '0' - status: '0' - uid: '0' - pager: - type: mini - options: - offset: 0 - pagination_heading_level: h4 - items_per_page: 50 - total_pages: null - id: 0 - tags: - next: ›› - previous: ‹‹ - expose: - items_per_page: false - items_per_page_label: 'Items per page' - items_per_page_options: '5, 10, 25, 50' - items_per_page_options_all: false - items_per_page_options_all_label: '- All -' - offset: false - offset_label: Offset - exposed_form: - type: basic - options: - submit_button: Apply - reset_button: false - reset_button_label: Reset - exposed_sorts_label: 'Sort by' - expose_sort_order: true - sort_asc_label: Asc - sort_desc_label: Desc - access: - type: group_permission - options: - group_permission: 'access group_media overview' - cache: - type: tag - options: {} - empty: {} - sorts: {} - arguments: - gid: - id: gid - table: group_relationship_field_data - field: gid - relationship: group_content - group_type: group - admin_label: '' - entity_type: group_content - entity_field: gid - plugin_id: group_id - default_action: ignore - exception: - value: all - title_enable: false - title: All - title_enable: true - title: '{{ arguments.gid|placeholder }} media items' - default_argument_type: fixed - default_argument_options: - argument: '' - summary_options: - base_path: '' - count: true - override: false - items_per_page: 25 - summary: - sort_order: asc - number_of_records: 0 - format: default_summary - specify_validation: false - validate: - type: none - fail: 'not found' - validate_options: {} - break_phrase: false - not: false - filters: - status: - id: status - table: media_field_data - field: status - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: status - plugin_id: boolean - operator: '=' - value: '1' - group: 1 - exposed: true - expose: - operator_id: '' - label: Status - description: null - use_operator: false - operator: status_op - identifier: status - required: true - remember: false - multiple: false - remember_roles: - authenticated: authenticated - is_grouped: true - group_info: - label: Status - description: '' - identifier: status - optional: true - widget: select - multiple: false - remember: false - default_group: All - default_group_multiple: {} - group_items: - 1: - title: Published - operator: '=' - value: '1' - 2: - title: Unpublished - operator: '=' - value: '0' - bundle: - id: bundle - table: media_field_data - field: bundle - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: bundle - plugin_id: bundle - operator: in - value: {} - group: 1 - exposed: true - expose: - operator_id: bundle_op - label: 'Media type' - description: '' - use_operator: false - operator: bundle_op - identifier: bundle - required: false - remember: false - multiple: false - remember_roles: - authenticated: authenticated - anonymous: '0' - administrator: '0' - reduce: false - is_grouped: false - group_info: - label: '' - description: '' - identifier: '' - optional: true - widget: select - multiple: false - remember: false - default_group: All - default_group_multiple: {} - group_items: {} - style: - type: table - options: - grouping: {} - row_class: '' - default_row_class: true - columns: - name: name - bundle: bundle - status: status - uid: uid - view_group_content: view_group_content - edit_group_content: edit_group_content - delete_group_content: delete_group_content - edit_media: edit_media - delete_media: delete_media - dropbutton: dropbutton - default: '-1' - info: - name: - sortable: true - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - bundle: - sortable: true - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - status: - sortable: true - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - uid: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - view_group_content: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - edit_group_content: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - delete_group_content: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - edit_media: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - delete_media: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - dropbutton: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - override: true - sticky: false - summary: '' - empty_table: false - caption: '' - description: '' - row: - type: fields - query: - type: views_query - options: - query_comment: '' - disable_sql_rewrite: false - distinct: false - replica: false - query_tags: {} - relationships: - group_content: - id: group_content - table: media_field_data - field: group_content - relationship: none - group_type: group - admin_label: 'Media group content' - entity_type: media - plugin_id: group_content_to_entity_reverse - required: false - group_content_plugins: - 'group_media:audio': '0' - 'group_media:file': '0' - 'group_media:image': '0' - 'group_media:remote_video': '0' - 'group_media:video': '0' - header: {} - footer: {} - display_extenders: {} - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - route.group - - url - - url.query_args - - user.group_permissions - tags: {} - page_1: - id: page_1 - display_title: Page - display_plugin: page - position: 1 - display_options: - display_extenders: {} - path: group/%group/media - menu: - type: tab - title: Media - description: '' - weight: 0 - expanded: false - menu_name: main - parent: '' - context: '0' - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - route.group - - url - - url.query_args - - user.group_permissions - tags: {} diff --git a/modules/collabora_online_group/config/override/views.view.group_media.yml b/modules/collabora_online_group/config/override/views.view.group_media.yml deleted file mode 100644 index 0db5c082..00000000 --- a/modules/collabora_online_group/config/override/views.view.group_media.yml +++ /dev/null @@ -1,758 +0,0 @@ -status: true -dependencies: - module: - - collabora_online - - group - - media - enforced: - module: - - groupmedia -id: group_media -label: 'Group Media' -module: views -description: '' -tag: '' -base_table: media_field_data -base_field: mid -display: - default: - display_plugin: default - id: default - display_title: Master - position: 0 - display_options: - title: 'Group Media' - fields: - name: - id: name - table: media_field_data - field: name - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: media - plugin_id: field - label: 'Media name' - exclude: false - alter: - alter_text: false - make_link: false - absolute: false - word_boundary: false - ellipsis: false - strip_tags: false - trim: false - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: value - type: string - settings: - link_to_entity: true - group_column: value - group_columns: {} - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - bundle: - id: bundle - table: media_field_data - field: bundle - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: bundle - plugin_id: field - label: Bundle - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: target_id - type: entity_reference_label - settings: - link: false - group_column: target_id - group_columns: {} - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - status: - id: status - table: media_field_data - field: status - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: status - plugin_id: field - label: Status - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: value - type: boolean - settings: - format: yes-no - format_custom_false: '' - format_custom_true: '' - group_column: value - group_columns: {} - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - uid: - id: uid - table: media_field_data - field: uid - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: uid - plugin_id: field - label: Publisher - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: target_id - type: entity_reference_label - settings: - link: false - group_column: target_id - group_columns: {} - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - collabora_preview: - id: collabora_preview - table: media - field: collabora_preview - relationship: none - group_type: group - admin_label: '' - entity_type: media - plugin_id: media_collabora_preview - label: '' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: false - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: 'Preview in Collabora' - collabora_edit: - id: collabora_edit - table: media - field: collabora_edit - relationship: none - group_type: group - admin_label: '' - entity_type: media - plugin_id: media_collabora_edit - label: '' - exclude: true - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: false - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: 'Edit in Collabora' - dropbutton: - id: dropbutton - table: views - field: dropbutton - relationship: none - group_type: group - admin_label: '' - plugin_id: dropbutton - label: Operations - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - destination: true - fields: - collabora_preview: collabora_preview - collabora_edit: collabora_edit - edit_media: edit_media - delete_media: delete_media - edit_group_relationship: edit_group_relationship - delete_group_relationship: delete_group_relationship - view_group_relationship: view_group_relationship - name: '0' - bundle: '0' - status: '0' - uid: '0' - pager: - type: mini - options: - offset: 0 - items_per_page: 50 - total_pages: null - id: 0 - tags: - next: ›› - previous: ‹‹ - expose: - items_per_page: false - items_per_page_label: 'Items per page' - items_per_page_options: '5, 10, 25, 50' - items_per_page_options_all: false - items_per_page_options_all_label: '- All -' - offset: false - offset_label: Offset - exposed_form: - type: basic - options: - submit_button: Apply - reset_button: false - reset_button_label: Reset - exposed_sorts_label: 'Sort by' - expose_sort_order: true - sort_asc_label: Asc - sort_desc_label: Desc - access: - type: group_permission - options: - group_permission: 'access group_media overview' - cache: - type: tag - options: {} - empty: {} - sorts: {} - arguments: - gid: - id: gid - table: group_relationship_field_data - field: gid - relationship: group_relationship - group_type: group - admin_label: '' - entity_type: group_relationship - entity_field: gid - plugin_id: group_id - default_action: ignore - exception: - value: all - title_enable: false - title: All - title_enable: true - title: '{{ arguments.gid|placeholder }} media items' - default_argument_type: fixed - default_argument_options: - argument: '' - default_argument_skip_url: false - summary_options: - base_path: '' - count: true - override: false - items_per_page: 25 - summary: - sort_order: asc - number_of_records: 0 - format: default_summary - specify_validation: false - validate: - type: none - fail: 'not found' - validate_options: {} - break_phrase: false - not: false - filters: - status: - id: status - table: media_field_data - field: status - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: status - plugin_id: boolean - operator: '=' - value: '1' - group: 1 - exposed: true - expose: - operator_id: '' - label: Status - description: null - use_operator: false - operator: status_op - identifier: status - required: true - remember: false - multiple: false - remember_roles: - authenticated: authenticated - is_grouped: true - group_info: - label: Status - description: '' - identifier: status - optional: true - widget: select - multiple: false - remember: false - default_group: All - default_group_multiple: {} - group_items: - 1: - title: Published - operator: '=' - value: '1' - 2: - title: Unpublished - operator: '=' - value: '0' - bundle: - id: bundle - table: media_field_data - field: bundle - relationship: none - group_type: group - admin_label: '' - entity_type: media - entity_field: bundle - plugin_id: bundle - operator: in - value: {} - group: 1 - exposed: true - expose: - operator_id: bundle_op - label: 'Media type' - description: '' - use_operator: false - operator: bundle_op - identifier: bundle - required: false - remember: false - multiple: false - remember_roles: - authenticated: authenticated - anonymous: '0' - administrator: '0' - reduce: false - is_grouped: false - group_info: - label: '' - description: '' - identifier: '' - optional: true - widget: select - multiple: false - remember: false - default_group: All - default_group_multiple: {} - group_items: {} - style: - type: table - options: - grouping: {} - row_class: '' - default_row_class: true - columns: - name: name - bundle: bundle - status: status - uid: uid - view_group_content: view_group_content - edit_group_content: edit_group_content - delete_group_content: delete_group_content - edit_media: edit_media - delete_media: delete_media - dropbutton: dropbutton - default: '-1' - info: - name: - sortable: true - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - bundle: - sortable: true - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - status: - sortable: true - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - uid: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - view_group_content: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - edit_group_content: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - delete_group_content: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - edit_media: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - delete_media: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - dropbutton: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - override: true - sticky: false - summary: '' - empty_table: false - caption: '' - description: '' - row: - type: fields - query: - type: views_query - options: - query_comment: '' - disable_sql_rewrite: false - distinct: false - replica: false - query_tags: {} - relationships: - group_relationship: - id: group_relationship - table: media_field_data - field: group_relationship - relationship: none - group_type: group - admin_label: 'Media group relationship' - entity_type: media - plugin_id: group_relationship_to_entity_reverse - required: false - group_relation_plugins: - 'group_media:audio': '0' - 'group_media:document': '0' - 'group_media:image': '0' - 'group_media:remote_video': '0' - 'group_media:video': '0' - header: {} - footer: {} - display_extenders: {} - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - route.group - - url - - url.query_args - - user.group_permissions - tags: {} - page_1: - id: page_1 - display_title: Page - display_plugin: page - position: 1 - display_options: - display_extenders: {} - path: group/%group/media - menu: - type: tab - title: Media - description: '' - weight: 0 - expanded: false - menu_name: main - parent: '' - context: '0' - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - route.group - - url - - url.query_args - - user.group_permissions - tags: {} From 8e88ed0d624a66b41b9d8e14537c99c8c3a9d0ba Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 8 Nov 2024 13:42:41 +0100 Subject: [PATCH 09/53] Issue CollaboraOnline/collabora-drupal#52: Add title content check. --- .../tests/src/Kernel/PermissionTest.php | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php index 599fd9a3..0cb0dbfe 100644 --- a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -32,6 +32,7 @@ public function testGroupPermissions(): void { // Generate types: group and media. $group_type_1 = $this->createGroupType(); $group_type_2 = $this->createGroupType(); + $group_type_3 = $this->createGroupType(); $media_type_1 = $this->createMediaType('file'); $media_type_2 = $this->createMediaType('file'); @@ -61,20 +62,41 @@ public function testGroupPermissions(): void { // Check that permissions are generated for the groups. // The 'group_1' has only 'media_type_1' permissions. $permissions_group_1 = \Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_1); - $this->assertArrayHasKey("preview group_media:{$media_type_1->id()} in collabora", $permissions_group_1); - $this->assertArrayHasKey("edit any group_media:{$media_type_1->id()} in collabora", $permissions_group_1); - $this->assertArrayHasKey("edit own group_media:{$media_type_1->id()} in collabora", $permissions_group_1); - $this->assertArrayNotHasKey("preview group_media:{$media_type_2->id()} in collabora", $permissions_group_1); - $this->assertArrayNotHasKey("edit any group_media:{$media_type_2->id()} in collabora", $permissions_group_1); - $this->assertArrayNotHasKey("edit own group_media:{$media_type_2->id()} in collabora", $permissions_group_1); + $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_1); + $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_1, FALSE); // The 'group_2' has 'media_type_1' and 'media_type_2' permissions. $permissions_group_2 = \Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_2); - $this->assertArrayHasKey("preview group_media:{$media_type_1->id()} in collabora", $permissions_group_1); - $this->assertArrayHasKey("edit any group_media:{$media_type_1->id()} in collabora", $permissions_group_1); - $this->assertArrayHasKey("edit own group_media:{$media_type_1->id()} in collabora", $permissions_group_1); - $this->assertArrayHasKey("preview group_media:{$media_type_2->id()} in collabora", $permissions_group_2); - $this->assertArrayHasKey("edit any group_media:{$media_type_2->id()} in collabora", $permissions_group_2); - $this->assertArrayHasKey("edit own group_media:{$media_type_2->id()} in collabora", $permissions_group_2); + $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_2); + $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_2); + // The 'group_3' doesn't have any permission. + $permissions_group_3 = \Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_3); + $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_3, FALSE); + $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_3, FALSE); } + /** + * Asserts that collabora permissions are present or not in a given array. + * + * @param string $id + * The entity ID. + * @param array $permissions + * The permission where to perform the checks. + * @param bool $enabled + * If the permissions are enabled. + */ + protected function assertCollaboraPermissions(string $id, array $permissions, bool $enabled = TRUE): void { + $expected_permissions = [ + "preview $id in collabora" => "Entity: Preview media item in collabora", + "edit any $id in collabora" => "Entity: Edit any media item in collabora", + "edit own $id in collabora" => "Entity: Edit own media item in collabora", + ]; + + foreach($expected_permissions as $name => $description) { + if ($enabled === FALSE) { + $this->assertArrayNotHasKey($name, $permissions); + continue; + } + $this->assertEquals($description, $permissions[$name]['title']); + } + } } From b1a189b0a382254bcf87e371a6214efccc0fdaac Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Mon, 18 Nov 2024 12:02:52 +0100 Subject: [PATCH 10/53] Issue CollaboraOnline/collabora-drupal#52: Supoprt for different versions in test. --- .../tests/src/Functional/ViewTest.php | 3 ++- .../tests/src/Traits/GroupRelationTrait.php | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Functional/ViewTest.php b/modules/collabora_online_group/tests/src/Functional/ViewTest.php index 58f75b2f..834ecb9d 100644 --- a/modules/collabora_online_group/tests/src/Functional/ViewTest.php +++ b/modules/collabora_online_group/tests/src/Functional/ViewTest.php @@ -92,7 +92,8 @@ public function testViewLinks(): void { $this->assertEquals('Bundle', $cols[1]->getText()); $this->assertEquals('Status', $cols[2]->getText()); $this->assertEquals('Publisher', $cols[3]->getText()); - $this->assertEquals('Operations', $cols[4]->getText()); + // Support for different vesrions of groupmedia. + $this->assertEquals($this->isGroupRelationShipType() ? 'Operations' : 'Dropbutton', $cols[4]->getText()); // Check that rows contain new links for operations in Collabora. $table_body = $assert_session->elementExists('css', 'tbody', $table); diff --git a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php index 807353bf..c3f6c7e6 100644 --- a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php +++ b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php @@ -31,7 +31,7 @@ protected function createPluginRelation(GroupTypeInterface $group_type, string $ $entity_type_id = 'group_relationship_type'; // Fallback for older versions. - if ($this->entityTypeManager()->getDefinition($entity_type_id, FALSE) === NULL) { + if (!$this->isGroupRelationShipType()) { $entity_type_id = 'group_content_type'; } @@ -43,4 +43,14 @@ protected function createPluginRelation(GroupTypeInterface $group_type, string $ return $entity; } + /** + * Checks if 'group_relationship_type' group type entity exists. + * + * @return bool + * If the entity type exists. + */ + protected function isGroupRelationshipType(): bool { + return ($this->entityTypeManager()->getDefinition('group_relationship_type', FALSE) !== NULL); + } + } From 0bf076ffa62ad74e0f4d3ac17d07e69ebb8eb4a0 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 8 Nov 2024 15:11:05 +0100 Subject: [PATCH 11/53] Issue CollaboraOnline/collabora-drupal#52: Permission count check. --- .../tests/src/Kernel/PermissionTest.php | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php index 0cb0dbfe..39a31a17 100644 --- a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\collabora_online_group\Kernel; +use Drupal\Component\DependencyInjection\Container; use Drupal\Tests\group\Kernel\GroupKernelTestBase; use Drupal\Tests\media\Traits\MediaTypeCreationTrait; @@ -22,7 +23,6 @@ class PermissionTest extends GroupKernelTestBase { 'media', 'group', 'groupmedia', - 'collabora_online_group', ]; /** @@ -60,18 +60,30 @@ public function testGroupPermissions(): void { ->save(); // Check that permissions are generated for the groups. + // Save current permissions count for each group. + $permissions_handler = \Drupal::service('group.permissions'); + $count_group_1 = count($permissions_handler->getPermissionsByGroupType($group_type_1)); + $count_group_2 = count($permissions_handler->getPermissionsByGroupType($group_type_2)); + $count_group_3 = count($permissions_handler->getPermissionsByGroupType($group_type_3)); + + // Check collabora permissions in each group. + $this->enableModules(['collabora_online_group']); // The 'group_1' has only 'media_type_1' permissions. + drupal_static_reset(); $permissions_group_1 = \Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_1); $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_1); $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_1, FALSE); + $this->assertCount($count_group_1 + 3, $permissions_group_1); // The 'group_2' has 'media_type_1' and 'media_type_2' permissions. - $permissions_group_2 = \Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_2); + $permissions_group_2 = $permissions_handler->getPermissionsByGroupType($group_type_2); $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_2); $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_2); - // The 'group_3' doesn't have any permission. - $permissions_group_3 = \Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_3); + $this->assertCount($count_group_2 + 6, $permissions_group_2); + // The 'group_3' doesn't have any new permissions. + $permissions_group_3 = $permissions_handler->getPermissionsByGroupType($group_type_3); $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_3, FALSE); $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_3, FALSE); + $this->assertCount($count_group_3, $permissions_group_3); } /** From 3364c1f0a2046dd130ffa1233a2fc428a5a2198c Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 19 Nov 2024 16:22:32 +0100 Subject: [PATCH 12/53] Issue CollaboraOnline/collabora-drupal#52: Code formatting and documentation fixes. --- collabora_online.views.inc | 8 +- .../collabora_online_group.install | 20 ++-- .../tests/src/Functional/ViewTest.php | 8 +- .../tests/src/Traits/GroupRelationTrait.php | 2 +- src/Plugin/views/field/CollaboraEdit.php | 2 +- src/Plugin/views/field/CollaboraPreview.php | 4 +- tests/src/Kernel/ViewsLinkFieldsTest.php | 95 ++++++++++--------- 7 files changed, 74 insertions(+), 65 deletions(-) diff --git a/collabora_online.views.inc b/collabora_online.views.inc index 956ca91c..18d0e7e6 100644 --- a/collabora_online.views.inc +++ b/collabora_online.views.inc @@ -6,18 +6,18 @@ declare(strict_types=1); * Implements hook_views_data_alter(). */ function collabora_online_views_data_alter(array &$data): void { - $data['media']['collabora_preview'] = [ + $data['media']['collabora_preview'] = [ 'title' => t('Preview operation in collabora'), 'group' => t('Media'), - 'field' => [ + 'field' => [ 'title' => t('Media preview in collabora'), 'id' => 'media_collabora_preview', ], ]; - $data['media']['collabora_edit'] = [ + $data['media']['collabora_edit'] = [ 'title' => t('Edit operation in collabora'), 'group' => t('Media'), - 'field' => [ + 'field' => [ 'title' => t('Media edit in collabora'), 'id' => 'media_collabora_edit', ], diff --git a/modules/collabora_online_group/collabora_online_group.install b/modules/collabora_online_group/collabora_online_group.install index ae540a8d..0a506c1f 100644 --- a/modules/collabora_online_group/collabora_online_group.install +++ b/modules/collabora_online_group/collabora_online_group.install @@ -21,22 +21,22 @@ function collabora_online_group_install(): void { 'collabora_preview' => [ 'id' => 'collabora_preview', 'table' => 'media', - 'field'=> 'collabora_preview', + 'field' => 'collabora_preview', 'plugin_id' => 'media_collabora_preview', 'label' => '', 'exclude' => TRUE, 'text' => t('Preview in Collabora'), - ]]; + ]]; $display['display_options']['fields'] += [ 'collabora_edit' => [ - 'id' => 'collabora_edit', - 'table' => 'media', - 'field'=> 'collabora_edit', - 'plugin_id' => 'media_collabora_edit', - 'label' => '', - 'exclude' => TRUE, - 'text' => t('Edit in Collabora'), - ]]; + 'id' => 'collabora_edit', + 'table' => 'media', + 'field' => 'collabora_edit', + 'plugin_id' => 'media_collabora_edit', + 'label' => '', + 'exclude' => TRUE, + 'text' => t('Edit in Collabora'), + ]]; // Add new fields as options for the dropbutton and move the element to the end. $dropbutton = $display['display_options']['fields']['dropbutton']; $dropbutton['fields'] += [ diff --git a/modules/collabora_online_group/tests/src/Functional/ViewTest.php b/modules/collabora_online_group/tests/src/Functional/ViewTest.php index 834ecb9d..07491943 100644 --- a/modules/collabora_online_group/tests/src/Functional/ViewTest.php +++ b/modules/collabora_online_group/tests/src/Functional/ViewTest.php @@ -54,7 +54,7 @@ public function testViewLinks(): void { 'view group_media:document entity', 'edit any group_media:document in collabora', 'preview group_media:document in collabora', - ], + ], ]); $this->createPluginRelation($group_type, 'group_media:document', [ 'group_cardinality' => 0, @@ -64,7 +64,7 @@ public function testViewLinks(): void { // Create content. $group = $this->createGroup(['type' => 'group_type_1']); - for ($i = 1;$i < 4;$i++) { + for ($i = 1; $i < 4; $i++) { $media = $this->createMediaEntity('document', [ 'id' => 'media_' . $i, 'name' => 'Media ' . $i, @@ -93,13 +93,13 @@ public function testViewLinks(): void { $this->assertEquals('Status', $cols[2]->getText()); $this->assertEquals('Publisher', $cols[3]->getText()); // Support for different vesrions of groupmedia. - $this->assertEquals($this->isGroupRelationShipType() ? 'Operations' : 'Dropbutton', $cols[4]->getText()); + $this->assertEquals($this->isGroupRelationshipType() ? 'Operations' : 'Dropbutton', $cols[4]->getText()); // Check that rows contain new links for operations in Collabora. $table_body = $assert_session->elementExists('css', 'tbody', $table); $rows = $table_body->findAll('css', 'tr'); $i = 0; - foreach(Media::loadMultiple() as $media) { + foreach (Media::loadMultiple() as $media) { $cols = $rows[$i]->findAll('css', 'td'); $this->assertEquals($media->getName(), $cols[0]->getText()); $this->assertEquals($media_type->label(), $cols[1]->getText()); diff --git a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php index c3f6c7e6..69e380e6 100644 --- a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php +++ b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php @@ -31,7 +31,7 @@ protected function createPluginRelation(GroupTypeInterface $group_type, string $ $entity_type_id = 'group_relationship_type'; // Fallback for older versions. - if (!$this->isGroupRelationShipType()) { + if (!$this->isGroupRelationshipType()) { $entity_type_id = 'group_content_type'; } diff --git a/src/Plugin/views/field/CollaboraEdit.php b/src/Plugin/views/field/CollaboraEdit.php index 26add133..420cb287 100644 --- a/src/Plugin/views/field/CollaboraEdit.php +++ b/src/Plugin/views/field/CollaboraEdit.php @@ -18,7 +18,7 @@ */ class CollaboraEdit extends LinkBase { - protected function getUrlInfo(ResultRow $row): Url|NULL { + protected function getUrlInfo(ResultRow $row): Url|null { /** @var \Drupal\media\MediaInterface $entity */ $entity = $this->getEntity($row); diff --git a/src/Plugin/views/field/CollaboraPreview.php b/src/Plugin/views/field/CollaboraPreview.php index 1b0e4cb3..ed0544c7 100644 --- a/src/Plugin/views/field/CollaboraPreview.php +++ b/src/Plugin/views/field/CollaboraPreview.php @@ -18,8 +18,8 @@ */ class CollaboraPreview extends LinkBase { - protected function getUrlInfo(ResultRow $row): Url|NULL { - /** @var \Drupal\media\MediaInterface $entity */ + protected function getUrlInfo(ResultRow $row): Url|null { + /** @var \Drupal\media\MediaInterface $entity */ $entity = $this->getEntity($row); if ($entity === NULL) { diff --git a/tests/src/Kernel/ViewsLinkFieldsTest.php b/tests/src/Kernel/ViewsLinkFieldsTest.php index 5ccdbf08..bdb4e42e 100644 --- a/tests/src/Kernel/ViewsLinkFieldsTest.php +++ b/tests/src/Kernel/ViewsLinkFieldsTest.php @@ -55,13 +55,14 @@ protected function setUp(): void { $this->installEntitySchema('user'); $this->installConfig(['user', 'views', 'collabora_online_test']); $this->installSchema('file', ['file_usage']); - // Install user module avoid user 1 permissions bypass. + // Install user module to avoid user 1 permissions bypass. \Drupal::moduleHandler()->loadInclude('user', 'install'); user_install(); // Create two medias to check access with different scopes, 'any' and 'own'. $this->createMediaEntity('document'); - $this->ownMedia = $this->createMediaEntity('document');; + $this->ownMedia = $this->createMediaEntity('document'); + ; } /** @@ -69,46 +70,54 @@ protected function setUp(): void { */ public function testLinks(): void { // User without permissions can't see links. - $this->doTestLinks([ - 'preview' => [FALSE, FALSE], - 'edit' => [FALSE, FALSE], - ], - $this->createUser([])); + $this->doTestLinks( + [ + 'preview' => [FALSE, FALSE], + 'edit' => [FALSE, FALSE], + ], + $this->createUser([]) + ); // User with 'Preview' permission can see preview link. - $this->doTestLinks([ - 'preview' => [TRUE, TRUE], - 'edit' => [FALSE, FALSE], - ], - $this->createUser([ - 'preview document in collabora' - ])); + $this->doTestLinks( + [ + 'preview' => [TRUE, TRUE], + 'edit' => [FALSE, FALSE], + ], + $this->createUser([ + 'preview document in collabora' + ]) + ); // User with 'Edit any' permission can see edit link. - $this->doTestLinks([ - 'preview' => [FALSE, FALSE], - 'edit' => [TRUE, TRUE], - ], - $this->createUser([ - 'edit any document in collabora' - ])); + $this->doTestLinks( + [ + 'preview' => [FALSE, FALSE], + 'edit' => [TRUE, TRUE], + ], + $this->createUser([ + 'edit any document in collabora' + ]) + ); // User with 'Edit own' permission can see edit link for entities they own. - $this->doTestLinks([ - 'preview' => [FALSE, FALSE], - 'edit' => [FALSE, TRUE], - ], - $this->createUser([ - 'edit own document in collabora' - ])); + $this->doTestLinks( + [ + 'preview' => [FALSE, FALSE], + 'edit' => [FALSE, TRUE], + ], + $this->createUser([ + 'edit own document in collabora' + ]) + ); } /** * Tests that links behave as expected. * - * @param [] $expected_results + * @param array $expected_results * An associative array of expected results keyed by operation. * @param \Drupal\Core\Session\AccountInterface $account - * The user account to be used to run the test; + * The user account to be used to run the test. */ - protected function doTestLinks(array $expected_results, AccountInterface $account) { + protected function doTestLinks(array $expected_results, AccountInterface $account): void { $this->setCurrentUser(account: $account); // Set the current user as the owner to check 'edit own' access. $this->ownMedia->setOwnerId($account->id())->save(); @@ -116,21 +125,21 @@ protected function doTestLinks(array $expected_results, AccountInterface $accoun $view->preview(); $info = [ - 'preview' => [ - 'label' => 'Preview in Collabora', - 'field_id' => 'collabora_preview', - 'route' => 'collabora-online.view' - ], - 'edit' => [ - 'label' => 'Edit in Collabora', - 'field_id' => 'collabora_edit', - 'route' => 'collabora-online.edit' - ], + 'preview' => [ + 'label' => 'Preview in Collabora', + 'field_id' => 'collabora_preview', + 'route' => 'collabora-online.view' + ], + 'edit' => [ + 'label' => 'Edit in Collabora', + 'field_id' => 'collabora_edit', + 'route' => 'collabora-online.edit' + ], ]; $i = 0; // Check each expected results for every media. - foreach(Media::loadMultiple() as $media) { + foreach (Media::loadMultiple() as $media) { foreach ($expected_results as $operation => $expected_result) { $expected_link = ''; // The operation array contains results for each of the entities. @@ -142,7 +151,7 @@ protected function doTestLinks(array $expected_results, AccountInterface $accoun $link = $view->style_plugin->getField($i, $info[$operation]['field_id']); $this->assertEquals($expected_link, (string) $link); } - $i++; + $i++; } } From 3cf6dcd169d350b80b3286728c3efd57d2127bb2 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 8 Nov 2024 15:41:17 +0100 Subject: [PATCH 13/53] Issue CollaboraOnline/collabora-drupal#52: Fix getPermissions method. --- .../CollaboraPermissionProvider.php | 4 +-- .../tests/src/Kernel/PermissionTest.php | 29 +++++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php index f89cbc45..431c7d0b 100644 --- a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php @@ -65,9 +65,7 @@ public function getPermission($operation, $target, $scope = 'any'): bool|string } } - // Since we are overriding decorated service method, we call the original - // method too. - return $this->groupMediaPermissionProvider->getPermission($operation, $target, $scope); + return $this->parent->getPermission($operation, $target, $scope); } /** diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php index 39a31a17..932dd1c8 100644 --- a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -4,7 +4,6 @@ namespace Drupal\Tests\collabora_online_group\Kernel; -use Drupal\Component\DependencyInjection\Container; use Drupal\Tests\group\Kernel\GroupKernelTestBase; use Drupal\Tests\media\Traits\MediaTypeCreationTrait; @@ -30,11 +29,11 @@ class PermissionTest extends GroupKernelTestBase { */ public function testGroupPermissions(): void { // Generate types: group and media. - $group_type_1 = $this->createGroupType(); - $group_type_2 = $this->createGroupType(); - $group_type_3 = $this->createGroupType(); - $media_type_1 = $this->createMediaType('file'); - $media_type_2 = $this->createMediaType('file'); + $group_type_1 = $this->createGroupType(['id' => 'group_1']); + $group_type_2 = $this->createGroupType(['id' => 'group_2']); + $group_type_3 = $this->createGroupType(['id' => 'group_3']); + $media_type_1 = $this->createMediaType('file', ['id' => 'media_1']); + $media_type_2 = $this->createMediaType('file', ['id' => 'media_2']); // Enable relation plugins in groups. $this->entityTypeManager()->getStorage('group_relationship_type') @@ -61,26 +60,26 @@ public function testGroupPermissions(): void { // Check that permissions are generated for the groups. // Save current permissions count for each group. - $permissions_handler = \Drupal::service('group.permissions'); - $count_group_1 = count($permissions_handler->getPermissionsByGroupType($group_type_1)); - $count_group_2 = count($permissions_handler->getPermissionsByGroupType($group_type_2)); - $count_group_3 = count($permissions_handler->getPermissionsByGroupType($group_type_3)); + $permission_handler = \Drupal::service('group.permissions'); + $count_group_1 = count(\Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_1)); + $count_group_2 = count(\Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_2)); + $count_group_3 = count(\Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_3)); // Check collabora permissions in each group. $this->enableModules(['collabora_online_group']); + $permission_handler = \Drupal::service('group.permissions'); // The 'group_1' has only 'media_type_1' permissions. - drupal_static_reset(); - $permissions_group_1 = \Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_1); + $permissions_group_1 = $permission_handler->getPermissionsByGroupType($group_type_1); $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_1); $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_1, FALSE); $this->assertCount($count_group_1 + 3, $permissions_group_1); // The 'group_2' has 'media_type_1' and 'media_type_2' permissions. - $permissions_group_2 = $permissions_handler->getPermissionsByGroupType($group_type_2); + $permissions_group_2 = $permission_handler->getPermissionsByGroupType($group_type_2); $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_2); $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_2); $this->assertCount($count_group_2 + 6, $permissions_group_2); // The 'group_3' doesn't have any new permissions. - $permissions_group_3 = $permissions_handler->getPermissionsByGroupType($group_type_3); + $permissions_group_3 = $permission_handler->getPermissionsByGroupType($group_type_3); $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_3, FALSE); $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_3, FALSE); $this->assertCount($count_group_3, $permissions_group_3); @@ -108,7 +107,7 @@ protected function assertCollaboraPermissions(string $id, array $permissions, bo $this->assertArrayNotHasKey($name, $permissions); continue; } - $this->assertEquals($description, $permissions[$name]['title']); + $this->assertEquals($description, $permissions[$name]['title']); } } } From 9b9cf1d7f3251e13d071ec7a67df8e95faff305e Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 19 Nov 2024 16:53:44 +0100 Subject: [PATCH 14/53] Issue CollaboraOnline/collabora-drupal#52: Change field label. --- collabora_online.views.inc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/collabora_online.views.inc b/collabora_online.views.inc index 18d0e7e6..fff2b5b6 100644 --- a/collabora_online.views.inc +++ b/collabora_online.views.inc @@ -7,18 +7,16 @@ declare(strict_types=1); */ function collabora_online_views_data_alter(array &$data): void { $data['media']['collabora_preview'] = [ - 'title' => t('Preview operation in collabora'), + 'title' => t('Link to preview in Collabora'), 'group' => t('Media'), 'field' => [ - 'title' => t('Media preview in collabora'), 'id' => 'media_collabora_preview', ], ]; $data['media']['collabora_edit'] = [ - 'title' => t('Edit operation in collabora'), + 'title' => t('Link to edit in Collabora'), 'group' => t('Media'), 'field' => [ - 'title' => t('Media edit in collabora'), 'id' => 'media_collabora_edit', ], ]; From 38fa60610a2bf112ce5f310d6bff513351e9695b Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 8 Nov 2024 18:50:06 +0100 Subject: [PATCH 15/53] Issue CollaboraOnline/collabora-drupal#52: Add access test. --- .../tests/src/Kernel/AccessTest.php | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 modules/collabora_online_group/tests/src/Kernel/AccessTest.php diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php new file mode 100644 index 00000000..d95f66bf --- /dev/null +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -0,0 +1,134 @@ +installEntitySchema('file'); + $this->installEntitySchema('media'); + $this->installEntitySchema('group_role'); + $this->installSchema('file', ['file_usage']); + } + + /** + * Tests that group permissions are properly created. + * @dataProvider dataProvider + */ + public function testCollaboraAccess(array $permissions, array $group_permissions, string $operation, bool $result): void { + // Create group type, media type and enable plugin. + $group_type = $this->createGroupType(); + $this->createGroupRole([ + 'group_type' => $group_type->id(), + 'scope' => PermissionScopeInterface::INSIDER_ID, + 'global_role' => RoleInterface::AUTHENTICATED_ID, + 'permissions' => $group_permissions + ]); + $this->createMediaType('file', ['id' => 'document']); + $this->entityTypeManager()->getStorage('group_relationship_type') + ->createFromPlugin($group_type, 'group_media:document', [ + 'group_cardinality' => 0, + 'entity_cardinality' => 1, + 'use_creation_wizard' => FALSE, + ]) + ->save(); + + // Add group, media and relation between both.. + $group = $this->createGroup(['type' => $group_type->id()]); + $media = $this->createMediaEntity('document'); + $group->addRelationship($media, 'group_media:document'); + + // Create the user with the given permissions and as member of the group. + $user = $this->createUser($permissions); + $group->addMember($user); + + // Check access. + $this->assertEquals($result, $media->access($operation, $user)); + } + + /** + * Data provider for File defaults by type widget. + * + * @return \Generator + * The test data. + */ + protected function dataProvider(): \Generator { + // User with no permissions at all. + yield [ + [], + [], + 'preview in collabora', + FALSE + ]; + yield [ + [], + [ + 'preview group_media:document in collabora' + ], + 'preview in collabora', + TRUE + ]; + } + + /** + * Creates a media entity with attached file. + * + * @param string $type + * Media type. + * @param array $values + * Values for the media entity. + * + * @return \Drupal\media\MediaInterface + * New media entity. + */ + protected function createMediaEntity(string $type, array $values = []): MediaInterface { + file_put_contents('public://test.txt', 'Hello test'); + $file = File::create([ + 'uri' => 'public://test.txt', + ]); + $file->save(); + $values += [ + 'bundle' => $type, + 'field_media_file' => $file->id(), + ]; + $media = Media::create($values); + $media->save(); + return $media; + } + +} From 9a714f9636f367108f5daabee4655d35a021fd57 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 19 Nov 2024 17:39:29 +0100 Subject: [PATCH 16/53] Issue CollaboraOnline/collabora-drupal#52: Early return for module isntall. --- .../collabora_online_group.install | 78 ++++++++++--------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/modules/collabora_online_group/collabora_online_group.install b/modules/collabora_online_group/collabora_online_group.install index 0a506c1f..03092a7d 100644 --- a/modules/collabora_online_group/collabora_online_group.install +++ b/modules/collabora_online_group/collabora_online_group.install @@ -7,45 +7,47 @@ use Drupal\views\Entity\View; */ function collabora_online_group_install(): void { if ( - \Drupal::moduleHandler()->moduleExists('views') && - $view = View::load('group_media') + !\Drupal::moduleHandler()->moduleExists('views') || + !($view = View::load('group_media')) ) { - // Load display and apply changes. - $display = &$view->getDisplay('default'); - if ($display === NULL) { - return; - } - - // Add new fields to the display. - $display['display_options']['fields'] += [ - 'collabora_preview' => [ - 'id' => 'collabora_preview', - 'table' => 'media', - 'field' => 'collabora_preview', - 'plugin_id' => 'media_collabora_preview', - 'label' => '', - 'exclude' => TRUE, - 'text' => t('Preview in Collabora'), - ]]; - $display['display_options']['fields'] += [ - 'collabora_edit' => [ - 'id' => 'collabora_edit', - 'table' => 'media', - 'field' => 'collabora_edit', - 'plugin_id' => 'media_collabora_edit', - 'label' => '', - 'exclude' => TRUE, - 'text' => t('Edit in Collabora'), - ]]; - // Add new fields as options for the dropbutton and move the element to the end. - $dropbutton = $display['display_options']['fields']['dropbutton']; - $dropbutton['fields'] += [ - 'collabora_preview' => 'collabora_preview', - 'collabora_edit' => 'collabora_edit', - ]; - unset($display['display_options']['fields']['dropbutton']); - $display['display_options']['fields']['dropbutton'] = $dropbutton; + return; + } - $view->save(); + // Load display and apply changes. + $display = &$view->getDisplay('default'); + if ($display === NULL) { + return; } + + // Add new fields to the display. + $display['display_options']['fields'] += [ + 'collabora_preview' => [ + 'id' => 'collabora_preview', + 'table' => 'media', + 'field' => 'collabora_preview', + 'plugin_id' => 'media_collabora_preview', + 'label' => '', + 'exclude' => TRUE, + 'text' => t('Preview in Collabora'), + ]]; + $display['display_options']['fields'] += [ + 'collabora_edit' => [ + 'id' => 'collabora_edit', + 'table' => 'media', + 'field' => 'collabora_edit', + 'plugin_id' => 'media_collabora_edit', + 'label' => '', + 'exclude' => TRUE, + 'text' => t('Edit in Collabora'), + ]]; + // Add new fields as options for the dropbutton and move the element to the end. + $dropbutton = $display['display_options']['fields']['dropbutton']; + $dropbutton['fields'] += [ + 'collabora_preview' => 'collabora_preview', + 'collabora_edit' => 'collabora_edit', + ]; + unset($display['display_options']['fields']['dropbutton']); + $display['display_options']['fields']['dropbutton'] = $dropbutton; + + $view->save(); } From d4cae2063f5ad6ff3c9d1078401920b865fe8005 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 22 Nov 2024 11:55:05 +0100 Subject: [PATCH 17/53] Issue CollaboraOnline/collabora-drupal#52: Add access test cases and refactoring. --- .../CollaboraPermissionProvider.php | 30 ++----- .../tests/src/Kernel/AccessTest.php | 82 ++++++++----------- .../tests/src/Kernel/PermissionTest.php | 16 ++-- tests/src/Traits/MediaCreationTrait.php | 45 ++++++++++ 4 files changed, 94 insertions(+), 79 deletions(-) create mode 100644 tests/src/Traits/MediaCreationTrait.php diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php index 431c7d0b..3451688c 100644 --- a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php @@ -8,7 +8,7 @@ use Drupal\group\Plugin\Group\RelationHandler\PermissionProviderInterface; /** - * Provides group permissions for Collabora. + * Provides Collabora permissions for group. */ class CollaboraPermissionProvider extends GroupMediaPermissionProvider { @@ -61,30 +61,18 @@ public function getPermission($operation, $target, $scope = 'any'): bool|string return "preview $this->pluginId in collabora"; case 'edit in collabora': - return $this->getCollaboraEditPermission($scope); + if ( + $this->definesEntityPermissions && + ($this->implementsOwnerInterface || $scope === 'any') + ) { + return "edit $scope $this->pluginId in collabora"; + } + + return FALSE; } } return $this->parent->getPermission($operation, $target, $scope); } - /** - * Gets the name of the edit permission in Collabora. - * - * @param string $scope - * (optional) Whether the 'any' or 'own' permission name should be returned. - * Defaults to 'any'. - * - * @return string|false - * The permission name or FALSE if it does not apply. - */ - protected function getCollaboraEditPermission($scope = 'any'): bool|string { - if ($this->definesEntityPermissions) { - if ($this->implementsOwnerInterface || $scope === 'any') { - return "edit $scope $this->pluginId in collabora"; - } - } - - return FALSE; - } } diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php index d95f66bf..2ffa8da4 100644 --- a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -4,22 +4,21 @@ namespace Drupal\Tests\collabora_online_group\Kernel; -use Drupal\file\Entity\File; use Drupal\group\PermissionScopeInterface; -use Drupal\media\Entity\Media; -use Drupal\media\MediaInterface; +use Drupal\Tests\collabora_online\Traits\MediaCreationTrait; use Drupal\Tests\group\Kernel\GroupKernelTestBase; use Drupal\Tests\media\Traits\MediaTypeCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\user\RoleInterface; /** - * Tests group permissions. + * Tests Collabora group access. */ class AccessTest extends GroupKernelTestBase { use MediaTypeCreationTrait; use UserCreationTrait; + use MediaCreationTrait; /** * {@inheritdoc} @@ -30,6 +29,7 @@ class AccessTest extends GroupKernelTestBase { 'image', 'group', 'groupmedia', + 'collabora_online', 'collabora_online_group', 'user' ]; @@ -47,10 +47,11 @@ protected function setUp(): void { } /** - * Tests that group permissions are properly created. + * Tests that access to Collabora group permissions is handled. + * * @dataProvider dataProvider */ - public function testCollaboraAccess(array $permissions, array $group_permissions, string $operation, bool $result): void { + public function testCollaboraAccess(bool $expected_result, array $permissions, array $group_permissions, string $operation, string $scope = ''): void { // Create group type, media type and enable plugin. $group_type = $this->createGroupType(); $this->createGroupRole([ @@ -68,7 +69,7 @@ public function testCollaboraAccess(array $permissions, array $group_permissions ]) ->save(); - // Add group, media and relation between both.. + // Add group, media and relation between both. $group = $this->createGroup(['type' => $group_type->id()]); $media = $this->createMediaEntity('document'); $group->addRelationship($media, 'group_media:document'); @@ -77,58 +78,39 @@ public function testCollaboraAccess(array $permissions, array $group_permissions $user = $this->createUser($permissions); $group->addMember($user); + if ($scope === 'own') { + $media->setOwnerId($user->id())->save(); + } + // Check access. - $this->assertEquals($result, $media->access($operation, $user)); + $this->assertEquals($expected_result, $media->access($operation, $user)); } /** - * Data provider for File defaults by type widget. + * Data provider. * * @return \Generator * The test data. */ protected function dataProvider(): \Generator { - // User with no permissions at all. - yield [ - [], - [], - 'preview in collabora', - FALSE - ]; - yield [ - [], - [ - 'preview group_media:document in collabora' - ], - 'preview in collabora', - TRUE - ]; + // Preview: user with no permissions at all. + yield [FALSE, [], [], 'preview in collabora']; + // Preview: user with global permissions doesn't have access. + yield [FALSE, ['preview document in collabora'], [], 'preview in collabora']; + // Preview: user with group permissions have access. + yield [TRUE, [], ['preview group_media:document in collabora'], 'preview in collabora']; + // Edit any: user with no permissions at all. + yield [FALSE, [], [], 'edit in collabora']; + // Edit any: user with global permissions doesn't have access. + yield [FALSE, ['edit any document in collabora'], [], 'edit in collabora']; + // Edit any: User with group permissions have access. + yield [TRUE, [], ['edit any group_media:document in collabora'], 'edit in collabora']; + // Edit own: user with no permissions at all. + yield [FALSE, [], [], 'edit in collabora', 'own']; + // Edit own: user with global permissions doesn't have access. + yield [FALSE, ['edit own document in collabora'], [], 'edit in collabora', 'own' ]; + // Edit own: user with group permissions have access. + yield [TRUE, [], ['edit own group_media:document in collabora'], 'edit in collabora', 'own']; } - /** - * Creates a media entity with attached file. - * - * @param string $type - * Media type. - * @param array $values - * Values for the media entity. - * - * @return \Drupal\media\MediaInterface - * New media entity. - */ - protected function createMediaEntity(string $type, array $values = []): MediaInterface { - file_put_contents('public://test.txt', 'Hello test'); - $file = File::create([ - 'uri' => 'public://test.txt', - ]); - $file->save(); - $values += [ - 'bundle' => $type, - 'field_media_file' => $file->id(), - ]; - $media = Media::create($values); - $media->save(); - return $media; - } - } diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php index 932dd1c8..39aff0ac 100644 --- a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -28,7 +28,7 @@ class PermissionTest extends GroupKernelTestBase { * Tests that group permissions are properly created. */ public function testGroupPermissions(): void { - // Generate types: group and media. + // Generate types: groups and medias. $group_type_1 = $this->createGroupType(['id' => 'group_1']); $group_type_2 = $this->createGroupType(['id' => 'group_2']); $group_type_3 = $this->createGroupType(['id' => 'group_3']); @@ -59,13 +59,13 @@ public function testGroupPermissions(): void { ->save(); // Check that permissions are generated for the groups. - // Save current permissions count for each group. + // Save current permissions count. $permission_handler = \Drupal::service('group.permissions'); - $count_group_1 = count(\Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_1)); - $count_group_2 = count(\Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_2)); - $count_group_3 = count(\Drupal::service('group.permissions')->getPermissionsByGroupType($group_type_3)); + $count_group_1 = count($permission_handler->getPermissionsByGroupType($group_type_1)); + $count_group_2 = count($permission_handler->getPermissionsByGroupType($group_type_2)); + $count_group_3 = count($permission_handler->getPermissionsByGroupType($group_type_3)); - // Check collabora permissions in each group. + // Check collabora permissions after enabling the module. $this->enableModules(['collabora_online_group']); $permission_handler = \Drupal::service('group.permissions'); // The 'group_1' has only 'media_type_1' permissions. @@ -86,12 +86,12 @@ public function testGroupPermissions(): void { } /** - * Asserts that collabora permissions are present or not in a given array. + * Asserts whether collaboration permissions are present in a given array. * * @param string $id * The entity ID. * @param array $permissions - * The permission where to perform the checks. + * The permission to check. * @param bool $enabled * If the permissions are enabled. */ diff --git a/tests/src/Traits/MediaCreationTrait.php b/tests/src/Traits/MediaCreationTrait.php new file mode 100644 index 00000000..a8e1d47e --- /dev/null +++ b/tests/src/Traits/MediaCreationTrait.php @@ -0,0 +1,45 @@ + 'public://test.txt', + ]); + $file->save(); + $values += [ + 'bundle' => $type, + 'field_media_file' => $file->id(), + ]; + $media = Media::create($values); + $media->save(); + + return $media; + } + +} From 38c61c3ec93e96a33f61c8f6ddff712319c1fc7d Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 19 Nov 2024 17:14:36 +0100 Subject: [PATCH 18/53] Issue CollaboraOnline/collabora-drupal#52: Module is syncing. --- modules/collabora_online_group/collabora_online_group.install | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/collabora_online_group/collabora_online_group.install b/modules/collabora_online_group/collabora_online_group.install index 03092a7d..7ae5919d 100644 --- a/modules/collabora_online_group/collabora_online_group.install +++ b/modules/collabora_online_group/collabora_online_group.install @@ -5,8 +5,9 @@ use Drupal\views\Entity\View; /** * Implements hook_install(). */ -function collabora_online_group_install(): void { +function collabora_online_group_install(bool $is_syncing): void { if ( + $is_syncing || !\Drupal::moduleHandler()->moduleExists('views') || !($view = View::load('group_media')) ) { From 0b09b47929e96d3a83d84391222b245ddf8f3117 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Mon, 11 Nov 2024 11:57:50 +0100 Subject: [PATCH 19/53] Issue CollaboraOnline/collabora-drupal#52: Remove unneeded service. --- .../collabora_online_group.services.yml | 6 +-- .../CollaboraAccessControl.php | 43 ------------------- .../CollaboraPermissionProvider.php | 15 ------- 3 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php diff --git a/modules/collabora_online_group/collabora_online_group.services.yml b/modules/collabora_online_group/collabora_online_group.services.yml index 7cb176b0..06b6737a 100644 --- a/modules/collabora_online_group/collabora_online_group.services.yml +++ b/modules/collabora_online_group/collabora_online_group.services.yml @@ -2,8 +2,4 @@ services: group.relation_handler.permission_provider.collabora_group_media: class: 'Drupal\collabora_online_group\Plugin\Group\RelationHandler\CollaboraPermissionProvider' decorates: group.relation_handler.permission_provider.group_media - arguments: [ '@group.relation_handler.permission_provider.collabora_group_media.inner', '@group.relation_handler.permission_provider' ] - - group.relation_handler.access_control.group_media: - class: 'Drupal\collabora_online_group\Plugin\Group\RelationHandler\CollaboraAccessControl' - arguments: ['@group.relation_handler.access_control'] + arguments: [ '@group.relation_handler.permission_provider.collabora_group_media.inner' ] diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php deleted file mode 100644 index 4dd7a168..00000000 --- a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php +++ /dev/null @@ -1,43 +0,0 @@ -parent = $parent; - } - - /** - * {@inheritdoc} - */ - public function supportsOperation($operation, $target): bool { - $allowed_operations = [ - 'edit in collabora', - 'preview in collabora' - ]; - - if (in_array($operation, $allowed_operations) && $target === 'entity') { - return TRUE; - } - - return $this->parent->supportsOperation($operation, $target); - } - -} diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php index 3451688c..72aebd95 100644 --- a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php @@ -12,21 +12,6 @@ */ class CollaboraPermissionProvider extends GroupMediaPermissionProvider { - /** - * Constructs a new CollaboraPermissionProvider. - * - * @param \Drupal\group\Plugin\Group\RelationHandler\PermissionProviderInterface $groupMediaPermissionProvider - * The original access control handler. - * @param \Drupal\group\Plugin\Group\RelationHandler\PermissionProviderInterface $parent - * The parent access control handler. - */ - public function __construct( - protected PermissionProviderInterface $groupMediaPermissionProvider, - PermissionProviderInterface $parent - ) { - parent::__construct($parent); - } - /** * {@inheritdoc} */ From 9acef9c12078b76a03cf10cf0184fee71adbbb8c Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 19 Nov 2024 17:29:47 +0100 Subject: [PATCH 20/53] Issue CollaboraOnline/collabora-drupal#52: Missing docs. --- src/Plugin/views/field/CollaboraEdit.php | 3 +++ src/Plugin/views/field/CollaboraPreview.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Plugin/views/field/CollaboraEdit.php b/src/Plugin/views/field/CollaboraEdit.php index 420cb287..e78ba9dd 100644 --- a/src/Plugin/views/field/CollaboraEdit.php +++ b/src/Plugin/views/field/CollaboraEdit.php @@ -18,6 +18,9 @@ */ class CollaboraEdit extends LinkBase { + /** + * {@inheritdoc} + */ protected function getUrlInfo(ResultRow $row): Url|null { /** @var \Drupal\media\MediaInterface $entity */ $entity = $this->getEntity($row); diff --git a/src/Plugin/views/field/CollaboraPreview.php b/src/Plugin/views/field/CollaboraPreview.php index ed0544c7..9c47f431 100644 --- a/src/Plugin/views/field/CollaboraPreview.php +++ b/src/Plugin/views/field/CollaboraPreview.php @@ -18,6 +18,9 @@ */ class CollaboraPreview extends LinkBase { + /** + * {@inheritdoc} + */ protected function getUrlInfo(ResultRow $row): Url|null { /** @var \Drupal\media\MediaInterface $entity */ $entity = $this->getEntity($row); From 5325f466f6639808d1e66697e24859a1889e2654 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Mon, 11 Nov 2024 12:32:41 +0100 Subject: [PATCH 21/53] Issue CollaboraOnline/collabora-drupal#52: Remove unused class. --- .../Plugin/Group/RelationHandler/CollaboraPermissionProvider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php index 72aebd95..e04c0d5c 100644 --- a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php @@ -5,7 +5,6 @@ namespace Drupal\collabora_online_group\Plugin\Group\RelationHandler; use Drupal\groupmedia\Plugin\Group\RelationHandler\GroupMediaPermissionProvider; -use Drupal\group\Plugin\Group\RelationHandler\PermissionProviderInterface; /** * Provides Collabora permissions for group. From c8239c736a3f6bee6dbd6fa8f50b6e0d13bf29af Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 19 Nov 2024 17:30:08 +0100 Subject: [PATCH 22/53] Issue CollaboraOnline/collabora-drupal#52: Rename views test. --- .../src/Functional/{ViewTest.php => GroupMediaViewsTest.php} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename modules/collabora_online_group/tests/src/Functional/{ViewTest.php => GroupMediaViewsTest.php} (97%) diff --git a/modules/collabora_online_group/tests/src/Functional/ViewTest.php b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php similarity index 97% rename from modules/collabora_online_group/tests/src/Functional/ViewTest.php rename to modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php index 07491943..e376e1f1 100644 --- a/modules/collabora_online_group/tests/src/Functional/ViewTest.php +++ b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php @@ -15,9 +15,9 @@ use Drupal\user\RoleInterface; /** - * Test the provided view by the module. + * Test the modifications performend in groupmedia view by the module. */ -class ViewTest extends BrowserTestBase { +class GroupMediaViewsTest extends BrowserTestBase { use MediaCreationTrait; use GroupRelationTrait; From 14bcfb81ff87011d35f826a68c8caf612c27bccd Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Mon, 11 Nov 2024 17:17:15 +0100 Subject: [PATCH 23/53] Issue CollaboraOnline/collabora-drupal#52: Add support for groupmedia 3 and 4. --- .github/workflows/ci.yaml | 13 +++++++++++-- composer.json | 2 +- phpunit.xml.dist | 6 ++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 21b0b808..e6e3d219 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,6 +12,7 @@ jobs: fail-fast: true matrix: php: [8.1, 8.2, 8.3] + groupmedia: [3, 4] steps: - uses: actions/checkout@v4 @@ -54,7 +55,7 @@ jobs: - name: Composer install run: | docker-compose exec -T web composer config --merge --json "extra.patches" '{"drupal/group": {"Using a translatable string as a category for field type is deprecated - https://www.drupal.org/project/group/issues/3458530": "https://www.drupal.org/files/issues/2024-07-02/group-translate-string-as-category-is-deprecated_0.patch"}}' - docker-compose exec -T web composer require --dev cweagans/composer-patches + docker-compose exec -T web composer require --dev cweagans/composer-patches drupal/groupmedia:~${{ matrix.groupmedia }} - name: PhpCS run: | @@ -65,5 +66,13 @@ jobs: docker-compose exec -T web ./vendor/bin/run drupal:site-install - name: PhpUnit + if: ${{ matrix.groupmedia != '3' }} run: | - docker-compose exec -T web ./vendor/bin/phpunit -vvv --debug + docker-compose exec -T web ./vendor/bin/phpunit -vvv --debug + + - name: PhpUnit + if: ${{ matrix.groupmedia == '3' }} + run: | + docker-compose exec -T web ./vendor/bin/phpunit -vvv --debug --testsuite "Collabora Online Group" + + diff --git a/composer.json b/composer.json index 06973770..28e4b24a 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "drupal/core-composer-scaffold": "^10.3.6", "drupal/core-dev": "^10.3.6", "drupal/core-recommended": "^10.3.6", - "drupal/groupmedia": "^4", + "drupal/groupmedia": "^3 || ^4", "drush/drush": "^12.4", "openeuropa/task-runner": "^2@dev", "openeuropa/task-runner-drupal-project-symlink": "^1.0.0-beta6", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 59cc4a4e..d441b3ea 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -22,9 +22,11 @@ value='["${selenium.browser}", {"browserName":"chrome","goog:chromeOptions":{"w3c": false, "args":["--no-sandbox", "--start-maximized", "--disable-gpu", "--window-size=1440,900", "--disable-dev-shm-usage", "--disable-setuid-sandbox", "--disable-web-security", "--DNS-prefetch-disable", "--disable-translate", "--ignore-certificate-errors", "--test-type", "--disable-extensions", "--incognito", "--disable-infobars"]}}, "${selenium.host}:${selenium.port}/wd/hub"]' /> - + ./tests/src/ - ./modules/**/tests/src/ + + + ./modules/collabora_online_group/tests/src/ From 6b87ed09b02a4435cb43c9705859ab464d51eb71 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Wed, 20 Nov 2024 08:26:33 +0100 Subject: [PATCH 24/53] Issue CollaboraOnline/collabora-drupal#52: PHP attributes for plugin. --- src/Plugin/views/field/CollaboraEdit.php | 4 ++-- src/Plugin/views/field/CollaboraPreview.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugin/views/field/CollaboraEdit.php b/src/Plugin/views/field/CollaboraEdit.php index e78ba9dd..56bedf4c 100644 --- a/src/Plugin/views/field/CollaboraEdit.php +++ b/src/Plugin/views/field/CollaboraEdit.php @@ -6,6 +6,7 @@ use Drupal\collabora_online\Cool\CoolUtils; use Drupal\Core\Url; +use Drupal\views\Attribute\ViewsField; use Drupal\views\Plugin\views\field\LinkBase; use Drupal\views\ResultRow; @@ -13,9 +14,8 @@ * Field handler for link to edit a collabora file. * * @ingroup views_field_handlers - * - * @ViewsField("media_collabora_edit") */ +#[ViewsField('media_collabora_edit')] class CollaboraEdit extends LinkBase { /** diff --git a/src/Plugin/views/field/CollaboraPreview.php b/src/Plugin/views/field/CollaboraPreview.php index 9c47f431..a0d24411 100644 --- a/src/Plugin/views/field/CollaboraPreview.php +++ b/src/Plugin/views/field/CollaboraPreview.php @@ -6,6 +6,7 @@ use Drupal\collabora_online\Cool\CoolUtils; use Drupal\Core\Url; +use Drupal\views\Attribute\ViewsField; use Drupal\views\Plugin\views\field\LinkBase; use Drupal\views\ResultRow; @@ -13,9 +14,8 @@ * Field handler for link to preview a collabora file. * * @ingroup views_field_handlers - * - * @ViewsField("media_collabora_preview") */ +#[ViewsField('media_collabora_preview')] class CollaboraPreview extends LinkBase { /** From d156334b123675a14d72be7fbb272378ddd05f76 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Mon, 11 Nov 2024 17:42:40 +0100 Subject: [PATCH 25/53] Issue CollaboraOnline/collabora-drupal#52: Fix tests. --- .../tests/src/Kernel/AccessTest.php | 14 +++--- .../tests/src/Kernel/PermissionTest.php | 29 +++++++----- .../tests/src/Traits/GroupRelationTrait.php | 46 +++++++++++++++++++ 3 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php index 2ffa8da4..15965d24 100644 --- a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -6,6 +6,7 @@ use Drupal\group\PermissionScopeInterface; use Drupal\Tests\collabora_online\Traits\MediaCreationTrait; +use Drupal\Tests\collabora_online_group\Traits\GroupRelationTrait; use Drupal\Tests\group\Kernel\GroupKernelTestBase; use Drupal\Tests\media\Traits\MediaTypeCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait; @@ -19,6 +20,7 @@ class AccessTest extends GroupKernelTestBase { use MediaTypeCreationTrait; use UserCreationTrait; use MediaCreationTrait; + use GroupRelationTrait; /** * {@inheritdoc} @@ -61,13 +63,11 @@ public function testCollaboraAccess(bool $expected_result, array $permissions, a 'permissions' => $group_permissions ]); $this->createMediaType('file', ['id' => 'document']); - $this->entityTypeManager()->getStorage('group_relationship_type') - ->createFromPlugin($group_type, 'group_media:document', [ - 'group_cardinality' => 0, - 'entity_cardinality' => 1, - 'use_creation_wizard' => FALSE, - ]) - ->save(); + $this->createPluginRelation($group_type, 'group_media:document', [ + 'group_cardinality' => 0, + 'entity_cardinality' => 1, + 'use_creation_wizard' => FALSE, + ]); // Add group, media and relation between both. $group = $this->createGroup(['type' => $group_type->id()]); diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php index 39aff0ac..406c5c27 100644 --- a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\collabora_online_group\Kernel; +use Drupal\Tests\collabora_online_group\Traits\GroupRelationTrait; use Drupal\Tests\group\Kernel\GroupKernelTestBase; use Drupal\Tests\media\Traits\MediaTypeCreationTrait; @@ -13,6 +14,7 @@ class PermissionTest extends GroupKernelTestBase { use MediaTypeCreationTrait; + use GroupRelationTrait; /** * {@inheritdoc} @@ -36,27 +38,30 @@ public function testGroupPermissions(): void { $media_type_2 = $this->createMediaType('file', ['id' => 'media_2']); // Enable relation plugins in groups. - $this->entityTypeManager()->getStorage('group_relationship_type') - ->createFromPlugin($group_type_1, 'group_media:' . $media_type_1->id(), [ + $this->createPluginRelation( + $group_type_1, + 'group_media:' . $media_type_1->id(), + [ 'group_cardinality' => 0, 'entity_cardinality' => 1, 'use_creation_wizard' => FALSE, - ]) - ->save(); - $this->entityTypeManager()->getStorage('group_relationship_type') - ->createFromPlugin($group_type_2, 'group_media:' . $media_type_1->id(), [ + ]); + $this->createPluginRelation( + $group_type_2, + 'group_media:' . $media_type_1->id(), + [ 'group_cardinality' => 0, 'entity_cardinality' => 1, 'use_creation_wizard' => FALSE, - ]) - ->save(); - $this->entityTypeManager()->getStorage('group_relationship_type') - ->createFromPlugin($group_type_2, 'group_media:' . $media_type_2->id(), [ + ]); + $this->createPluginRelation( + $group_type_2, + 'group_media:' . $media_type_2->id(), + [ 'group_cardinality' => 0, 'entity_cardinality' => 1, 'use_creation_wizard' => FALSE, - ]) - ->save(); + ]); // Check that permissions are generated for the groups. // Save current permissions count. diff --git a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php new file mode 100644 index 00000000..69d4a3c8 --- /dev/null +++ b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php @@ -0,0 +1,46 @@ +entityTypeManager()->getDefinition($entity_type_id, FALSE) === NULL) { + $entity_type_id = 'group_content_type'; + } + + $entity = $this->entityTypeManager() + ->getStorage($entity_type_id) + ->createFromPlugin($group_type, $plugin_id, $values); + $entity->save(); + + return $entity; + } + +} From 9fa7f4c61a11ffe2a9b1733bd970df089f75556c Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 19 Nov 2024 17:37:22 +0100 Subject: [PATCH 26/53] Issue CollaboraOnline/collabora-drupal#52: Remove named parameter. --- tests/src/Kernel/ViewsLinkFieldsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Kernel/ViewsLinkFieldsTest.php b/tests/src/Kernel/ViewsLinkFieldsTest.php index bdb4e42e..3c72b5e1 100644 --- a/tests/src/Kernel/ViewsLinkFieldsTest.php +++ b/tests/src/Kernel/ViewsLinkFieldsTest.php @@ -118,7 +118,7 @@ public function testLinks(): void { * The user account to be used to run the test. */ protected function doTestLinks(array $expected_results, AccountInterface $account): void { - $this->setCurrentUser(account: $account); + $this->setCurrentUser($account); // Set the current user as the owner to check 'edit own' access. $this->ownMedia->setOwnerId($account->id())->save(); $view = Views::getView('test_collabora_links'); From 2b19c150c5fe82b120e4b2d9326dff315bff70c0 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 12 Nov 2024 09:18:13 +0100 Subject: [PATCH 27/53] Issue CollaboraOnline/collabora-drupal#52: Documentation improvements. --- .../tests/src/Kernel/AccessTest.php | 11 +++++++++ .../tests/src/Kernel/PermissionTest.php | 23 ++++++++++--------- tests/src/Traits/MediaCreationTrait.php | 2 -- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php index 15965d24..da54e644 100644 --- a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -51,6 +51,17 @@ protected function setUp(): void { /** * Tests that access to Collabora group permissions is handled. * + * @param bool $expected_result + * The access result. + * @param array $permissions + * The global permissions granted to the user. + * @param array $group_permissions + * The group permissions granted to the user. + * @param string $operation + * The operation to perform on the entity. + * @param string $scope + * Sets the user as author of the entity. + * * @dataProvider dataProvider */ public function testCollaboraAccess(bool $expected_result, array $permissions, array $group_permissions, string $operation, string $scope = ''): void { diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php index 406c5c27..9bedd665 100644 --- a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -34,13 +34,13 @@ public function testGroupPermissions(): void { $group_type_1 = $this->createGroupType(['id' => 'group_1']); $group_type_2 = $this->createGroupType(['id' => 'group_2']); $group_type_3 = $this->createGroupType(['id' => 'group_3']); - $media_type_1 = $this->createMediaType('file', ['id' => 'media_1']); - $media_type_2 = $this->createMediaType('file', ['id' => 'media_2']); + $this->createMediaType('file', ['id' => 'media_1']); + $this->createMediaType('file', ['id' => 'media_2']); // Enable relation plugins in groups. $this->createPluginRelation( $group_type_1, - 'group_media:' . $media_type_1->id(), + 'group_media:media_1', [ 'group_cardinality' => 0, 'entity_cardinality' => 1, @@ -48,7 +48,7 @@ public function testGroupPermissions(): void { ]); $this->createPluginRelation( $group_type_2, - 'group_media:' . $media_type_1->id(), + 'group_media:media_1', [ 'group_cardinality' => 0, 'entity_cardinality' => 1, @@ -56,7 +56,7 @@ public function testGroupPermissions(): void { ]); $this->createPluginRelation( $group_type_2, - 'group_media:' . $media_type_2->id(), + 'group_media:media_2', [ 'group_cardinality' => 0, 'entity_cardinality' => 1, @@ -65,6 +65,7 @@ public function testGroupPermissions(): void { // Check that permissions are generated for the groups. // Save current permissions count. + /** @var \Drupal\group\Access\GroupPermissionHandlerInterface $permission_handler */ $permission_handler = \Drupal::service('group.permissions'); $count_group_1 = count($permission_handler->getPermissionsByGroupType($group_type_1)); $count_group_2 = count($permission_handler->getPermissionsByGroupType($group_type_2)); @@ -75,18 +76,18 @@ public function testGroupPermissions(): void { $permission_handler = \Drupal::service('group.permissions'); // The 'group_1' has only 'media_type_1' permissions. $permissions_group_1 = $permission_handler->getPermissionsByGroupType($group_type_1); - $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_1); - $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_1, FALSE); + $this->assertCollaboraPermissions('group_media:media_1', $permissions_group_1); + $this->assertCollaboraPermissions('group_media:media_2', $permissions_group_1, FALSE); $this->assertCount($count_group_1 + 3, $permissions_group_1); // The 'group_2' has 'media_type_1' and 'media_type_2' permissions. $permissions_group_2 = $permission_handler->getPermissionsByGroupType($group_type_2); - $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_2); - $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_2); + $this->assertCollaboraPermissions('group_media:media_1', $permissions_group_2); + $this->assertCollaboraPermissions('group_media:media_2', $permissions_group_2); $this->assertCount($count_group_2 + 6, $permissions_group_2); // The 'group_3' doesn't have any new permissions. $permissions_group_3 = $permission_handler->getPermissionsByGroupType($group_type_3); - $this->assertCollaboraPermissions('group_media:' . $media_type_1->id(), $permissions_group_3, FALSE); - $this->assertCollaboraPermissions('group_media:' . $media_type_2->id(), $permissions_group_3, FALSE); + $this->assertCollaboraPermissions('group_media:media_1', $permissions_group_3, FALSE); + $this->assertCollaboraPermissions('group_media:media_2', $permissions_group_3, FALSE); $this->assertCount($count_group_3, $permissions_group_3); } diff --git a/tests/src/Traits/MediaCreationTrait.php b/tests/src/Traits/MediaCreationTrait.php index a8e1d47e..32b59310 100644 --- a/tests/src/Traits/MediaCreationTrait.php +++ b/tests/src/Traits/MediaCreationTrait.php @@ -10,8 +10,6 @@ /** * Provides methods to create a media from given values. - * - * This trait is meant to be used only by test classes. */ trait MediaCreationTrait { From e3c54ae7c13adcadfe2db527b2d08d4e88d136aa Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 7 Nov 2024 18:08:51 +0100 Subject: [PATCH 28/53] Issue CollaboraOnline/collabora-drupal#52: Add module. --- collabora_online.info.yml | 2 +- composer.json | 1 + .../collabora_online_group.info.yml | 9 +++++++++ phpunit.xml.dist | 1 + runner.yml.dist | 2 ++ 5 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 modules/collabora_online_group/collabora_online_group.info.yml diff --git a/collabora_online.info.yml b/collabora_online.info.yml index 209be32f..2c08fe02 100644 --- a/collabora_online.info.yml +++ b/collabora_online.info.yml @@ -1,6 +1,6 @@ name: Collabora Online description: Integrate Collabora Online for document viewing and editing. -package: Custom +package: Collabora online configure: collabora-online.settings dependencies: - drupal:media diff --git a/composer.json b/composer.json index 226caeb8..06973770 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "drupal/core-composer-scaffold": "^10.3.6", "drupal/core-dev": "^10.3.6", "drupal/core-recommended": "^10.3.6", + "drupal/groupmedia": "^4", "drush/drush": "^12.4", "openeuropa/task-runner": "^2@dev", "openeuropa/task-runner-drupal-project-symlink": "^1.0.0-beta6", diff --git a/modules/collabora_online_group/collabora_online_group.info.yml b/modules/collabora_online_group/collabora_online_group.info.yml new file mode 100644 index 00000000..194a8825 --- /dev/null +++ b/modules/collabora_online_group/collabora_online_group.info.yml @@ -0,0 +1,9 @@ +name: Collabora Online Group +description: Integrates Collabora Online with Group module +package: Collabora online +dependencies: + - collabora_online:collabora_online + - groupmedia:groupmedia + +type: module +core_version_requirement: ^10 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f9c88b18..59cc4a4e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -24,6 +24,7 @@ ./tests/src/ + ./modules/**/tests/src/ diff --git a/runner.yml.dist b/runner.yml.dist index 6eba4d40..943d0fe5 100755 --- a/runner.yml.dist +++ b/runner.yml.dist @@ -36,6 +36,8 @@ drupal: - "./vendor/bin/drush -y config-set collabora_online.settings cool.key_id collabora" - "./vendor/bin/drush -y config-set collabora_online.settings cool.access_token_ttl 86400" - "./vendor/bin/drush -y config-set collabora_online.settings cool.disable_cert_check 1" + # Sub-modules. + - "./vendor/bin/drush -y en collabora_online_group" # Create the JWT key. - | From 2f0e5e1bb0ceec5ba934ba5ba1957fa1ea0c7ab5 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 21 Nov 2024 11:22:24 +0100 Subject: [PATCH 29/53] Issue 52: Fix sniffer errors. --- collabora_online.views.inc | 5 ++ .../collabora_online_group.install | 8 +++- .../src/Functional/GroupMediaViewsTest.php | 8 ++-- .../tests/src/Kernel/AccessTest.php | 47 ++++++++++--------- .../tests/src/Kernel/PermissionTest.php | 7 +-- .../tests/src/Traits/GroupRelationTrait.php | 2 +- src/Plugin/views/field/CollaboraEdit.php | 1 + src/Plugin/views/field/CollaboraPreview.php | 1 + tests/src/Kernel/ViewsLinkFieldsTest.php | 21 +++++---- 9 files changed, 58 insertions(+), 42 deletions(-) diff --git a/collabora_online.views.inc b/collabora_online.views.inc index 1e3d8302..275511b5 100644 --- a/collabora_online.views.inc +++ b/collabora_online.views.inc @@ -1,5 +1,10 @@ t('Edit in Collabora Online'), ], ]; - // Add new fields as options for the dropbutton and move the element to the end. + // Add new fields as options for the dropbutton, and move the dropbutton to + // the end of the array. $dropbutton = $display['display_options']['fields']['dropbutton']; $dropbutton['fields'] += [ 'collabora_preview' => 'collabora_preview', diff --git a/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php index b574ba74..a95267d3 100644 --- a/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php +++ b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php @@ -114,12 +114,12 @@ public function testViewLinks(): void { Url::fromRoute( 'collabora-online.view', [ - 'media' => $media->id() + 'media' => $media->id(), ], [ 'query' => [ 'destination' => "/group/{$group->id()}/media", - ] + ], ] )->toString(), $operation_links[0]->getAttribute('href') @@ -129,12 +129,12 @@ public function testViewLinks(): void { Url::fromRoute( 'collabora-online.edit', [ - 'media' => $media->id() + 'media' => $media->id(), ], [ 'query' => [ 'destination' => "/group/{$group->id()}/media", - ] + ], ] )->toString(), $operation_links[1]->getAttribute('href') diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php index 866e9b51..d73f6c5c 100644 --- a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -33,20 +33,20 @@ class AccessTest extends GroupKernelTestBase { 'groupmedia', 'collabora_online', 'collabora_online_group', - 'user' + 'user', ]; /** - * {@inheritdoc} - */ - protected function setUp(): void { - parent::setUp(); + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); - $this->installEntitySchema('file'); - $this->installEntitySchema('media'); - $this->installEntitySchema('group_role'); - $this->installSchema('file', ['file_usage']); - } + $this->installEntitySchema('file'); + $this->installEntitySchema('media'); + $this->installEntitySchema('group_role'); + $this->installSchema('file', ['file_usage']); + } /** * Tests that access to Collabora group permissions is handled. @@ -76,7 +76,8 @@ public function testCollaboraAccess(): void { foreach ($this->getTestScenarios() as $scenario_name => $scenario) { // Set the current permissions for the existing role. $group_role->set('permissions', $scenario['group_permissions'])->save(); - // Create the user with the given permissions and as member of the group. + // Create the user with the given permissions and as member of the + // group. $user = $this->createUser($scenario['permissions']); $group->addMember($user); // Set user as owner if the scope is 'own'. @@ -90,7 +91,7 @@ public function testCollaboraAccess(): void { sprintf('Access check failed for scenario: %s', $scenario_name) ); } - } + } /** * Retrieves the scenarios to be tested. @@ -105,65 +106,65 @@ protected function getTestScenarios(): array { 'permissions' => [], 'group_permissions' => [], 'operation' => 'preview in collabora', - 'scope' => 'any' + 'scope' => 'any', ], 'preview_global_permisions' => [ 'result' => FALSE, 'permissions' => ['preview document in collabora'], 'group_permissions' => [], 'operation' => 'preview in collabora', - 'scope' => 'any' + 'scope' => 'any', ], - 'preview_group_permisions' =>[ + 'preview_group_permisions' => [ 'result' => TRUE, 'permissions' => [], 'group_permissions' => ['preview group_media:document in collabora'], 'operation' => 'preview in collabora', - 'scope' => 'any' + 'scope' => 'any', ], 'edit_any_no_permisions' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => [], 'operation' => 'edit in collabora', - 'scope' => 'any' + 'scope' => 'any', ], 'edit_any_global_permisions' => [ 'result' => FALSE, 'permissions' => ['edit any document in collabora'], 'group_permissions' => [], 'operation' => 'edit in collabora', - 'scope' => 'any' + 'scope' => 'any', ], 'edit_any_group_permisions' => [ 'result' => TRUE, 'permissions' => [], 'group_permissions' => ['edit any group_media:document in collabora'], 'operation' => 'edit in collabora', - 'scope' => 'any' + 'scope' => 'any', ], 'edit_own_no_permisions' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => [], 'operation' => 'edit in collabora', - 'scope' => 'own' + 'scope' => 'own', ], 'edit_own_global_permisions' => [ 'result' => FALSE, 'permissions' => ['edit own document in collabora'], 'group_permissions' => [], 'operation' => 'edit in collabora', - 'scope' => 'own' + 'scope' => 'own', ], 'edit_own_group_permisions' => [ 'result' => TRUE, 'permissions' => [], 'group_permissions' => ['edit own group_media:document in collabora'], 'operation' => 'edit in collabora', - 'scope' => 'own' + 'scope' => 'own', ], ]; - } + } } diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php index 362c9c7a..9baa06ce 100644 --- a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -45,7 +45,7 @@ public function testGroupPermissions(): void { 'group_cardinality' => 0, 'entity_cardinality' => 1, 'use_creation_wizard' => FALSE, - ]); + ]); $this->createPluginRelation( $group_type_2, 'group_media:document', @@ -53,7 +53,7 @@ public function testGroupPermissions(): void { 'group_cardinality' => 0, 'entity_cardinality' => 1, 'use_creation_wizard' => FALSE, - ]); + ]); $this->createPluginRelation( $group_type_2, 'group_media:spreadsheet', @@ -61,7 +61,7 @@ public function testGroupPermissions(): void { 'group_cardinality' => 0, 'entity_cardinality' => 1, 'use_creation_wizard' => FALSE, - ]); + ]); // Check that permissions are generated for the groups. // Save current permissions. @@ -117,4 +117,5 @@ public function testGroupPermissions(): void { $new_permissions_3, )); } + } diff --git a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php index b66dc3d2..fb6c508d 100644 --- a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php +++ b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php @@ -18,7 +18,7 @@ trait GroupRelationTrait { * Wrapper to support group 2.x and 3.x. * * @param \Drupal\group\Entity\GroupTypeInterface $group_type - * The group type + * The group type. * @param string $plugin_id * The plugin. * @param array $values diff --git a/src/Plugin/views/field/CollaboraEdit.php b/src/Plugin/views/field/CollaboraEdit.php index 92bc2bd7..328ebc76 100644 --- a/src/Plugin/views/field/CollaboraEdit.php +++ b/src/Plugin/views/field/CollaboraEdit.php @@ -39,4 +39,5 @@ protected function getUrlInfo(ResultRow $row): Url|null { protected function getDefaultLabel(): TranslatableMarkup { return $this->t('Edit in Collabora Online'); } + } diff --git a/src/Plugin/views/field/CollaboraPreview.php b/src/Plugin/views/field/CollaboraPreview.php index e93817f9..f636b359 100644 --- a/src/Plugin/views/field/CollaboraPreview.php +++ b/src/Plugin/views/field/CollaboraPreview.php @@ -39,4 +39,5 @@ protected function getUrlInfo(ResultRow $row): Url|null { protected function getDefaultLabel(): TranslatableMarkup { return $this->t('View in Collabora Online'); } + } diff --git a/tests/src/Kernel/ViewsLinkFieldsTest.php b/tests/src/Kernel/ViewsLinkFieldsTest.php index 2aa9e7ef..e7dc336d 100644 --- a/tests/src/Kernel/ViewsLinkFieldsTest.php +++ b/tests/src/Kernel/ViewsLinkFieldsTest.php @@ -25,7 +25,7 @@ class ViewsLinkFieldsTest extends KernelTestBase { /** * Media owned by current user. * - * @var \Drupal\media\MediaInterface; + * @var \Drupal\media\MediaInterface */ protected $ownMedia = NULL; @@ -59,7 +59,7 @@ protected function setUp(): void { \Drupal::moduleHandler()->loadInclude('user', 'install'); user_install(); - // Create two medias to check access with different scopes, 'any' and 'own'. + // Create two medias to check access with different scopes: any and own. $this->createMediaEntity('document'); $this->ownMedia = $this->createMediaEntity('document'); } @@ -83,7 +83,7 @@ public function testLinks(): void { 'edit' => [FALSE, FALSE], ], $this->createUser([ - 'preview document in collabora' + 'preview document in collabora', ]) ); // User with 'Edit any' permission can see edit link. @@ -93,17 +93,18 @@ public function testLinks(): void { 'edit' => [TRUE, TRUE], ], $this->createUser([ - 'edit any document in collabora' + 'edit any document in collabora', ]) ); - // User with 'Edit own' permission can see edit link for entities they own. + // User with 'Edit own' permission can see edit link for entities they + // own. $this->doTestLinks( [ 'preview' => [FALSE, FALSE], 'edit' => [FALSE, TRUE], ], $this->createUser([ - 'edit own document in collabora' + 'edit own document in collabora', ]) ); } @@ -127,12 +128,12 @@ protected function doTestLinks(array $expected_results, AccountInterface $accoun 'preview' => [ 'label' => 'View in Collabora Online', 'field_id' => 'collabora_preview', - 'route' => 'collabora-online.view' + 'route' => 'collabora-online.view', ], 'edit' => [ 'label' => 'Edit in Collabora Online', 'field_id' => 'collabora_edit', - 'route' => 'collabora-online.edit' + 'route' => 'collabora-online.edit', ], ]; @@ -141,12 +142,12 @@ protected function doTestLinks(array $expected_results, AccountInterface $accoun foreach (Media::loadMultiple() as $media) { foreach ($expected_results as $operation => $expected_result) { $expected_link = ''; - // The operation array contains results for each of the entities. + // The operations array contains results for each entity. if ($expected_result[$i]) { $path = Url::fromRoute($info[$operation]['route'], ['media' => $media->id()])->toString(); $expected_link = '' . $info[$operation]['label'] . ''; } - // We check the output, whether it is a link or is empty (access denied). + // We check the output: link HTML or empty (access denied). $link = $view->style_plugin->getField($i, $info[$operation]['field_id']); $this->assertEquals($expected_link, (string) $link); } From 42c9c0cc8ce4c411fab74e5fbb297f8574d47c34 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Wed, 20 Nov 2024 10:59:41 +0100 Subject: [PATCH 30/53] Issue CollaboraOnline/collabora-drupal#52: Drop version function. --- .../tests/src/Functional/GroupMediaViewsTest.php | 2 +- .../tests/src/Traits/GroupRelationTrait.php | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php index e376e1f1..0db5e3d5 100644 --- a/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php +++ b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php @@ -93,7 +93,7 @@ public function testViewLinks(): void { $this->assertEquals('Status', $cols[2]->getText()); $this->assertEquals('Publisher', $cols[3]->getText()); // Support for different vesrions of groupmedia. - $this->assertEquals($this->isGroupRelationshipType() ? 'Operations' : 'Dropbutton', $cols[4]->getText()); + $this->assertTrue(in_array($cols[4]->getText(), ['Operations', 'Dropbutton'])); // Check that rows contain new links for operations in Collabora. $table_body = $assert_session->elementExists('css', 'tbody', $table); diff --git a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php index 69e380e6..b66dc3d2 100644 --- a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php +++ b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php @@ -31,7 +31,7 @@ protected function createPluginRelation(GroupTypeInterface $group_type, string $ $entity_type_id = 'group_relationship_type'; // Fallback for older versions. - if (!$this->isGroupRelationshipType()) { + if ($this->entityTypeManager()->getDefinition($entity_type_id, FALSE) === NULL) { $entity_type_id = 'group_content_type'; } @@ -43,14 +43,4 @@ protected function createPluginRelation(GroupTypeInterface $group_type, string $ return $entity; } - /** - * Checks if 'group_relationship_type' group type entity exists. - * - * @return bool - * If the entity type exists. - */ - protected function isGroupRelationshipType(): bool { - return ($this->entityTypeManager()->getDefinition('group_relationship_type', FALSE) !== NULL); - } - } From 5d7bb766d364b9bd05a4f0ef1158d039fdc8cbb1 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 12 Nov 2024 10:10:42 +0100 Subject: [PATCH 31/53] Issue CollaboraOnline/collabora-drupal#52: Refactor permissions check. --- .../tests/src/Kernel/PermissionTest.php | 87 ++++++++++--------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php index 9bedd665..27df6a6f 100644 --- a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -64,56 +64,57 @@ public function testGroupPermissions(): void { ]); // Check that permissions are generated for the groups. - // Save current permissions count. + // Save current permissions. /** @var \Drupal\group\Access\GroupPermissionHandlerInterface $permission_handler */ $permission_handler = \Drupal::service('group.permissions'); - $count_group_1 = count($permission_handler->getPermissionsByGroupType($group_type_1)); - $count_group_2 = count($permission_handler->getPermissionsByGroupType($group_type_2)); - $count_group_3 = count($permission_handler->getPermissionsByGroupType($group_type_3)); + $permissions_before_1 = $permission_handler->getPermissionsByGroupType($group_type_1); + $permissions_before_2 = $permission_handler->getPermissionsByGroupType($group_type_2); + $permissions_before_3 = $permission_handler->getPermissionsByGroupType($group_type_3); - // Check collabora permissions after enabling the module. + // Get permissions difference after enabling the module. $this->enableModules(['collabora_online_group']); $permission_handler = \Drupal::service('group.permissions'); + $permissions_after_1 = $permission_handler->getPermissionsByGroupType($group_type_1); + $new_permissions_1 = array_diff_key($permissions_after_1, $permissions_before_1); + ksort($new_permissions_1); + $permissions_after_2 = $permission_handler->getPermissionsByGroupType($group_type_2); + $new_permissions_2 = array_diff_key($permissions_after_2, $permissions_before_2); + ksort($new_permissions_2); + $permissions_after_3 = $permission_handler->getPermissionsByGroupType($group_type_3); + $new_permissions_3 = array_diff_key($permissions_after_3, $permissions_before_3); + ksort($new_permissions_3); + // The 'group_1' has only 'media_type_1' permissions. - $permissions_group_1 = $permission_handler->getPermissionsByGroupType($group_type_1); - $this->assertCollaboraPermissions('group_media:media_1', $permissions_group_1); - $this->assertCollaboraPermissions('group_media:media_2', $permissions_group_1, FALSE); - $this->assertCount($count_group_1 + 3, $permissions_group_1); + $this->assertSame( + [ + 'edit any group_media:media_1 in collabora' => 'Entity: Edit any media item in collabora', + 'edit own group_media:media_1 in collabora' => 'Entity: Edit own media item in collabora', + 'preview group_media:media_1 in collabora' => 'Entity: Preview media item in collabora', + ], + array_map( + fn ($permission) => (string) $permission['title'], + $new_permissions_1, + )); // The 'group_2' has 'media_type_1' and 'media_type_2' permissions. - $permissions_group_2 = $permission_handler->getPermissionsByGroupType($group_type_2); - $this->assertCollaboraPermissions('group_media:media_1', $permissions_group_2); - $this->assertCollaboraPermissions('group_media:media_2', $permissions_group_2); - $this->assertCount($count_group_2 + 6, $permissions_group_2); + $this->assertSame( + [ + 'edit any group_media:media_1 in collabora' => 'Entity: Edit any media item in collabora', + 'edit any group_media:media_2 in collabora' => 'Entity: Edit any media item in collabora', + 'edit own group_media:media_1 in collabora' => 'Entity: Edit own media item in collabora', + 'edit own group_media:media_2 in collabora' => 'Entity: Edit own media item in collabora', + 'preview group_media:media_1 in collabora' => 'Entity: Preview media item in collabora', + 'preview group_media:media_2 in collabora' => 'Entity: Preview media item in collabora', + ], + array_map( + fn ($permission) => (string) $permission['title'], + $new_permissions_2, + )); // The 'group_3' doesn't have any new permissions. - $permissions_group_3 = $permission_handler->getPermissionsByGroupType($group_type_3); - $this->assertCollaboraPermissions('group_media:media_1', $permissions_group_3, FALSE); - $this->assertCollaboraPermissions('group_media:media_2', $permissions_group_3, FALSE); - $this->assertCount($count_group_3, $permissions_group_3); - } - - /** - * Asserts whether collaboration permissions are present in a given array. - * - * @param string $id - * The entity ID. - * @param array $permissions - * The permission to check. - * @param bool $enabled - * If the permissions are enabled. - */ - protected function assertCollaboraPermissions(string $id, array $permissions, bool $enabled = TRUE): void { - $expected_permissions = [ - "preview $id in collabora" => "Entity: Preview media item in collabora", - "edit any $id in collabora" => "Entity: Edit any media item in collabora", - "edit own $id in collabora" => "Entity: Edit own media item in collabora", - ]; - - foreach($expected_permissions as $name => $description) { - if ($enabled === FALSE) { - $this->assertArrayNotHasKey($name, $permissions); - continue; - } - $this->assertEquals($description, $permissions[$name]['title']); - } + $this->assertSame( + [], + array_map( + fn ($permission) => (string) $permission['title'], + $new_permissions_3, + )); } } From 325b21799d66616129055a5687c5f2e574193203 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 7 Nov 2024 09:47:44 +0100 Subject: [PATCH 32/53] Issue CollaboraOnline/collabora-drupal#52: Add smoke test for sub-module. --- .../tests/src/Functional/SmokeTest.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 modules/collabora_online_group/tests/src/Functional/SmokeTest.php diff --git a/modules/collabora_online_group/tests/src/Functional/SmokeTest.php b/modules/collabora_online_group/tests/src/Functional/SmokeTest.php new file mode 100644 index 00000000..95a22e47 --- /dev/null +++ b/modules/collabora_online_group/tests/src/Functional/SmokeTest.php @@ -0,0 +1,36 @@ +drupalGet(''); + $this->assertSession()->statusCodeEquals(200); + } + +} From 2b41aa2cb8b04a9bd128cf1703bd450349eb8752 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 21 Nov 2024 11:33:18 +0100 Subject: [PATCH 33/53] Issue 52: Use media creation trait. --- tests/src/Kernel/CollaboraMediaAccessTest.php | 31 ++----------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/tests/src/Kernel/CollaboraMediaAccessTest.php b/tests/src/Kernel/CollaboraMediaAccessTest.php index fd9a9c42..b9b6d814 100644 --- a/tests/src/Kernel/CollaboraMediaAccessTest.php +++ b/tests/src/Kernel/CollaboraMediaAccessTest.php @@ -8,10 +8,8 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AnonymousUserSession; use Drupal\Core\Url; -use Drupal\file\Entity\File; use Drupal\KernelTests\KernelTestBase; -use Drupal\media\Entity\Media; -use Drupal\media\MediaInterface; +use Drupal\Tests\collabora_online\Traits\MediaCreationTrait; use Drupal\Tests\media\Traits\MediaTypeCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\user\RoleInterface; @@ -23,6 +21,7 @@ class CollaboraMediaAccessTest extends KernelTestBase { use MediaTypeCreationTrait; use UserCreationTrait; + use MediaCreationTrait; /** * {@inheritdoc} @@ -272,32 +271,6 @@ protected function assertCollaboraMediaAccess(array $expected, AccountInterface ); } - /** - * Creates a media entity with attached file. - * - * @param string $type - * Media type. - * @param array $values - * Values for the media entity. - * - * @return \Drupal\media\MediaInterface - * New media entity. - */ - protected function createMediaEntity(string $type, array $values = []): MediaInterface { - file_put_contents('public://test.txt', 'Hello test'); - $file = File::create([ - 'uri' => 'public://test.txt', - ]); - $file->save(); - $values += [ - 'bundle' => $type, - 'field_media_file' => $file->id(), - ]; - $media = Media::create($values); - $media->save(); - return $media; - } - /** * Asserts that two values are the same when exported to yaml. * From 9a01a48c3de0e20a547bd64ec67927d87de9e61b Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Wed, 20 Nov 2024 10:41:56 +0100 Subject: [PATCH 34/53] Issue CollaboraOnline/collabora-drupal#52: Change preview links label. --- collabora_online.views.inc | 4 ++-- config/schema/collabora_online.schema.yml | 2 +- .../collabora_online_group.install | 10 ++++++---- .../tests/src/Functional/GroupMediaViewsTest.php | 4 ++-- .../optional/views.view.test_collabora_links.yml | 4 ++-- tests/src/Kernel/ViewsLinkFieldsTest.php | 4 ++-- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/collabora_online.views.inc b/collabora_online.views.inc index fff2b5b6..1e3d8302 100644 --- a/collabora_online.views.inc +++ b/collabora_online.views.inc @@ -7,14 +7,14 @@ declare(strict_types=1); */ function collabora_online_views_data_alter(array &$data): void { $data['media']['collabora_preview'] = [ - 'title' => t('Link to preview in Collabora'), + 'title' => t('Link to view in Collabora Online'), 'group' => t('Media'), 'field' => [ 'id' => 'media_collabora_preview', ], ]; $data['media']['collabora_edit'] = [ - 'title' => t('Link to edit in Collabora'), + 'title' => t('Link to edit in Collabora Online'), 'group' => t('Media'), 'field' => [ 'id' => 'media_collabora_edit', diff --git a/config/schema/collabora_online.schema.yml b/config/schema/collabora_online.schema.yml index 6d16d9de..9b2093ea 100644 --- a/config/schema/collabora_online.schema.yml +++ b/config/schema/collabora_online.schema.yml @@ -27,7 +27,7 @@ collabora_online.settings: views.field.media_collabora_preview: type: views_field - label: 'Collabora preview link' + label: 'Collabora view link' mapping: text: type: label diff --git a/modules/collabora_online_group/collabora_online_group.install b/modules/collabora_online_group/collabora_online_group.install index 7ae5919d..8ec5580b 100644 --- a/modules/collabora_online_group/collabora_online_group.install +++ b/modules/collabora_online_group/collabora_online_group.install @@ -29,8 +29,9 @@ function collabora_online_group_install(bool $is_syncing): void { 'plugin_id' => 'media_collabora_preview', 'label' => '', 'exclude' => TRUE, - 'text' => t('Preview in Collabora'), - ]]; + 'text' => t('View in Collabora Online'), + ], + ]; $display['display_options']['fields'] += [ 'collabora_edit' => [ 'id' => 'collabora_edit', @@ -39,8 +40,9 @@ function collabora_online_group_install(bool $is_syncing): void { 'plugin_id' => 'media_collabora_edit', 'label' => '', 'exclude' => TRUE, - 'text' => t('Edit in Collabora'), - ]]; + 'text' => t('Edit in Collabora Online'), + ], + ]; // Add new fields as options for the dropbutton and move the element to the end. $dropbutton = $display['display_options']['fields']['dropbutton']; $dropbutton['fields'] += [ diff --git a/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php index 0db5e3d5..a67c6a3e 100644 --- a/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php +++ b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php @@ -106,7 +106,7 @@ public function testViewLinks(): void { $this->assertEquals('Yes', $cols[2]->getText()); $this->assertEquals('Anonymous', $cols[3]->getText()); $operation_links = $cols[4]->findAll('css', 'a'); - $this->assertEquals('Preview in Collabora', $operation_links[0]->getText()); + $this->assertEquals('View in Collabora Online', $operation_links[0]->getText()); $this->assertEquals( Url::fromRoute( 'collabora-online.view', @@ -121,7 +121,7 @@ public function testViewLinks(): void { )->toString(), $operation_links[0]->getAttribute('href') ); - $this->assertEquals('Edit in Collabora', $operation_links[1]->getText()); + $this->assertEquals('Edit in Collabora Online', $operation_links[1]->getText()); $this->assertEquals( Url::fromRoute( 'collabora-online.edit', diff --git a/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml b/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml index e5c96ff1..58fd87ac 100644 --- a/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml +++ b/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml @@ -117,7 +117,7 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - text: "Preview in Collabora" + text: "View in Collabora Online" collabora_edit: id: collabora_edit table: media @@ -168,7 +168,7 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - text: "Edit in Collabora" + text: "Edit in Collabora Online" pager: type: mini options: diff --git a/tests/src/Kernel/ViewsLinkFieldsTest.php b/tests/src/Kernel/ViewsLinkFieldsTest.php index 3c72b5e1..e561270f 100644 --- a/tests/src/Kernel/ViewsLinkFieldsTest.php +++ b/tests/src/Kernel/ViewsLinkFieldsTest.php @@ -126,12 +126,12 @@ protected function doTestLinks(array $expected_results, AccountInterface $accoun $info = [ 'preview' => [ - 'label' => 'Preview in Collabora', + 'label' => 'View in Collabora Online', 'field_id' => 'collabora_preview', 'route' => 'collabora-online.view' ], 'edit' => [ - 'label' => 'Edit in Collabora', + 'label' => 'Edit in Collabora Online', 'field_id' => 'collabora_edit', 'route' => 'collabora-online.edit' ], From fbc574ebce94b65ecfba3f9d19d7830d4da6e4e7 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Wed, 13 Nov 2024 16:21:06 +0100 Subject: [PATCH 35/53] Issue CollaboraOnline/collabora-drupal#52: Code documentation improvements. --- .../CollaboraPermissionProvider.php | 2 +- .../tests/src/Kernel/AccessTest.php | 4 +- .../tests/src/Kernel/PermissionTest.php | 38 +++++++++---------- .../tests/src/Traits/GroupRelationTrait.php | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php index e04c0d5c..f523bdbe 100644 --- a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php @@ -17,7 +17,7 @@ class CollaboraPermissionProvider extends GroupMediaPermissionProvider { public function buildPermissions(): array { $permissions = $this->parent->buildPermissions(); - /** @see \Drupal\group\Plugin\Group\RelationHandlerDefault\PermissionProvider::buildPermissions() */ + /* @see \Drupal\group\Plugin\Group\RelationHandlerDefault\PermissionProvider::buildPermissions() */ $provider_chain = $this->groupRelationTypeManager()->getPermissionProvider($this->pluginId); // Add Collabora permissions. diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php index da54e644..3f6aac51 100644 --- a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -53,9 +53,9 @@ protected function setUp(): void { * * @param bool $expected_result * The access result. - * @param array $permissions + * @param string[] $permissions * The global permissions granted to the user. - * @param array $group_permissions + * @param string[] $group_permissions * The group permissions granted to the user. * @param string $operation * The operation to perform on the entity. diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php index 27df6a6f..362c9c7a 100644 --- a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -31,16 +31,16 @@ class PermissionTest extends GroupKernelTestBase { */ public function testGroupPermissions(): void { // Generate types: groups and medias. - $group_type_1 = $this->createGroupType(['id' => 'group_1']); - $group_type_2 = $this->createGroupType(['id' => 'group_2']); - $group_type_3 = $this->createGroupType(['id' => 'group_3']); - $this->createMediaType('file', ['id' => 'media_1']); - $this->createMediaType('file', ['id' => 'media_2']); + $group_type_1 = $this->createGroupType(); + $group_type_2 = $this->createGroupType(); + $group_type_3 = $this->createGroupType(); + $this->createMediaType('file', ['id' => 'document']); + $this->createMediaType('file', ['id' => 'spreadsheet']); // Enable relation plugins in groups. $this->createPluginRelation( $group_type_1, - 'group_media:media_1', + 'group_media:document', [ 'group_cardinality' => 0, 'entity_cardinality' => 1, @@ -48,7 +48,7 @@ public function testGroupPermissions(): void { ]); $this->createPluginRelation( $group_type_2, - 'group_media:media_1', + 'group_media:document', [ 'group_cardinality' => 0, 'entity_cardinality' => 1, @@ -56,7 +56,7 @@ public function testGroupPermissions(): void { ]); $this->createPluginRelation( $group_type_2, - 'group_media:media_2', + 'group_media:spreadsheet', [ 'group_cardinality' => 0, 'entity_cardinality' => 1, @@ -84,26 +84,26 @@ public function testGroupPermissions(): void { $new_permissions_3 = array_diff_key($permissions_after_3, $permissions_before_3); ksort($new_permissions_3); - // The 'group_1' has only 'media_type_1' permissions. + // The 'group_1' has only 'document' permissions. $this->assertSame( [ - 'edit any group_media:media_1 in collabora' => 'Entity: Edit any media item in collabora', - 'edit own group_media:media_1 in collabora' => 'Entity: Edit own media item in collabora', - 'preview group_media:media_1 in collabora' => 'Entity: Preview media item in collabora', + 'edit any group_media:document in collabora' => 'Entity: Edit any media item in collabora', + 'edit own group_media:document in collabora' => 'Entity: Edit own media item in collabora', + 'preview group_media:document in collabora' => 'Entity: Preview media item in collabora', ], array_map( fn ($permission) => (string) $permission['title'], $new_permissions_1, )); - // The 'group_2' has 'media_type_1' and 'media_type_2' permissions. + // The 'group_2' has 'document' and 'spreadsheet' permissions. $this->assertSame( [ - 'edit any group_media:media_1 in collabora' => 'Entity: Edit any media item in collabora', - 'edit any group_media:media_2 in collabora' => 'Entity: Edit any media item in collabora', - 'edit own group_media:media_1 in collabora' => 'Entity: Edit own media item in collabora', - 'edit own group_media:media_2 in collabora' => 'Entity: Edit own media item in collabora', - 'preview group_media:media_1 in collabora' => 'Entity: Preview media item in collabora', - 'preview group_media:media_2 in collabora' => 'Entity: Preview media item in collabora', + 'edit any group_media:document in collabora' => 'Entity: Edit any media item in collabora', + 'edit any group_media:spreadsheet in collabora' => 'Entity: Edit any media item in collabora', + 'edit own group_media:document in collabora' => 'Entity: Edit own media item in collabora', + 'edit own group_media:spreadsheet in collabora' => 'Entity: Edit own media item in collabora', + 'preview group_media:document in collabora' => 'Entity: Preview media item in collabora', + 'preview group_media:spreadsheet in collabora' => 'Entity: Preview media item in collabora', ], array_map( fn ($permission) => (string) $permission['title'], diff --git a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php index 69d4a3c8..807353bf 100644 --- a/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php +++ b/modules/collabora_online_group/tests/src/Traits/GroupRelationTrait.php @@ -8,7 +8,7 @@ use Drupal\group\Entity\GroupTypeInterface; /** - * Provides methods to create a media from given values. + * Provides a method to create a relation between a group type and a plugin. */ trait GroupRelationTrait { From 03120a3c90c8c60b9876bb303f70f74e6d3e7cfd Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 7 Nov 2024 18:12:14 +0100 Subject: [PATCH 36/53] Issue CollaboraOnline/collabora-drupal#52: Capitalise package. --- collabora_online.info.yml | 2 +- modules/collabora_online_group/collabora_online_group.info.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/collabora_online.info.yml b/collabora_online.info.yml index 2c08fe02..1230bfe7 100644 --- a/collabora_online.info.yml +++ b/collabora_online.info.yml @@ -1,6 +1,6 @@ name: Collabora Online description: Integrate Collabora Online for document viewing and editing. -package: Collabora online +package: Collabora Online configure: collabora-online.settings dependencies: - drupal:media diff --git a/modules/collabora_online_group/collabora_online_group.info.yml b/modules/collabora_online_group/collabora_online_group.info.yml index 194a8825..229a0249 100644 --- a/modules/collabora_online_group/collabora_online_group.info.yml +++ b/modules/collabora_online_group/collabora_online_group.info.yml @@ -1,6 +1,6 @@ name: Collabora Online Group description: Integrates Collabora Online with Group module -package: Collabora online +package: Collabora Online dependencies: - collabora_online:collabora_online - groupmedia:groupmedia From 5b227bb22eb842958cfb536d9c374e2c4dae1553 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 22 Nov 2024 12:21:05 +0100 Subject: [PATCH 37/53] Issue 52: Add new permission. --- .../CollaboraPermissionProvider.php | 24 +++++++++++-------- .../tests/src/Kernel/PermissionTest.php | 21 +++++++++------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php index f523bdbe..319d27af 100644 --- a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php @@ -23,7 +23,10 @@ public function buildPermissions(): array { // Add Collabora permissions. $prefix = 'Entity:'; if ($name = $provider_chain->getPermission('preview in collabora', 'entity')) { - $permissions[$name] = $this->buildPermission("$prefix Preview %entity_type in collabora"); + $permissions[$name] = $this->buildPermission("$prefix Preview published %entity_type in collabora"); + } + if ($name = $provider_chain->getPermission('preview in collabora', 'entity', 'own')) { + $permissions[$name] = $this->buildPermission("$prefix Preview own unpublished %entity_type in collabora"); } if ($name = $provider_chain->getPermission('edit in collabora', 'entity')) { $permissions[$name] = $this->buildPermission("$prefix Edit any %entity_type in collabora"); @@ -39,20 +42,21 @@ public function buildPermissions(): array { * {@inheritdoc} */ public function getPermission($operation, $target, $scope = 'any'): bool|string { - if ($target === 'entity') { + if ( + $target === 'entity' && + $this->definesEntityPermissions && + ($this->implementsOwnerInterface || $scope === 'any') + ) { switch ($operation) { case 'preview in collabora': + if ($scope === 'own') { + return "preview $scope unpublished $this->pluginId in collabora"; + } + return "preview $this->pluginId in collabora"; case 'edit in collabora': - if ( - $this->definesEntityPermissions && - ($this->implementsOwnerInterface || $scope === 'any') - ) { - return "edit $scope $this->pluginId in collabora"; - } - - return FALSE; + return "edit $scope $this->pluginId in collabora"; } } diff --git a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php index 9baa06ce..4938b508 100644 --- a/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/PermissionTest.php @@ -89,12 +89,13 @@ public function testGroupPermissions(): void { [ 'edit any group_media:document in collabora' => 'Entity: Edit any media item in collabora', 'edit own group_media:document in collabora' => 'Entity: Edit own media item in collabora', - 'preview group_media:document in collabora' => 'Entity: Preview media item in collabora', + 'preview group_media:document in collabora' => 'Entity: Preview published media item in collabora', + 'preview own unpublished group_media:document in collabora' => 'Entity: Preview own unpublished media item in collabora', ], array_map( - fn ($permission) => (string) $permission['title'], + fn($permission) => (string) $permission['title'], $new_permissions_1, - )); + )); // The 'group_2' has 'document' and 'spreadsheet' permissions. $this->assertSame( [ @@ -102,20 +103,22 @@ public function testGroupPermissions(): void { 'edit any group_media:spreadsheet in collabora' => 'Entity: Edit any media item in collabora', 'edit own group_media:document in collabora' => 'Entity: Edit own media item in collabora', 'edit own group_media:spreadsheet in collabora' => 'Entity: Edit own media item in collabora', - 'preview group_media:document in collabora' => 'Entity: Preview media item in collabora', - 'preview group_media:spreadsheet in collabora' => 'Entity: Preview media item in collabora', + 'preview group_media:document in collabora' => 'Entity: Preview published media item in collabora', + 'preview group_media:spreadsheet in collabora' => 'Entity: Preview published media item in collabora', + 'preview own unpublished group_media:document in collabora' => 'Entity: Preview own unpublished media item in collabora', + 'preview own unpublished group_media:spreadsheet in collabora' => 'Entity: Preview own unpublished media item in collabora', ], array_map( - fn ($permission) => (string) $permission['title'], + fn($permission) => (string) $permission['title'], $new_permissions_2, - )); + )); // The 'group_3' doesn't have any new permissions. $this->assertSame( [], array_map( - fn ($permission) => (string) $permission['title'], + fn($permission) => (string) $permission['title'], $new_permissions_3, - )); + )); } } From c8353989e9f1caba6f65139e1106ebe36b6a7203 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Wed, 20 Nov 2024 10:00:35 +0100 Subject: [PATCH 38/53] Issue CollaboraOnline/collabora-drupal#52: Index readability. --- tests/src/Kernel/ViewsLinkFieldsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Kernel/ViewsLinkFieldsTest.php b/tests/src/Kernel/ViewsLinkFieldsTest.php index e561270f..45cb4dd3 100644 --- a/tests/src/Kernel/ViewsLinkFieldsTest.php +++ b/tests/src/Kernel/ViewsLinkFieldsTest.php @@ -137,8 +137,8 @@ protected function doTestLinks(array $expected_results, AccountInterface $accoun ], ]; - $i = 0; // Check each expected results for every media. + $i = 0; foreach (Media::loadMultiple() as $media) { foreach ($expected_results as $operation => $expected_result) { $expected_link = ''; From 50ca212401648f4a568e6d2ad8333a584c4e9577 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 14 Nov 2024 08:23:03 +0100 Subject: [PATCH 39/53] Issue CollaboraOnline/collabora-drupal#52: Replace data provider with array. --- .../tests/src/Kernel/AccessTest.php | 135 ++++++++++++------ 1 file changed, 91 insertions(+), 44 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php index 3f6aac51..892d25f6 100644 --- a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -50,28 +50,15 @@ protected function setUp(): void { /** * Tests that access to Collabora group permissions is handled. - * - * @param bool $expected_result - * The access result. - * @param string[] $permissions - * The global permissions granted to the user. - * @param string[] $group_permissions - * The group permissions granted to the user. - * @param string $operation - * The operation to perform on the entity. - * @param string $scope - * Sets the user as author of the entity. - * - * @dataProvider dataProvider */ - public function testCollaboraAccess(bool $expected_result, array $permissions, array $group_permissions, string $operation, string $scope = ''): void { + public function testCollaboraAccess(): void { // Create group type, media type and enable plugin. $group_type = $this->createGroupType(); - $this->createGroupRole([ + $group_role = $this->createGroupRole([ 'group_type' => $group_type->id(), 'scope' => PermissionScopeInterface::INSIDER_ID, 'global_role' => RoleInterface::AUTHENTICATED_ID, - 'permissions' => $group_permissions + 'permissions' => [], ]); $this->createMediaType('file', ['id' => 'document']); $this->createPluginRelation($group_type, 'group_media:document', [ @@ -85,43 +72,103 @@ public function testCollaboraAccess(bool $expected_result, array $permissions, a $media = $this->createMediaEntity('document'); $group->addRelationship($media, 'group_media:document'); - // Create the user with the given permissions and as member of the group. - $user = $this->createUser($permissions); - $group->addMember($user); + // Iterate over each scenario. + foreach ($this->dataProvider() as $scenario) { + // Set the current permissions for the existing role. + $group_role->set('permissions', $scenario['group_permissions'])->save(); + // Create the user with the given permissions and as member of the group. + $user = $this->createUser($scenario['permissions']); + $group->addMember($user); + // Set user as owner if the scope is 'own'. + $owner = $scenario['scope'] === 'own' ? $user->id() : 0; + $media->setOwnerId($owner)->save(); - if ($scope === 'own') { - $media->setOwnerId($user->id())->save(); + // Check access. + $this->assertEquals($scenario['result'], $media->access($scenario['operation'], $user)); } - - // Check access. - $this->assertEquals($expected_result, $media->access($operation, $user)); } /** * Data provider. * - * @return \Generator + * @return array * The test data. */ - protected function dataProvider(): \Generator { - // Preview: user with no permissions at all. - yield [FALSE, [], [], 'preview in collabora']; - // Preview: user with global permissions doesn't have access. - yield [FALSE, ['preview document in collabora'], [], 'preview in collabora']; - // Preview: user with group permissions have access. - yield [TRUE, [], ['preview group_media:document in collabora'], 'preview in collabora']; - // Edit any: user with no permissions at all. - yield [FALSE, [], [], 'edit in collabora']; - // Edit any: user with global permissions doesn't have access. - yield [FALSE, ['edit any document in collabora'], [], 'edit in collabora']; - // Edit any: User with group permissions have access. - yield [TRUE, [], ['edit any group_media:document in collabora'], 'edit in collabora']; - // Edit own: user with no permissions at all. - yield [FALSE, [], [], 'edit in collabora', 'own']; - // Edit own: user with global permissions doesn't have access. - yield [FALSE, ['edit own document in collabora'], [], 'edit in collabora', 'own' ]; - // Edit own: user with group permissions have access. - yield [TRUE, [], ['edit own group_media:document in collabora'], 'edit in collabora', 'own']; + protected function dataProvider(): array { + return [ + // Preview: user with no permissions at all. + [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => [], + 'operation' => 'preview in collabora', + 'scope' => 'any' + ], + // Preview: user with global permissions doesn't have access. + [ + 'result' => FALSE, + 'permissions' => ['preview document in collabora'], + 'group_permissions' => [], + 'operation' => 'preview in collabora', + 'scope' => 'any' + ], + // Preview: user with group permissions have access. + [ + 'result' => TRUE, + 'permissions' => [], + 'group_permissions' => ['preview group_media:document in collabora'], + 'operation' => 'preview in collabora', + 'scope' => 'any' + ], + // Edit any: user with no permissions at all. + [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => [], + 'operation' => 'edit in collabora', + 'scope' => 'any' + ], + // Edit any: user with global permissions doesn't have access. + [ + 'result' => FALSE, + 'permissions' => ['edit any document in collabora'], + 'group_permissions' => [], + 'operation' => 'edit in collabora', + 'scope' => 'any' + ], + // Edit any: User with group permissions have access. + [ + 'result' => TRUE, + 'permissions' => [], + 'group_permissions' => ['edit any group_media:document in collabora'], + 'operation' => 'edit in collabora', + 'scope' => 'any' + ], + // Edit own: user with no permissions at all. + [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => [], + 'operation' => 'edit in collabora', + 'scope' => 'own' + ], + // Edit own: user with global permissions doesn't have access. + [ + 'result' => FALSE, + 'permissions' => ['edit own document in collabora'], + 'group_permissions' => [], + 'operation' => 'edit in collabora', + 'scope' => 'own' + ], + // Edit own: user with group permissions have access. + [ + 'result' => TRUE, + 'permissions' => [], + 'group_permissions' => ['edit own group_media:document in collabora'], + 'operation' => 'edit in collabora', + 'scope' => 'own' + ], + ]; } } From eabc3b01bc92db1cea5092df6820d06f0ca15dc5 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 7 Nov 2024 18:01:57 +0100 Subject: [PATCH 40/53] Issue CollaboraOnline/collabora-drupal#52: Add patch for group code deprecation. --- .github/workflows/ci.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9b9b992d..21b0b808 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -53,7 +53,8 @@ jobs: - name: Composer install run: | - docker-compose exec -T web composer install --no-interaction + docker-compose exec -T web composer config --merge --json "extra.patches" '{"drupal/group": {"Using a translatable string as a category for field type is deprecated - https://www.drupal.org/project/group/issues/3458530": "https://www.drupal.org/files/issues/2024-07-02/group-translate-string-as-category-is-deprecated_0.patch"}}' + docker-compose exec -T web composer require --dev cweagans/composer-patches - name: PhpCS run: | From aae87b75124c1b1775bc9c16bd1b63bbf9483c39 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 21 Nov 2024 14:02:29 +0100 Subject: [PATCH 41/53] Issue 52: Add new cases to group access test. --- .../tests/src/Kernel/AccessTest.php | 97 +++++++++++++++++-- 1 file changed, 87 insertions(+), 10 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php index d73f6c5c..ee3fc3e1 100644 --- a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -74,6 +74,8 @@ public function testCollaboraAccess(): void { // Iterate over each scenario. foreach ($this->getTestScenarios() as $scenario_name => $scenario) { + // Apply status to media. + $media->set('status', $scenario['status'])->save(); // Set the current permissions for the existing role. $group_role->set('permissions', $scenario['group_permissions'])->save(); // Create the user with the given permissions and as member of the @@ -88,7 +90,7 @@ public function testCollaboraAccess(): void { $this->assertEquals( $scenario['result'], $media->access($scenario['operation'], $user), - sprintf('Access check failed for scenario: %s', $scenario_name) + sprintf('Access check failed for scenario: "%s"', $scenario_name) ); } } @@ -100,70 +102,145 @@ public function testCollaboraAccess(): void { * An array of test scenarios. */ protected function getTestScenarios(): array { + // The scenario keys contains values used for each scenario: + // 'operation:status:scope:global_permission:group_permission'. return [ - 'preview_no_permisions' => [ + 'preview:published:any:::' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => [], 'operation' => 'preview in collabora', + 'status' => 1, 'scope' => 'any', ], - 'preview_global_permisions' => [ + 'preview:published:any:preview::' => [ 'result' => FALSE, 'permissions' => ['preview document in collabora'], 'group_permissions' => [], 'operation' => 'preview in collabora', + 'status' => 1, 'scope' => 'any', ], - 'preview_group_permisions' => [ + 'preview:published:any::preview' => [ 'result' => TRUE, 'permissions' => [], 'group_permissions' => ['preview group_media:document in collabora'], 'operation' => 'preview in collabora', + 'status' => 1, 'scope' => 'any', ], - 'edit_any_no_permisions' => [ + 'preview:published:own::preview' => [ + 'result' => TRUE, + 'permissions' => [], + 'group_permissions' => ['preview group_media:document in collabora'], + 'operation' => 'preview in collabora', + 'status' => 1, + 'scope' => 'own', + ], + 'FAIL preview:unpublished:any::preview' => [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => ['preview group_media:document in collabora'], + 'operation' => 'preview in collabora', + 'status' => 0, + 'scope' => 'any', + ], + 'FAIL preview:unpublished:own::preview' => [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => ['preview group_media:document in collabora'], + 'operation' => 'preview in collabora', + 'status' => 0, + 'scope' => 'own', + ], + 'preview:unpublished:own:preview_own::' => [ + 'result' => FALSE, + 'permissions' => ['preview own unpublished document in collabora'], + 'group_permissions' => [], + 'operation' => 'preview in collabora', + 'status' => 0, + 'scope' => 'own', + ], + 'preview:unpublished:own::preview_own' => [ + 'result' => TRUE, + 'permissions' => [], + 'group_permissions' => ['preview own unpublished group_media:document in collabora'], + 'operation' => 'preview in collabora', + 'status' => 0, + 'scope' => 'own', + ], + 'FAIL preview:published:own::preview_own' => [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => ['preview own unpublished group_media:document in collabora'], + 'operation' => 'preview in collabora', + 'status' => 1, + 'scope' => 'own', + ], + 'edit:published:any:::' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => [], 'operation' => 'edit in collabora', + 'status' => 1, 'scope' => 'any', ], - 'edit_any_global_permisions' => [ + 'edit:published:any:edit_any::' => [ 'result' => FALSE, 'permissions' => ['edit any document in collabora'], 'group_permissions' => [], 'operation' => 'edit in collabora', + 'status' => 1, 'scope' => 'any', ], - 'edit_any_group_permisions' => [ + 'edit:published:any::edit_any' => [ 'result' => TRUE, 'permissions' => [], 'group_permissions' => ['edit any group_media:document in collabora'], 'operation' => 'edit in collabora', + 'status' => 1, 'scope' => 'any', ], - 'edit_own_no_permisions' => [ + 'edit:published:own::edit_any' => [ + 'result' => TRUE, + 'permissions' => [], + 'group_permissions' => ['edit any group_media:document in collabora'], + 'operation' => 'edit in collabora', + 'status' => 1, + 'scope' => 'own', + ], + 'edit:published:own::' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => [], 'operation' => 'edit in collabora', + 'status' => 1, 'scope' => 'own', ], - 'edit_own_global_permisions' => [ + 'edit:published:own:edit_own:' => [ 'result' => FALSE, 'permissions' => ['edit own document in collabora'], 'group_permissions' => [], 'operation' => 'edit in collabora', + 'status' => 1, 'scope' => 'own', ], - 'edit_own_group_permisions' => [ + 'edit:published:own::edit_own' => [ 'result' => TRUE, 'permissions' => [], 'group_permissions' => ['edit own group_media:document in collabora'], 'operation' => 'edit in collabora', + 'status' => 1, 'scope' => 'own', ], + 'edit:published:any::edit_own' => [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => ['edit own group_media:document in collabora'], + 'operation' => 'edit in collabora', + 'status' => 1, + 'scope' => 'any', + ], ]; } From ae5d97dbc75bf9e3e66bd82302d661e97cd4b72c Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 21 Nov 2024 08:31:42 +0100 Subject: [PATCH 42/53] Issue CollaboraOnline/collabora-drupal#52: Test and docs. --- .../tests/src/Functional/GroupMediaViewsTest.php | 2 +- tests/src/Kernel/ViewsLinkFieldsTest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php index a67c6a3e..a6b5f65b 100644 --- a/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php +++ b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php @@ -92,7 +92,7 @@ public function testViewLinks(): void { $this->assertEquals('Bundle', $cols[1]->getText()); $this->assertEquals('Status', $cols[2]->getText()); $this->assertEquals('Publisher', $cols[3]->getText()); - // Support for different vesrions of groupmedia. + // Support different versions of groupmedia. $this->assertTrue(in_array($cols[4]->getText(), ['Operations', 'Dropbutton'])); // Check that rows contain new links for operations in Collabora. diff --git a/tests/src/Kernel/ViewsLinkFieldsTest.php b/tests/src/Kernel/ViewsLinkFieldsTest.php index 45cb4dd3..2aa9e7ef 100644 --- a/tests/src/Kernel/ViewsLinkFieldsTest.php +++ b/tests/src/Kernel/ViewsLinkFieldsTest.php @@ -62,7 +62,6 @@ protected function setUp(): void { // Create two medias to check access with different scopes, 'any' and 'own'. $this->createMediaEntity('document'); $this->ownMedia = $this->createMediaEntity('document'); - ; } /** From 9e7a0c9b89192527e1f53f28244458a427f6742f Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 14 Nov 2024 08:53:31 +0100 Subject: [PATCH 43/53] Issue CollaboraOnline/collabora-drupal#52: Replace matrix with extra step. --- .github/workflows/ci.yaml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e6e3d219..5fc1d6f6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,6 @@ jobs: fail-fast: true matrix: php: [8.1, 8.2, 8.3] - groupmedia: [3, 4] steps: - uses: actions/checkout@v4 @@ -55,7 +54,7 @@ jobs: - name: Composer install run: | docker-compose exec -T web composer config --merge --json "extra.patches" '{"drupal/group": {"Using a translatable string as a category for field type is deprecated - https://www.drupal.org/project/group/issues/3458530": "https://www.drupal.org/files/issues/2024-07-02/group-translate-string-as-category-is-deprecated_0.patch"}}' - docker-compose exec -T web composer require --dev cweagans/composer-patches drupal/groupmedia:~${{ matrix.groupmedia }} + docker-compose exec -T web composer require --dev cweagans/composer-patches - name: PhpCS run: | @@ -66,13 +65,10 @@ jobs: docker-compose exec -T web ./vendor/bin/run drupal:site-install - name: PhpUnit - if: ${{ matrix.groupmedia != '3' }} run: | - docker-compose exec -T web ./vendor/bin/phpunit -vvv --debug + docker-compose exec -T web ./vendor/bin/phpunit -vvv --debug - - name: PhpUnit - if: ${{ matrix.groupmedia == '3' }} + - name: PhpUnit - groupmedia 3 run: | - docker-compose exec -T web ./vendor/bin/phpunit -vvv --debug --testsuite "Collabora Online Group" - - + docker-compose exec -T web composer require --dev drupal/groupmedia:^3 -W + docker-compose exec -T web ./vendor/bin/phpunit -vvv --debug --testsuite "Collabora Online Group" From 748d4dcf6214914ca9dd636d1aaf97355a814ad5 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 8 Nov 2024 08:21:55 +0100 Subject: [PATCH 44/53] Issue CollaboraOnline/collabora-drupal#52: Remove sub-modules installation from runner. --- runner.yml.dist | 2 -- 1 file changed, 2 deletions(-) diff --git a/runner.yml.dist b/runner.yml.dist index 943d0fe5..6eba4d40 100755 --- a/runner.yml.dist +++ b/runner.yml.dist @@ -36,8 +36,6 @@ drupal: - "./vendor/bin/drush -y config-set collabora_online.settings cool.key_id collabora" - "./vendor/bin/drush -y config-set collabora_online.settings cool.access_token_ttl 86400" - "./vendor/bin/drush -y config-set collabora_online.settings cool.disable_cert_check 1" - # Sub-modules. - - "./vendor/bin/drush -y en collabora_online_group" # Create the JWT key. - | From 004f57308c8cfb3bd5a0f0ea7e24f56e186d995b Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 21 Nov 2024 18:31:54 +0100 Subject: [PATCH 45/53] Issue 52: Add access control to set preview operation for unpublished entities. --- .../collabora_online_group.services.yml | 6 ++- .../CollaboraAccessControl.php | 42 +++++++++++++++++++ .../CollaboraPermissionProvider.php | 13 ++++-- .../tests/src/Kernel/AccessTest.php | 6 +-- 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php diff --git a/modules/collabora_online_group/collabora_online_group.services.yml b/modules/collabora_online_group/collabora_online_group.services.yml index 06b6737a..25f25af2 100644 --- a/modules/collabora_online_group/collabora_online_group.services.yml +++ b/modules/collabora_online_group/collabora_online_group.services.yml @@ -2,4 +2,8 @@ services: group.relation_handler.permission_provider.collabora_group_media: class: 'Drupal\collabora_online_group\Plugin\Group\RelationHandler\CollaboraPermissionProvider' decorates: group.relation_handler.permission_provider.group_media - arguments: [ '@group.relation_handler.permission_provider.collabora_group_media.inner' ] + arguments: ["@group.relation_handler.permission_provider.collabora_group_media.inner"] + + group.relation_handler.access_control.group_media: + class: 'Drupal\collabora_online_group\Plugin\Group\RelationHandler\CollaboraAccessControl' + arguments: ["@group.relation_handler.access_control"] diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php new file mode 100644 index 00000000..e2574362 --- /dev/null +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php @@ -0,0 +1,42 @@ +parent = $parent; + } + + /** + * {@inheritdoc} + */ + public function entityAccess(EntityInterface $entity, $operation, AccountInterface $account, $return_as_object = FALSE) { + // Add support for unpublished vs published for "preview in collabora". + $check_published = $operation === 'preview in collabora' && $this->implementsPublishedInterface; + + if ($check_published && !$entity->isPublished()) { + $operation .= ' unpublished'; + } + + return $this->parent->entityAccess($entity, $operation, $account, $return_as_object); + } + +} diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php index 319d27af..8d754ba6 100644 --- a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php @@ -25,7 +25,7 @@ public function buildPermissions(): array { if ($name = $provider_chain->getPermission('preview in collabora', 'entity')) { $permissions[$name] = $this->buildPermission("$prefix Preview published %entity_type in collabora"); } - if ($name = $provider_chain->getPermission('preview in collabora', 'entity', 'own')) { + if ($name = $provider_chain->getPermission('preview in collabora unpublished', 'entity', 'own')) { $permissions[$name] = $this->buildPermission("$prefix Preview own unpublished %entity_type in collabora"); } if ($name = $provider_chain->getPermission('edit in collabora', 'entity')) { @@ -49,11 +49,18 @@ public function getPermission($operation, $target, $scope = 'any'): bool|string ) { switch ($operation) { case 'preview in collabora': - if ($scope === 'own') { + if ($scope === 'any') { + return "preview $this->pluginId in collabora"; + } + + return FALSE; + + case 'preview in collabora unpublished': + if ($this->implementsPublishedInterface && $scope === 'own') { return "preview $scope unpublished $this->pluginId in collabora"; } - return "preview $this->pluginId in collabora"; + return FALSE; case 'edit in collabora': return "edit $scope $this->pluginId in collabora"; diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php index ee3fc3e1..c2d9e6b2 100644 --- a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -137,7 +137,7 @@ protected function getTestScenarios(): array { 'status' => 1, 'scope' => 'own', ], - 'FAIL preview:unpublished:any::preview' => [ + 'preview:unpublished:any::preview' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => ['preview group_media:document in collabora'], @@ -145,7 +145,7 @@ protected function getTestScenarios(): array { 'status' => 0, 'scope' => 'any', ], - 'FAIL preview:unpublished:own::preview' => [ + 'preview:unpublished:own::preview' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => ['preview group_media:document in collabora'], @@ -169,7 +169,7 @@ protected function getTestScenarios(): array { 'status' => 0, 'scope' => 'own', ], - 'FAIL preview:published:own::preview_own' => [ + 'preview:published:own::preview_own' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => ['preview own unpublished group_media:document in collabora'], From 27f759a63f6fe9abbfdb9109b8cc1ec9a9f86a78 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Wed, 20 Nov 2024 17:33:55 +0100 Subject: [PATCH 46/53] Issue CollaboraOnline/collabora-drupal#52: Harcoded entity labels. --- .../tests/src/Functional/GroupMediaViewsTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php index a6b5f65b..b574ba74 100644 --- a/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php +++ b/modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php @@ -43,7 +43,10 @@ class GroupMediaViewsTest extends BrowserTestBase { public function testViewLinks(): void { // Add configuration needed for testing. $group_type = $this->createGroupType(['id' => 'group_type_1']); - $media_type = $this->createMediaType('file', ['id' => 'document']); + $this->createMediaType('file', [ + 'id' => 'document', + 'label' => 'Document', + ]); $this->createGroupRole([ 'group_type' => 'group_type_1', 'scope' => PermissionScopeInterface::INSIDER_ID, @@ -64,7 +67,7 @@ public function testViewLinks(): void { // Create content. $group = $this->createGroup(['type' => 'group_type_1']); - for ($i = 1; $i < 4; $i++) { + for ($i = 0; $i < 3; $i++) { $media = $this->createMediaEntity('document', [ 'id' => 'media_' . $i, 'name' => 'Media ' . $i, @@ -101,8 +104,8 @@ public function testViewLinks(): void { $i = 0; foreach (Media::loadMultiple() as $media) { $cols = $rows[$i]->findAll('css', 'td'); - $this->assertEquals($media->getName(), $cols[0]->getText()); - $this->assertEquals($media_type->label(), $cols[1]->getText()); + $this->assertEquals('Media ' . $i, $cols[0]->getText()); + $this->assertEquals('Document', $cols[1]->getText()); $this->assertEquals('Yes', $cols[2]->getText()); $this->assertEquals('Anonymous', $cols[3]->getText()); $operation_links = $cols[4]->findAll('css', 'a'); From faafe5a56092b764cb541cd6ab3c3fd674ba44d8 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 14 Nov 2024 13:22:32 +0100 Subject: [PATCH 47/53] Issue CollaboraOnline/collabora-drupal#52: Improve access test failure description. --- .../tests/src/Kernel/AccessTest.php | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php index 892d25f6..866e9b51 100644 --- a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -73,7 +73,7 @@ public function testCollaboraAccess(): void { $group->addRelationship($media, 'group_media:document'); // Iterate over each scenario. - foreach ($this->dataProvider() as $scenario) { + foreach ($this->getTestScenarios() as $scenario_name => $scenario) { // Set the current permissions for the existing role. $group_role->set('permissions', $scenario['group_permissions'])->save(); // Create the user with the given permissions and as member of the group. @@ -84,84 +84,79 @@ public function testCollaboraAccess(): void { $media->setOwnerId($owner)->save(); // Check access. - $this->assertEquals($scenario['result'], $media->access($scenario['operation'], $user)); + $this->assertEquals( + $scenario['result'], + $media->access($scenario['operation'], $user), + sprintf('Access check failed for scenario: %s', $scenario_name) + ); } } /** - * Data provider. + * Retrieves the scenarios to be tested. * * @return array - * The test data. + * An array of test scenarios. */ - protected function dataProvider(): array { + protected function getTestScenarios(): array { return [ - // Preview: user with no permissions at all. - [ + 'preview_no_permisions' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => [], 'operation' => 'preview in collabora', 'scope' => 'any' ], - // Preview: user with global permissions doesn't have access. - [ + 'preview_global_permisions' => [ 'result' => FALSE, 'permissions' => ['preview document in collabora'], 'group_permissions' => [], 'operation' => 'preview in collabora', 'scope' => 'any' ], - // Preview: user with group permissions have access. - [ + 'preview_group_permisions' =>[ 'result' => TRUE, 'permissions' => [], 'group_permissions' => ['preview group_media:document in collabora'], 'operation' => 'preview in collabora', 'scope' => 'any' ], - // Edit any: user with no permissions at all. - [ + 'edit_any_no_permisions' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => [], 'operation' => 'edit in collabora', 'scope' => 'any' ], - // Edit any: user with global permissions doesn't have access. - [ + 'edit_any_global_permisions' => [ 'result' => FALSE, 'permissions' => ['edit any document in collabora'], 'group_permissions' => [], 'operation' => 'edit in collabora', 'scope' => 'any' ], - // Edit any: User with group permissions have access. - [ + 'edit_any_group_permisions' => [ 'result' => TRUE, 'permissions' => [], 'group_permissions' => ['edit any group_media:document in collabora'], 'operation' => 'edit in collabora', 'scope' => 'any' ], - // Edit own: user with no permissions at all. - [ + 'edit_own_no_permisions' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => [], 'operation' => 'edit in collabora', 'scope' => 'own' ], - // Edit own: user with global permissions doesn't have access. - [ + 'edit_own_global_permisions' => [ 'result' => FALSE, 'permissions' => ['edit own document in collabora'], 'group_permissions' => [], 'operation' => 'edit in collabora', 'scope' => 'own' ], - // Edit own: user with group permissions have access. - [ + 'edit_own_group_permisions' => [ 'result' => TRUE, 'permissions' => [], 'group_permissions' => ['edit own group_media:document in collabora'], From 5162dd8fb00b56fb1839c5fb70997b6031666c19 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 22 Nov 2024 14:00:24 +0100 Subject: [PATCH 48/53] Issue 52: Add submodule readme and reference in parent. --- README.md | 17 ++++++++++---- modules/collabora_online_group/README.md | 30 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 modules/collabora_online_group/README.md diff --git a/README.md b/README.md index 83c72505..449dd57b 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Minimal steps to see the editor in action: Advanced usage: - Configure roles and permissions as in "User permissions" section below. -- Create a non-admin user with sufficient roles, login, +- Create a non-admin user with sufficient roles, login, ### Running the tests @@ -198,19 +198,19 @@ not needed, if the Collabora instance is configured from outside of Drupal. For each media type, the module introduces four permissions: -- "(media type): Edit any media file in Collabora" +- "(media type): Edit any media file in Collabora" Users with this permission are allowed to edit documents attached to a media entity of the given type, using the Collabora Online editor. -- "(media type): Edit own media file in Collabora" +- "(media type): Edit own media file in Collabora" Users with this permission are allowed to edit documents attached to a media entity of the given type, using the Collabora Online editor, if they are the owner/author of that media entity. -- "(media type): Preview published media file in Collabora" +- "(media type): Preview published media file in Collabora" Users with this permission are allowed to preview documents attached to a published media entity of the given type, using the Collabora Online editor in preview/readonly mode. -- "(media type): Preview own unpublished media file in Collabora" +- "(media type): Preview own unpublished media file in Collabora" Users with this permission are allowed to preview documents attached to an unpublished media entity of the given type, using the Collabora Online editor in preview/readonly mode. @@ -246,6 +246,13 @@ upload_max_filesize = 30M These set the limits to a maximum of 30M. You can change as appropriate. +Sub-modules +------------- + +### Collabora Online Group + +Integration of Collabora Online with Group module. Check out the [README](/modules/collabora_online_group/README.md) of the module. + License ------- diff --git a/modules/collabora_online_group/README.md b/modules/collabora_online_group/README.md new file mode 100644 index 00000000..2604815e --- /dev/null +++ b/modules/collabora_online_group/README.md @@ -0,0 +1,30 @@ +Collabora Online Group +===================================== + +This submodule integrates the Group module (https://www.drupal.org/project/group) by managing group-related permissions. It allows fine-grained control over user access within groups, enabling specific permissions for Collabora content and actions based on group membership. + +### Requirements + +- Groupmedia module: https://www.drupal.org/project/groupmedia + - Compatible with versions 3.x and 4.x. + +### User permissions + +The module maps existing Collabora media operation permissions to the group type instances. + +#### Permissions: +- "(media type): Edit any media file in Collabora" +- "(media type): Edit own media file in Collabora" +- "(media type): Preview published media file in Collabora" +- "(media type): Preview own unpublished media file in Collabora" + +Check [Collabora Online README](/README.md#user-permissions) for more information about permissions. + +### Views + +Additionally, the submodule modifies Groupmedia view configuration to add links for Collabora operations. + +License +------- + +This module is published under the MPL-2.0 license. From 134a14c64171fc573877885cb7cf0633de704636 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 22 Nov 2024 09:32:13 +0100 Subject: [PATCH 49/53] Issue 52: Add access check for links in view. --- .../views.view.test_collabora_links.yml | 31 +++++----- tests/src/Kernel/ViewsLinkFieldsTest.php | 58 ++++++++++++------- 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml b/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml index 7f79189b..bb423faf 100644 --- a/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml +++ b/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml @@ -199,27 +199,30 @@ display: sort_asc_label: Asc sort_desc_label: Desc access: - type: perm - options: - perm: "view media" + type: none + options: { } cache: type: tag options: {} empty: {} - sorts: {} - arguments: {} - filters: - status: - id: status + sorts: + mid: + id: mid table: media_field_data - field: status + field: mid + relationship: none + group_type: group + admin_label: '' entity_type: media - entity_field: status - plugin_id: boolean - value: "1" - group: 1 + entity_field: mid + plugin_id: standard + order: ASC expose: - operator: "" + label: '' + field_identifier: '' + exposed: false + arguments: {} + filters: {} style: type: default options: diff --git a/tests/src/Kernel/ViewsLinkFieldsTest.php b/tests/src/Kernel/ViewsLinkFieldsTest.php index e7dc336d..10c4cbc2 100644 --- a/tests/src/Kernel/ViewsLinkFieldsTest.php +++ b/tests/src/Kernel/ViewsLinkFieldsTest.php @@ -22,13 +22,6 @@ class ViewsLinkFieldsTest extends KernelTestBase { use MediaCreationTrait; use MediaTypeCreationTrait; - /** - * Media owned by current user. - * - * @var \Drupal\media\MediaInterface - */ - protected $ownMedia = NULL; - /** * {@inheritdoc} */ @@ -58,10 +51,6 @@ protected function setUp(): void { // Install user module to avoid user 1 permissions bypass. \Drupal::moduleHandler()->loadInclude('user', 'install'); user_install(); - - // Create two medias to check access with different scopes: any and own. - $this->createMediaEntity('document'); - $this->ownMedia = $this->createMediaEntity('document'); } /** @@ -71,26 +60,37 @@ public function testLinks(): void { // User without permissions can't see links. $this->doTestLinks( [ - 'preview' => [FALSE, FALSE], - 'edit' => [FALSE, FALSE], + 'preview' => [FALSE, FALSE, FALSE, FALSE], + 'edit' => [FALSE, FALSE, FALSE, FALSE], ], $this->createUser([]) ); // User with 'Preview' permission can see preview link. $this->doTestLinks( [ - 'preview' => [TRUE, TRUE], - 'edit' => [FALSE, FALSE], + 'preview' => [TRUE, FALSE, TRUE, FALSE], + 'edit' => [FALSE, FALSE, FALSE, FALSE], ], $this->createUser([ 'preview document in collabora', ]) ); + // User with 'Preview own unpublished' permission can see preview link + // for unpublished entity they own. + $this->doTestLinks( + [ + 'preview' => [FALSE, FALSE, FALSE, TRUE], + 'edit' => [FALSE, FALSE, FALSE, FALSE], + ], + $this->createUser([ + 'preview own unpublished document in collabora', + ]) + ); // User with 'Edit any' permission can see edit link. $this->doTestLinks( [ - 'preview' => [FALSE, FALSE], - 'edit' => [TRUE, TRUE], + 'preview' => [FALSE, FALSE, FALSE, FALSE], + 'edit' => [TRUE, TRUE, TRUE, TRUE], ], $this->createUser([ 'edit any document in collabora', @@ -100,8 +100,8 @@ public function testLinks(): void { // own. $this->doTestLinks( [ - 'preview' => [FALSE, FALSE], - 'edit' => [FALSE, TRUE], + 'preview' => [FALSE, FALSE, FALSE, FALSE], + 'edit' => [FALSE, FALSE, TRUE, TRUE], ], $this->createUser([ 'edit own document in collabora', @@ -119,8 +119,22 @@ public function testLinks(): void { */ protected function doTestLinks(array $expected_results, AccountInterface $account): void { $this->setCurrentUser($account); - // Set the current user as the owner to check 'edit own' access. - $this->ownMedia->setOwnerId($account->id())->save(); + // Create medias: cover all combinations of status and ownership. + $this->createMediaEntity('document', [ + 'uid' => $this->createUser(), + ]); + $this->createMediaEntity('document', [ + 'uid' => $this->createUser(), + 'status' => 0, + ]); + $this->createMediaEntity('document', [ + 'uid' => $account->id(), + ]); + $this->createMediaEntity('document', [ + 'uid' => $account->id(), + 'status' => 0, + ]); + $view = Views::getView('test_collabora_links'); $view->preview(); @@ -152,6 +166,8 @@ protected function doTestLinks(array $expected_results, AccountInterface $accoun $this->assertEquals($expected_link, (string) $link); } $i++; + // Clean medias as we check results. + $media->delete(); } } From b9b9eef5b1d11ba4393e4f41b623b019a5049d68 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 21 Nov 2024 08:47:54 +0100 Subject: [PATCH 50/53] Issue CollaboraOnline/collabora-drupal#52: Add default label. --- src/Plugin/views/field/CollaboraEdit.php | 29 ++++++++++++------- src/Plugin/views/field/CollaboraPreview.php | 29 ++++++++++++------- .../views.view.test_collabora_links.yml | 4 +-- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/Plugin/views/field/CollaboraEdit.php b/src/Plugin/views/field/CollaboraEdit.php index 56bedf4c..92bc2bd7 100644 --- a/src/Plugin/views/field/CollaboraEdit.php +++ b/src/Plugin/views/field/CollaboraEdit.php @@ -5,6 +5,7 @@ namespace Drupal\collabora_online\Plugin\views\field; use Drupal\collabora_online\Cool\CoolUtils; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; use Drupal\views\Attribute\ViewsField; use Drupal\views\Plugin\views\field\LinkBase; @@ -18,18 +19,24 @@ #[ViewsField('media_collabora_edit')] class CollaboraEdit extends LinkBase { - /** - * {@inheritdoc} - */ - protected function getUrlInfo(ResultRow $row): Url|null { - /** @var \Drupal\media\MediaInterface $entity */ - $entity = $this->getEntity($row); + /** + * {@inheritdoc} + */ + protected function getUrlInfo(ResultRow $row): Url|null { + /** @var \Drupal\media\MediaInterface $entity */ + $entity = $this->getEntity($row); - if ($entity === NULL) { - return NULL; - } + if ($entity === NULL) { + return NULL; + } - return CoolUtils::getEditorUrl($entity, TRUE); - } + return CoolUtils::getEditorUrl($entity, TRUE); + } + /** + * {@inheritdoc} + */ + protected function getDefaultLabel(): TranslatableMarkup { + return $this->t('Edit in Collabora Online'); + } } diff --git a/src/Plugin/views/field/CollaboraPreview.php b/src/Plugin/views/field/CollaboraPreview.php index a0d24411..e93817f9 100644 --- a/src/Plugin/views/field/CollaboraPreview.php +++ b/src/Plugin/views/field/CollaboraPreview.php @@ -5,6 +5,7 @@ namespace Drupal\collabora_online\Plugin\views\field; use Drupal\collabora_online\Cool\CoolUtils; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; use Drupal\views\Attribute\ViewsField; use Drupal\views\Plugin\views\field\LinkBase; @@ -18,18 +19,24 @@ #[ViewsField('media_collabora_preview')] class CollaboraPreview extends LinkBase { - /** - * {@inheritdoc} - */ - protected function getUrlInfo(ResultRow $row): Url|null { - /** @var \Drupal\media\MediaInterface $entity */ - $entity = $this->getEntity($row); + /** + * {@inheritdoc} + */ + protected function getUrlInfo(ResultRow $row): Url|null { + /** @var \Drupal\media\MediaInterface $entity */ + $entity = $this->getEntity($row); - if ($entity === NULL) { - return NULL; - } + if ($entity === NULL) { + return NULL; + } - return CoolUtils::getEditorUrl($entity, FALSE); - } + return CoolUtils::getEditorUrl($entity, FALSE); + } + /** + * {@inheritdoc} + */ + protected function getDefaultLabel(): TranslatableMarkup { + return $this->t('View in Collabora Online'); + } } diff --git a/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml b/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml index 58fd87ac..7f79189b 100644 --- a/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml +++ b/tests/modules/collabora_online_test/config/optional/views.view.test_collabora_links.yml @@ -117,7 +117,7 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - text: "View in Collabora Online" + text: "" collabora_edit: id: collabora_edit table: media @@ -168,7 +168,7 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - text: "Edit in Collabora Online" + text: "" pager: type: mini options: From fa1d808dcb0dc7ca2f9625dafa386979c989f5e1 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 22 Nov 2024 15:24:16 +0100 Subject: [PATCH 51/53] Issue 52: Reference to view on main. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 449dd57b..8043f684 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,14 @@ Developers can use entity access hooks to alter which users may edit or preview media files in Collabora. This would allow to grant access based on e.g. membership in a group. +### Views + +The module integrates with Views by providing links as view fields, allowing +users to perform specific operations on documents directly from the view display. + +These operations include actions such as "preview" and "edit," which can be +easily accessed through the generated links. + ### Other configuration If you need to change the accepted extensions to upload, go to From 4a47fe58df40c7fe230d41c7b6243cb672b2fd24 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 22 Nov 2024 10:46:20 +0100 Subject: [PATCH 52/53] Issue 52: Add more cases to access check and improve docs. --- .../CollaboraAccessControl.php | 9 +- .../tests/src/Kernel/AccessTest.php | 123 +++++++++++++++--- 2 files changed, 110 insertions(+), 22 deletions(-) diff --git a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php index e2574362..3694007f 100644 --- a/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php +++ b/modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php @@ -1,7 +1,10 @@ implementsPublishedInterface; if ($check_published && !$entity->isPublished()) { diff --git a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php index c2d9e6b2..b4d6e231 100644 --- a/modules/collabora_online_group/tests/src/Kernel/AccessTest.php +++ b/modules/collabora_online_group/tests/src/Kernel/AccessTest.php @@ -105,7 +105,8 @@ protected function getTestScenarios(): array { // The scenario keys contains values used for each scenario: // 'operation:status:scope:global_permission:group_permission'. return [ - 'preview:published:any:::' => [ + // Preview no permissions cases. + 'preview:published:any::' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => [], @@ -113,7 +114,17 @@ protected function getTestScenarios(): array { 'status' => 1, 'scope' => 'any', ], - 'preview:published:any:preview::' => [ + 'preview:published:own::' => [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => [], + 'operation' => 'preview in collabora', + 'status' => 1, + 'scope' => 'own', + ], + // The global permissions that would allow to preview, doesn't work + // in a media related to a group. + 'preview:published:any:preview:' => [ 'result' => FALSE, 'permissions' => ['preview document in collabora'], 'group_permissions' => [], @@ -121,6 +132,16 @@ protected function getTestScenarios(): array { 'status' => 1, 'scope' => 'any', ], + 'preview:published:own:preview:' => [ + 'result' => FALSE, + 'permissions' => ['preview document in collabora'], + 'group_permissions' => [], + 'operation' => 'preview in collabora', + 'status' => 1, + 'scope' => 'own', + ], + // User can only see published entities with the group preview + // permission. 'preview:published:any::preview' => [ 'result' => TRUE, 'permissions' => [], @@ -153,7 +174,9 @@ protected function getTestScenarios(): array { 'status' => 0, 'scope' => 'own', ], - 'preview:unpublished:own:preview_own::' => [ + // The global preview unpublished doesn't affect to medias related + // to a group. + 'preview:unpublished:own:preview_own_unpublished:' => [ 'result' => FALSE, 'permissions' => ['preview own unpublished document in collabora'], 'group_permissions' => [], @@ -161,7 +184,25 @@ protected function getTestScenarios(): array { 'status' => 0, 'scope' => 'own', ], - 'preview:unpublished:own::preview_own' => [ + // The group permission to preview own unpublished permission allows + // to see only entities with such properties. + 'preview:published:any::preview_own_unpublished' => [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => ['preview own unpublished group_media:document in collabora'], + 'operation' => 'preview in collabora', + 'status' => 1, + 'scope' => 'any', + ], + 'preview:published:own::preview_own_unpublished' => [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => ['preview own unpublished group_media:document in collabora'], + 'operation' => 'preview in collabora', + 'status' => 1, + 'scope' => 'own', + ], + 'preview:unpublished:own::preview_own_unpublished' => [ 'result' => TRUE, 'permissions' => [], 'group_permissions' => ['preview own unpublished group_media:document in collabora'], @@ -169,15 +210,16 @@ protected function getTestScenarios(): array { 'status' => 0, 'scope' => 'own', ], - 'preview:published:own::preview_own' => [ + 'preview:unpublished:any::preview_own_unpublished' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => ['preview own unpublished group_media:document in collabora'], 'operation' => 'preview in collabora', - 'status' => 1, - 'scope' => 'own', + 'status' => 0, + 'scope' => 'any', ], - 'edit:published:any:::' => [ + // Edit no permissions cases. + 'edit:published:any::' => [ 'result' => FALSE, 'permissions' => [], 'group_permissions' => [], @@ -185,7 +227,16 @@ protected function getTestScenarios(): array { 'status' => 1, 'scope' => 'any', ], - 'edit:published:any:edit_any::' => [ + 'edit:published:own::' => [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => [], + 'operation' => 'edit in collabora', + 'status' => 1, + 'scope' => 'own', + ], + // The global permission doesn't grant access to edit in a group. + 'edit:published:any:edit_any:' => [ 'result' => FALSE, 'permissions' => ['edit any document in collabora'], 'group_permissions' => [], @@ -193,6 +244,23 @@ protected function getTestScenarios(): array { 'status' => 1, 'scope' => 'any', ], + 'edit:published:own:edit_any:' => [ + 'result' => FALSE, + 'permissions' => ['edit any document in collabora'], + 'group_permissions' => [], + 'operation' => 'edit in collabora', + 'status' => 1, + 'scope' => 'own', + ], + 'edit:published:own:edit_own:' => [ + 'result' => FALSE, + 'permissions' => ['edit own document in collabora'], + 'group_permissions' => [], + 'operation' => 'edit in collabora', + 'status' => 1, + 'scope' => 'own', + ], + // Only users with edit any permission in a group can edit all. 'edit:published:any::edit_any' => [ 'result' => TRUE, 'permissions' => [], @@ -209,22 +277,23 @@ protected function getTestScenarios(): array { 'status' => 1, 'scope' => 'own', ], - 'edit:published:own::' => [ - 'result' => FALSE, + 'edit:unpublished:any::edit_any' => [ + 'result' => TRUE, 'permissions' => [], - 'group_permissions' => [], + 'group_permissions' => ['edit any group_media:document in collabora'], 'operation' => 'edit in collabora', - 'status' => 1, - 'scope' => 'own', + 'status' => 0, + 'scope' => 'any', ], - 'edit:published:own:edit_own:' => [ - 'result' => FALSE, - 'permissions' => ['edit own document in collabora'], - 'group_permissions' => [], + 'edit:unpublished:own::edit_any' => [ + 'result' => TRUE, + 'permissions' => [], + 'group_permissions' => ['edit any group_media:document in collabora'], 'operation' => 'edit in collabora', - 'status' => 1, + 'status' => 0, 'scope' => 'own', ], + // Or edit own permission for the entities the user owns. 'edit:published:own::edit_own' => [ 'result' => TRUE, 'permissions' => [], @@ -233,6 +302,14 @@ protected function getTestScenarios(): array { 'status' => 1, 'scope' => 'own', ], + 'edit:unpublished:own::edit_own' => [ + 'result' => TRUE, + 'permissions' => [], + 'group_permissions' => ['edit own group_media:document in collabora'], + 'operation' => 'edit in collabora', + 'status' => 0, + 'scope' => 'own', + ], 'edit:published:any::edit_own' => [ 'result' => FALSE, 'permissions' => [], @@ -241,6 +318,14 @@ protected function getTestScenarios(): array { 'status' => 1, 'scope' => 'any', ], + 'edit:unpublished:any::edit_own' => [ + 'result' => FALSE, + 'permissions' => [], + 'group_permissions' => ['edit own group_media:document in collabora'], + 'operation' => 'edit in collabora', + 'status' => 0, + 'scope' => 'any', + ], ]; } From e2091f8b18696af66a381df8a6dfad9480260c54 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Fri, 22 Nov 2024 15:30:28 +0100 Subject: [PATCH 53/53] Issue 52: Break lines. --- modules/collabora_online_group/README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/collabora_online_group/README.md b/modules/collabora_online_group/README.md index 2604815e..a3a9c62d 100644 --- a/modules/collabora_online_group/README.md +++ b/modules/collabora_online_group/README.md @@ -1,7 +1,10 @@ Collabora Online Group ===================================== -This submodule integrates the Group module (https://www.drupal.org/project/group) by managing group-related permissions. It allows fine-grained control over user access within groups, enabling specific permissions for Collabora content and actions based on group membership. +This submodule integrates the Group module (https://www.drupal.org/project/group) +by managing group-related permissions. It allows fine-grained control over user +access within groups, enabling specific permissions for Collabora content and +actions based on group membership. ### Requirements @@ -10,7 +13,8 @@ This submodule integrates the Group module (https://www.drupal.org/project/group ### User permissions -The module maps existing Collabora media operation permissions to the group type instances. +The module maps existing Collabora media operation permissions to the group type +instances. #### Permissions: - "(media type): Edit any media file in Collabora" @@ -22,7 +26,8 @@ Check [Collabora Online README](/README.md#user-permissions) for more informatio ### Views -Additionally, the submodule modifies Groupmedia view configuration to add links for Collabora operations. +Additionally, the submodule modifies Groupmedia view configuration to add links +for Collabora operations. License -------