fix(video): restrict StreamSchedule to livestream rooms only#2758
Closed
Ruksana7 wants to merge 3 commits intofossasia:developmentfrom
Closed
fix(video): restrict StreamSchedule to livestream rooms only#2758Ruksana7 wants to merge 3 commits intofossasia:developmentfrom
Ruksana7 wants to merge 3 commits intofossasia:developmentfrom
Conversation
- Add livestream.hls to inferType() in room-types.js - Replace fragile v-if in EditForm.vue with showStreamSchedule computed - Add _room_supports_streaming() guard to StreamScheduleViewSet - Add CheckConstraint to StreamSchedule Meta for DB-level enforcement Fixes fossasia#1138
Contributor
Reviewer's GuideImplements a new StreamSchedule model and API restricted to livestream-capable rooms, wires it into the admin room edit UI for stage-type rooms, and centralizes room type inference logic in a shared room-types helper used by the frontend. Sequence diagram for StreamSchedule create and update with broadcast and notificationssequenceDiagram
actor Admin
participant WebApp as WebApp_Frontend
participant API as StreamScheduleViewSet
participant RoomModel as Room
participant StreamScheduleModel as StreamSchedule
participant Broadcaster as broadcast_stream_change
participant Notifier as notify_event_change
Admin->>WebApp: Open admin room edit form
WebApp->>WebApp: inferType(config) == stage
WebApp->>WebApp: Show StreamSchedule component
Admin->>WebApp: Create or edit stream schedule
WebApp->>API: POST or PUT /rooms/{room_pk}/stream_schedules
API->>API: get_room()
API->>RoomModel: get_current_stream()
RoomModel-->>API: previous_stream
API->>StreamScheduleModel: validate and save
StreamScheduleModel-->>API: instance
API->>RoomModel: get_current_stream()
RoomModel-->>API: current_stream
API->>API: Compare previous_stream and current_stream
alt Stream changed
API->>Broadcaster: broadcast_stream_change(room_id, current_stream, reload=True)
end
API->>Notifier: notify_event_change(event_id)
API-->>WebApp: 200 OK with StreamSchedule data
WebApp-->>Admin: Updated schedule shown
ER diagram for Room and StreamSchedule relationship and constraintserDiagram
ROOM {
int id PK
varchar name
int event_id FK
}
STREAM_SCHEDULE {
int id PK
int room_id FK
varchar title
varchar url
datetime start_time
datetime end_time
varchar stream_type
json config
datetime created_at
datetime updated_at
}
ROOM ||--o{ STREAM_SCHEDULE : has
Class diagram for StreamSchedule model and related backend componentsclassDiagram
class Room {
+int id
+str name
+int event_id
+Event event
+StreamSchedule get_current_stream()
}
class StreamSchedule {
+int id
+Room room
+str title
+str url
+datetime start_time
+datetime end_time
+str stream_type
+dict config
+datetime created_at
+datetime updated_at
+bool is_active(at_time)
+void clean()
+void save(*args, **kwargs)
+str __str__()
}
class StreamScheduleSerializer {
+StreamSchedule create(validated_data)
+StreamSchedule update(instance, validated_data)
}
class PretalxViewSetMixin {
+Event event
+str write_permission
}
class StreamScheduleViewSet {
+QuerySet queryset
+StreamScheduleSerializer serializer_class
+str endpoint
+tuple~str~ search_fields
+str write_permission
+Room get_room()
+dict get_serializer_context()
+QuerySet get_queryset()
+Response create(request, *args, **kwargs)
+Response update(request, *args, **kwargs)
+void perform_destroy(instance)
}
class Event {
+int id
+Organizer organizer
}
class Organizer {
+int id
}
class broadcast_stream_change {
+void __call__(int room_id, StreamSchedule current_stream, bool reload)
}
class notify_event_change {
+void __call__(int event_id)
}
Room "1" --> "*" StreamSchedule : stream_schedules
StreamScheduleViewSet --|> PretalxViewSetMixin
StreamScheduleViewSet --> StreamSchedule : manages
StreamScheduleViewSet --> StreamScheduleSerializer : uses
StreamSchedule --> Room : room
StreamScheduleViewSet ..> broadcast_stream_change : calls
StreamScheduleViewSet ..> notify_event_change : calls
Room --> Event : event
Event --> Organizer : organizer
Class diagram for frontend room editing and room type inferenceclassDiagram
class EditForm {
+Object config
+bool creating
+Object allRoomTypes
+Object typeComponents
+bool saving
+str error
+Object modules
+Object inferredType
+str localizedName
+str localizedDescription
+void save()
}
class ROOM_TYPES {
+list~RoomTypeDefinition~ types
}
class RoomTypeDefinition {
+str id
+str icon
+str name
+str description
+str startingModule
+str behindFeatureFlag
}
class room_types_helper {
+list~RoomTypeDefinition~ ROOM_TYPES
+RoomTypeDefinition inferType(config)
+RoomTypeDefinition inferRoomType(room)
}
class StreamScheduleComponent {
+int roomId
}
class StageComponent {
+Object config
+Object modules
+void beforeSave()
}
class features {
+bool enabled(flag)
}
EditForm --> room_types_helper : uses inferType
room_types_helper --> ROOM_TYPES : filters
ROOM_TYPES --> RoomTypeDefinition : elements
EditForm --> StageComponent : renders for stage type
EditForm --> StreamScheduleComponent : renders for stage type
room_types_helper ..> features : uses enabled
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
inferTypehelper assumesconfig.module_configis always present and an array; consider defaulting to an empty array (e.g.(config.module_config || []).reduce(...)) to avoid runtime errors when the config is incomplete or coming from unexpected sources. - The
StreamScheduleViewSet.createandupdatemethods duplicate the sameValidationError-to-response mapping logic; extracting this into a small helper (e.g._validation_error_response(e)) would simplify the code and make future changes to that behavior easier. - In
StreamScheduleViewSet.perform_destroy, the room is fetched twice in some branches; you can reduce redundant queries by fetching it once up front (or always viainstance.roombefore deletion) and reusing that reference when computingevent_id.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `inferType` helper assumes `config.module_config` is always present and an array; consider defaulting to an empty array (e.g. `(config.module_config || []).reduce(...)`) to avoid runtime errors when the config is incomplete or coming from unexpected sources.
- The `StreamScheduleViewSet.create` and `update` methods duplicate the same `ValidationError`-to-response mapping logic; extracting this into a small helper (e.g. `_validation_error_response(e)`) would simplify the code and make future changes to that behavior easier.
- In `StreamScheduleViewSet.perform_destroy`, the room is fetched twice in some branches; you can reduce redundant queries by fetching it once up front (or always via `instance.room` before deletion) and reusing that reference when computing `event_id`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Collaborator
Saksham-Sirohi
left a comment
There was a problem hiding this comment.
Closing as the changes do not make a change to the current branch, also, this functionality was already created a while back
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1138
Summary by Sourcery
Restrict the new StreamSchedule functionality to livestream rooms by introducing a dedicated stream scheduling model, API viewset, and admin UI integration for stage-type rooms only.
New Features:
Enhancements: