forked from CollaboraOnline/collabora-drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from donquixote/issue-52-epic-group-integration
Issue 52 epic group integration
- Loading branch information
Showing
23 changed files
with
1,534 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
], | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
9 changes: 9 additions & 0 deletions
9
modules/collabora_online_group/collabora_online_group.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
62
modules/collabora_online_group/collabora_online_group.install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
9 changes: 9 additions & 0 deletions
9
modules/collabora_online_group/collabora_online_group.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
45 changes: 45 additions & 0 deletions
45
modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...s/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraPermissionProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
Oops, something went wrong.