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

PROD-31337: Implement group update event for EDA #4197

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,148 @@ channels:
format: uri
description: Canonical URL for the actor profile

groupUpdate:
address: com.getopensocial.cms.group.update
messages:
groupUpdate:
payload:
allOf:
- $ref: '#/components/schemas/cloudEventsSchema'
- type: object
properties:
data:
type: object
properties:
id:
type: string
description: Unique group ID (UUIDv4)
created:
type: string
format: date-time
description: Creation time of the group
updated:
type: string
format: date-time
description: Last update time of the group
status:
type: string
description: Status of the group (e.g., published or unpublished)
enum:
- published
- unpublished
label:
type: string
description: Label of the group
visibility:
type: object
properties:
type:
type: string
description: The visibility type.
roles:
type: array
description: The list of roles ids.
contentVisibility:
type: object
properties:
method:
type: string
description: Visibility of content
enum:
- public
- community
- group
membership:
type: object
properties:
method:
type: string
description: Method of membership
enum:
- open
- invite
- request
type:
type: string
nullable: true
description: Type of the group (optional)
address:
type: object
properties:
label:
type: string
nullable: true
description: Label for the address (optional)
countryCode:
type: string
nullable: true
description: Country code (optional)
administrativeArea:
type: string
nullable: true
description: Administrative area (optional)
locality:
type: string
nullable: true
description: Locality (optional)
dependentLocality:
type: string
nullable: true
description: Dependent locality (optional)
postalCode:
type: string
nullable: true
description: Postal code (optional)
sortingCode:
type: string
nullable: true
description: Sorting code (optional)
addressLine1:
type: string
nullable: true
description: Address line 1 (optional)
addressLine2:
type: string
nullable: true
description: Address line 2 (optional)
href:
type: object
properties:
canonical:
type: string
format: uri
description: Canonical URL for the group
actor:
type: object
properties:
application:
type: object
nullable: true
properties:
id:
type: string
description: Application ID (UUIDv4)
name:
type: string
description: Name of the application
user:
type: object
nullable: true
properties:
id:
type: string
description: Actor user ID (UUIDv4)
displayName:
type: string
description: Display name of the actor user
href:
type: object
properties:
canonical:
type: string
format: uri
description: Canonical URL for the actor profile

operations:
onGroupCreate:
action: 'receive'
Expand All @@ -436,3 +578,7 @@ operations:
action: 'receive'
channel:
$ref: '#/channels/groupPublish'
onGroupUpdate:
action: 'receive'
channel:
$ref: '#/channels/groupUpdate'
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ function social_group_flexible_group_group_insert(GroupInterface $group): void {
}
}

/**
* Implements hook_ENTITY_TYPE_update().
*/
function social_group_flexible_group_group_update(EntityInterface $entity): void {
if ($entity instanceof GroupInterface && $entity->bundle() === 'flexible_group') {
\Drupal::service('social_group_flexible_group.eda_handler')->groupUpdate($entity);
}
}

/**
* Implements hook_social_core_ENTITY_TYPE_unpublished().
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ public function groupUnpublish(GroupInterface $group): void {
);
}

/**
* Update event handler.
*/
public function groupUpdate(GroupInterface $group): void {
$this->dispatch(
topic_name: $this->topicName,
event_type: "{$this->namespace}.cms.group.update",
group: $group
);
}

/**
* Transforms a GroupInterface into a CloudEvent.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,33 @@ public function testGroupPublish(): void {
$this->assertEquals('com.getopensocial.cms.group.publish', $group->getType());
}

/**
* Test the groupUpdate() method.
*
* @covers ::groupUpdate
*/
public function testGroupUpdate(): void {
// Create the handler instance.
$handler = $this->getMockedHandler();

// Create the group object.
$group = $handler->fromEntity($this->group, 'com.getopensocial.cms.group.update');

// Expect the dispatch method in the dispatcher to be called.
$this->dispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo('com.getopensocial.cms.group.v1'),
$this->equalTo($group)
);

// Call the groupUpdate method.
$handler->groupUpdate($this->group);

// Assert that the correct group is dispatched.
$this->assertEquals('com.getopensocial.cms.group.update', $group->getType());
}

/**
* Returns a mocked handler with dependencies injected.
*
Expand Down
Loading