Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

(obsolete) Issue #52: Group integration #63

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d10142f
Issue CollaboraOnline/collabora-drupal#52: Add links to operations.
AaronGilMartinez Nov 12, 2024
2d8a43d
Issue CollaboraOnline/collabora-drupal#52: Add view field links test.
AaronGilMartinez Nov 12, 2024
906b323
Issue CollaboraOnline/collabora-drupal#52: Override groupmedia view.
AaronGilMartinez Nov 15, 2024
4efedb7
Issue CollaboraOnline/collabora-drupal#52: Add test to check changes …
AaronGilMartinez Nov 18, 2024
e09542f
Issue CollaboraOnline/collabora-drupal#52: Add services.
AaronGilMartinez Nov 7, 2024
43b18da
Issue CollaboraOnline/collabora-drupal#52: Support for groupmedia 3 a…
AaronGilMartinez Nov 18, 2024
d396dff
Issue CollaboraOnline/collabora-drupal#52: Add permissions test.
AaronGilMartinez Nov 14, 2024
f2221cf
Issue CollaboraOnline/collabora-drupal#52: Replace config with view d…
AaronGilMartinez Nov 18, 2024
1a2c928
Issue CollaboraOnline/collabora-drupal#52: Add title content check.
AaronGilMartinez Nov 8, 2024
f8a3fb2
Issue CollaboraOnline/collabora-drupal#52: Supoprt for different vers…
AaronGilMartinez Nov 18, 2024
55d8bdb
Issue CollaboraOnline/collabora-drupal#52: Permission count check.
AaronGilMartinez Nov 8, 2024
4daa2b4
Issue CollaboraOnline/collabora-drupal#52: Code formatting and docume…
AaronGilMartinez Nov 19, 2024
6973e1d
Issue CollaboraOnline/collabora-drupal#52: Fix getPermissions method.
AaronGilMartinez Nov 8, 2024
69da350
Issue CollaboraOnline/collabora-drupal#52: Change field label.
AaronGilMartinez Nov 19, 2024
da09350
Issue CollaboraOnline/collabora-drupal#52: Add access test.
AaronGilMartinez Nov 8, 2024
672e496
Issue CollaboraOnline/collabora-drupal#52: Early return for module is…
AaronGilMartinez Nov 19, 2024
b9f889d
Issue CollaboraOnline/collabora-drupal#52: Add access test cases and …
AaronGilMartinez Nov 22, 2024
b5945a2
Issue CollaboraOnline/collabora-drupal#52: Module is syncing.
AaronGilMartinez Nov 19, 2024
753b71b
Issue CollaboraOnline/collabora-drupal#52: Remove unneeded service.
AaronGilMartinez Nov 11, 2024
36cf0d5
Issue CollaboraOnline/collabora-drupal#52: Missing docs.
AaronGilMartinez Nov 19, 2024
ad4e015
Issue CollaboraOnline/collabora-drupal#52: Remove unused class.
AaronGilMartinez Nov 11, 2024
95320c3
Issue CollaboraOnline/collabora-drupal#52: Rename views test.
AaronGilMartinez Nov 19, 2024
d54227f
Issue CollaboraOnline/collabora-drupal#52: Add support for groupmedia…
AaronGilMartinez Nov 11, 2024
69c1c5c
Issue CollaboraOnline/collabora-drupal#52: PHP attributes for plugin.
AaronGilMartinez Nov 20, 2024
50bca09
Issue CollaboraOnline/collabora-drupal#52: Fix tests.
AaronGilMartinez Nov 11, 2024
71a5aee
Issue CollaboraOnline/collabora-drupal#52: Remove named parameter.
AaronGilMartinez Nov 19, 2024
7d9ed8b
Issue CollaboraOnline/collabora-drupal#52: Documentation improvements.
AaronGilMartinez Nov 12, 2024
63efe62
Issue CollaboraOnline/collabora-drupal#52: Add module.
AaronGilMartinez Nov 7, 2024
a33a572
Issue 52: Fix sniffer errors.
AaronGilMartinez Nov 21, 2024
1054eec
Issue CollaboraOnline/collabora-drupal#52: Drop version function.
AaronGilMartinez Nov 20, 2024
1c55690
Issue CollaboraOnline/collabora-drupal#52: Refactor permissions check.
AaronGilMartinez Nov 12, 2024
4a5ab78
Issue CollaboraOnline/collabora-drupal#52: Add smoke test for sub-mod…
AaronGilMartinez Nov 7, 2024
9c31b2b
Issue 52: Use media creation trait.
AaronGilMartinez Nov 21, 2024
bc7eca7
Issue CollaboraOnline/collabora-drupal#52: Change preview links label.
AaronGilMartinez Nov 20, 2024
1be3dd8
Issue CollaboraOnline/collabora-drupal#52: Code documentation improve…
AaronGilMartinez Nov 13, 2024
c41f6cc
Issue CollaboraOnline/collabora-drupal#52: Capitalise package.
AaronGilMartinez Nov 7, 2024
9b5817e
Issue 52: Add new permission.
AaronGilMartinez Nov 22, 2024
2ee4e9c
Issue CollaboraOnline/collabora-drupal#52: Index readability.
AaronGilMartinez Nov 20, 2024
8b52fe2
Issue CollaboraOnline/collabora-drupal#52: Replace data provider with…
AaronGilMartinez Nov 14, 2024
e141e4d
Issue CollaboraOnline/collabora-drupal#52: Add patch for group code d…
AaronGilMartinez Nov 7, 2024
5ffe31d
Issue 52: Add new cases to group access test.
AaronGilMartinez Nov 21, 2024
9385ed1
Issue CollaboraOnline/collabora-drupal#52: Test and docs.
AaronGilMartinez Nov 21, 2024
886df05
Issue CollaboraOnline/collabora-drupal#52: Replace matrix with extra …
AaronGilMartinez Nov 14, 2024
b0751e1
Issue CollaboraOnline/collabora-drupal#52: Remove sub-modules install…
AaronGilMartinez Nov 8, 2024
e5045ca
Issue 52: Add access control to set preview operation for unpublished…
AaronGilMartinez Nov 21, 2024
d5bf485
Issue CollaboraOnline/collabora-drupal#52: Harcoded entity labels.
AaronGilMartinez Nov 20, 2024
140647a
Issue CollaboraOnline/collabora-drupal#52: Improve access test failur…
AaronGilMartinez Nov 14, 2024
ab13218
Merge pull request #8 from donquixote/group-integration-module
brummbar Nov 8, 2024
d03ee07
Issue 52: Add submodule readme and reference in parent.
AaronGilMartinez Nov 22, 2024
f6140c2
Issue 52: Add access check for links in view.
AaronGilMartinez Nov 22, 2024
c67b05d
Issue CollaboraOnline/collabora-drupal#52: Add default label.
AaronGilMartinez Nov 21, 2024
88ce891
Merge pull request #10 from donquixote/group-integration-services
donquixote Nov 14, 2024
13f3492
Issue 52: Reference to view on main.
AaronGilMartinez Nov 22, 2024
54896cf
Issue 52: Add more cases to access check and improve docs.
AaronGilMartinez Nov 22, 2024
9ee8c7e
Merge pull request #13 from donquixote/group-integration-links
donquixote Nov 21, 2024
3bdb834
Issue 52: Break lines.
AaronGilMartinez Nov 22, 2024
b98ff53
Merge pull request #15 from donquixote/group-unpublished-permissions
AaronGilMartinez Nov 25, 2024
05db794
Merge pull request #17 from donquixote/group-documentation
AaronGilMartinez Nov 25, 2024
03b9f61
Restore line breaks in README.md.
donquixote Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -66,3 +67,8 @@ jobs:
- name: PhpUnit
run: |
docker-compose exec -T web ./vendor/bin/phpunit -vvv --debug

