Skip to content

Commit

Permalink
PROD-30972: Implement user enrolls to event event for the EDA, https:…
Browse files Browse the repository at this point in the history
  • Loading branch information
nkoporec authored and ribel committed Nov 5, 2024
1 parent 5f03488 commit 35f5381
Show file tree
Hide file tree
Showing 6 changed files with 868 additions and 1 deletion.
232 changes: 231 additions & 1 deletion modules/social_features/social_event/asyncapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,233 @@ channels:
type: string
nullable: true
description: The type of the event.

eventEnrollmentCreate:
address: com.getopensocial.event.enrollment.create
messages:
eventEnrollmentCreate:
payload:
allOf:
- $ref: '#/components/schemas/cloudEventsSchema'
- type: object
properties:
data:
type: object
properties:
eventEnrollment:
type: object
properties:
id:
type: string
description: The UUID of the enrollment.
created:
type: string
format: date-time
description: The creation time of the enrollment.
updated:
type: string
format: date-time
description: The last updated time of the enrollment.
status:
type: string
description: The status of the enrollment.
enum:
- approved
- pending
- rejected
event:
type: object
properties:
id:
type: string
description: The UUID of the event.
created:
type: string
format: date-time
description: The creation time of the event.
updated:
type: string
format: date-time
description: The last updated time of the event.
status:
type: string
description: The status of the event.
enum:
- published
- unpublished
label:
type: string
description: The label of the event.
visibility:
type: object
properties:
type:
type: string
description: The visibility type.
enum:
- public
- community
- groups
- roles
groups:
type: array
description: List of group UUIDs (only applicable for "groups" visibility).
roles:
type: array
description: List of role IDs (only applicable for "roles" visibility).
type:
type: string
nullable: true
description: The type of the event.
group:
type: object
nullable: true
properties:
id:
type: string
description: The UUID of the group.
label:
type: string
description: The label of the group.
href:
type: object
properties:
canonical:
type: string
format: uri
description: Canonical URL of the group.
author:
type: object
properties:
id:
type: string
description: The UUID of the author.
displayName:
type: string
description: The display name of the author.
href:
type: object
properties:
canonical:
type: string
format: uri
description: Canonical URL of the author.
allDay:
type: boolean
description: Indicates if the event lasts all day.
start:
type: string
format: date-time
description: The start time of the event.
end:
type: string
format: date-time
description: The end time of the event.
timezone:
type: string
description: The timezone of the event.
address:
type: object
properties:
label:
type: string
description: The label of the event location.
countryCode:
type: string
description: The country code of the event location.
administrativeArea:
type: string
description: The administrative area of the event location.
locality:
type: string
description: The locality of the event location.
dependentLocality:
type: string
description: The dependent locality of the event location.
postalCode:
type: string
description: The postal code of the event location.
sortingCode:
type: string
description: The sorting code of the event location.
addressLine1:
type: string
description: The first address line of the event location.
addressLine2:
type: string
description: The second address line of the event location.
enrollment:
type: object
properties:
enabled:
type: boolean
description: Indicates if enrollment is enabled.
method:
type: string
description: The method of enrollment.
enum:
- open
- invite
- request
href:
type: object
properties:
canonical:
type: string
format: uri
description: Canonical URL of the event.
user:
type: object
properties:
id:
type: string
nullable: true
description: The UUID of the user (empty if anonymous).
displayName:
type: string
description: The display name of the user.
email:
type: string
format: email
nullable: true
description: The email of the user (present if anonymous).
href:
type: object
properties:
canonical:
type: string
format: uri
description: Canonical URL of the user.
actor:
type: object
properties:
application:
type: object
nullable: true
properties:
id:
type: string
description: The UUID of the application.
name:
type: string
description: The name of the application.
user:
type: object
nullable: true
properties:
id:
type: string
nullable: true
description: The UUID of the user (empty if anonymous).
displayName:
type: string
description: The display name of the user.
href:
type: object
properties:
canonical:
type: string
format: uri
description: Canonical URL of the user.
operations:
onEventCreate:
action: 'receive'
Expand All @@ -586,3 +812,7 @@ operations:
action: 'receive'
channel:
$ref: '#/channels/eventUpdate'
onEventEnrollmentCreate:
action: 'receive'
channel:
$ref: '#/channels/eventEnrollmentCreate'
32 changes: 32 additions & 0 deletions modules/social_features/social_event/social_event.module
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use Drupal\menu_link_content\MenuLinkContentInterface;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\social_event\Controller\SocialEventController;
use Drupal\social_event\Entity\EventEnrollment;
use Drupal\social_event\Entity\Node\Event;
use Drupal\social_event\EventEnrollmentInterface;
use Drupal\social_event\SocialEventDateAllDay;
Expand Down Expand Up @@ -270,6 +271,37 @@ function social_event_views_query_alter(ViewExecutable $view, QueryPluginBase $q
}
}

/**
* Implements hook_entity_insert().
*/
function social_event_entity_insert(EntityInterface $entity): void {
if ($entity instanceof EventEnrollment) {

// Invite or user requests statuses.
$invite_or_request_statuses = [
EventEnrollmentInterface::REQUEST_PENDING,
EventEnrollmentInterface::REQUEST_APPROVED,
EventEnrollmentInterface::REQUEST_OR_INVITE_DECLINED,
EventEnrollmentInterface::INVITE_INVITED,
EventEnrollmentInterface::INVITE_PENDING_REPLY,
EventEnrollmentInterface::INVITE_ACCEPTED_AND_JOINED,
EventEnrollmentInterface::INVITE_INVALID_OR_EXPIRED,
];

if (!$entity->get('field_request_or_invite_status')->isEmpty() &&
in_array(
(int) $entity->get('field_request_or_invite_status')->getString(),
$invite_or_request_statuses
)
) {
return;
}

\Drupal::service('social_event.eda_event_enrollment_handler')
->eventEnrollmentCreate($entity);
}
}

/**
* Implements hook_block_view_alter().
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ services:
class: Drupal\social_event\EdaHandler
tags:
- { name: social.eda.handler }
social_event.eda_event_enrollment_handler:
autowire: true
class: Drupal\social_event\EdaEventEnrollmentHandler
tags:
- { name: social.eda.handler }
Loading

0 comments on commit 35f5381

Please sign in to comment.