Skip to content

Commit

Permalink
PROD-31338 - Implement 'group delete' event for the EDA
Browse files Browse the repository at this point in the history
  • Loading branch information
nkoporec authored and ribel committed Dec 3, 2024
1 parent d0637ea commit c47798a
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,147 @@ channels:
type: string
format: uri
description: Canonical URL for the actor profile

groupDelete:
address: com.getopensocial.cms.group.delete
messages:
groupDelete:
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 @@ -582,3 +722,7 @@ operations:
action: 'receive'
channel:
$ref: '#/channels/groupUpdate'
onGroupDelete:
action: 'receive'
channel:
$ref: '#/channels/groupDelete'
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,16 @@ function social_group_flexible_group_social_core_group_published(EntityInterface
}
}

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

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

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

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

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

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

// 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 groupDelete method.
$handler->groupDelete($this->group);

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

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

0 comments on commit c47798a

Please sign in to comment.