- name: PhpUnit - groupmedia 3
run: |
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"
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -246,6 +254,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
-------

Expand Down
2 changes: 1 addition & 1 deletion collabora_online.info.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 28 additions & 0 deletions collabora_online.views.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* @file
* Provide views data for collabora_online.module.
*/

declare(strict_types=1);

/**
* Implements hook_views_data_alter().
*/
function collabora_online_views_data_alter(array &$data): void {
$data['media']['collabora_preview'] = [
'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 Online'),
'group' => t('Media'),
'field' => [
'id' => 'media_collabora_edit',
],
];
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "^3 || ^4",
"drush/drush": "^12.4",
"openeuropa/task-runner": "^2@dev",
"openeuropa/task-runner-drupal-project-symlink": "^1.0.0-beta6",
Expand Down
12 changes: 12 additions & 0 deletions config/schema/collabora_online.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ collabora_online.settings:
allowfullscreen:
type: boolean
label: 'Allow full-screen.'

views.field.media_collabora_preview:
type: views_field
label: 'Collabora view link'
mapping:
text:
type: label
label: 'Text to display'

views.field.media_collabora_edit:
type: views.field.media_collabora_preview
label: 'Collabora edit link'
35 changes: 35 additions & 0 deletions modules/collabora_online_group/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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.
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions modules/collabora_online_group/collabora_online_group.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* @file
* Install, update and uninstall functions for collabora_online_group.
*/

use Drupal\views\Entity\View;

/**
* Implements hook_install().
*/
function collabora_online_group_install(bool $is_syncing): void {
if (
$is_syncing ||
!\Drupal::moduleHandler()->moduleExists('views') ||
!($view = View::load('group_media'))
) {
return;
}

// 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('View in Collabora Online'),
],
];
$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 Online'),
],
];
// 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',
'collabora_edit' => 'collabora_edit',
];
unset($display['display_options']['fields']['dropbutton']);
$display['display_options']['fields']['dropbutton'] = $dropbutton;

$view->save();
}
Original file line number Diff line number Diff line change
@@ -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.access_control.group_media:
class: 'Drupal\collabora_online_group\Plugin\Group\RelationHandler\CollaboraAccessControl'
arguments: ["@group.relation_handler.access_control"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Drupal\collabora_online_group\Plugin\Group\RelationHandler;

use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\group\Plugin\Group\RelationHandler\AccessControlInterface;
use Drupal\group\Plugin\Group\RelationHandler\AccessControlTrait;
use Drupal\group\Plugin\Group\RelationHandlerDefault\AccessControl;

/**
* Provides access control for collabora group.
*/
class CollaboraAccessControl extends AccessControl {

use AccessControlTrait;

/**
* Constructs a new CollaboraAccessControl.
*
* @param \Drupal\group\Plugin\Group\RelationHandler\AccessControlInterface $parent
* The default access control.
*/
public function __construct(AccessControlInterface $parent) {
$this->parent = $parent;
}

/**
* {@inheritdoc}
*/
public function entityAccess(EntityInterface $entity, $operation, AccountInterface $account, $return_as_object = FALSE): AccessResultInterface|bool {
// Add support for unpublished operation: 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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace Drupal\collabora_online_group\Plugin\Group\RelationHandler;

use Drupal\groupmedia\Plugin\Group\RelationHandler\GroupMediaPermissionProvider;

/**
* Provides Collabora permissions for group.
*/
class CollaboraPermissionProvider extends GroupMediaPermissionProvider {

/**
* {@inheritdoc}
*/
public function buildPermissions(): array {
$permissions = $this->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 published %entity_type in collabora");
}
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')) {
$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' &&
$this->definesEntityPermissions &&
($this->implementsOwnerInterface || $scope === 'any')
) {
switch ($operation) {
case 'preview in collabora':
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 FALSE;

case 'edit in collabora':
return "edit $scope $this->pluginId in collabora";
}
}

return $this->parent->getPermission($operation, $target, $scope);
}

}
Loading