Skip to content

Commit

Permalink
Merge pull request rrze-mmz#178 from rrze-mmz/148-migrate-the-rest-op…
Browse files Browse the repository at this point in the history
…encast-options-for-a-series

148 migrate the rest opencast options for a series
  • Loading branch information
stefanosgeo authored Nov 12, 2024
2 parents 340a0f7 + 1eef2b0 commit 3559296
Show file tree
Hide file tree
Showing 48 changed files with 769 additions and 291 deletions.
3 changes: 2 additions & 1 deletion .phpactor.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "/tmp/.mount_TinkeroUrRYB/resources/phpactor/phpactor.schema.json",
"language_server_phpstan.enabled": false
"language_server_phpstan.enabled": false,
"php_code_sniffer.enabled": true
}
15 changes: 15 additions & 0 deletions app/Enums/OpencastLogoPosition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Enums;

use ArchTech\Enums\InvokableCases;

enum OpencastLogoPosition: string
{
use InvokableCases;

case TR = 'TOP RIGHT';
case TL = 'TOP LEFT';
case BR = 'BOTTOM RIGHT';
case BL = 'BOTTOM LEFT';
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Backend/ManageLivestreamRoom.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ManageLivestreamRoom extends Controller
*/
public function reserve(Request $request, OpencastService $opencastService, WowzaService $wowzaService)
{
$this->authorize('administrate-portal-pages');
$this->authorize('administrate-assistant-pages');
// Get all inputs
$inputs = $request->all();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Backend/SeriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function edit(Series $series, OpencastService $opencastService): View
$availableAssistants = collect();
$opencastSeriesInfo = $opencastService->getSeriesInfo($series);
$chapters = $series->chapters()->orderBy('position')->get();
if ($opencastSeriesInfo->get('health') && $series->opencast_series_id !== '') {
if ($opencastSeriesInfo->get('health')->get('status') === 'pass' && $series->opencast_series_id !== '') {
$assistants = User::byRole(Role::ASSISTANT)->get();
//reject all assistants that are already in opencast series acl
$availableAssistants = $assistants->reject(function ($admin) use ($opencastSeriesInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
use App\Services\OpencastService;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

use function PHPUnit\Framework\isEmpty;

class SeriesOpencastController extends Controller
class SeriesVideoWorkflowController extends Controller
{
/**
* Creates an Openast series for the given tides series
Expand Down Expand Up @@ -137,4 +138,19 @@ public function addScheduledEventsAsClips(

return to_route('series.edit', $series);
}

public function updateSeriesTheme(Series $series, Request $request, OpencastService $opencastService)
{
$opencastSettings = Setting::opencast();
$validated = $request->validate([
'faculty' => ['required', 'string'],
'position' => ['required', 'integer'],
]);
//actually position is the themeID
$opencastService->updateSeriesTheme($series, $validated['position']);

session()->flash('flashMessage', 'Video workflow updated successfully');

return to_route('series.edit', $series);
}
}
26 changes: 26 additions & 0 deletions app/Http/Controllers/Backend/VideoWorkflowSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\UpdateVideoWorkflowSettings;
use App\Models\Setting;
use App\Services\OpencastService;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
Expand Down Expand Up @@ -35,4 +36,29 @@ public function update(UpdateVideoWorkflowSettings $request): RedirectResponse

return to_route('settings.workflow.show');
}

public function fetchAndSaveOpencastThemes(OpencastService $opencastService)
{
$setting = Setting::opencast();
$settings = $setting->data;

// Initialize available_themes as an empty array if it's not set
$settings['available_themes'] = [];

// Fetch themes and append each theme to the available_themes array
$opencastThemes = $opencastService->getThemes();
$opencastThemes->each(function ($theme) use (&$settings) {
$settings['available_themes'][] = [
'id' => $theme['id'],
'name' => $theme['name'],
'watermarkPosition' => $theme['watermarkPosition'],
];
});

// Save the updated settings back to the database
$setting->data = $settings;
$setting->save();

return to_route('settings.workflow.show');
}
}
9 changes: 5 additions & 4 deletions app/Http/Controllers/Frontend/ShowClipsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class ShowClipsController extends Controller
*/
public function index(): View
{
// $clips = Clip::Public()->Single()->orderByDesc('updated_at')->paginate(12);
//
// return view('frontend.clips.index', compact('clips'));
return view('frontend.clips.index');
}

Expand Down Expand Up @@ -47,7 +44,11 @@ public function show(Clip $clip, WowzaService $wowzaService): View
});

$wowzaStatus = $wowzaService->getHealth();
$urls = ($wowzaStatus) ? $wowzaService->getDefaultPlayerURL($clip) : collect([]);
$urls = ($wowzaStatus->has('status') && $wowzaStatus->get('status') !== 'failed')
? $wowzaService->getDefaultPlayerURL($clip)
: collect([
'defaultPlayerUrl' => getProtectedUrl($clip->assets()->formatVideo()->first()?->path),
]);

return view('frontend.clips.show', [
'clip' => $clip,
Expand Down
24 changes: 20 additions & 4 deletions app/Http/Requests/UpdateVideoWorkflowSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,30 @@ public function rules()
'password' => ['required', Password::min(6)],
'default_workflow_id' => ['required', 'string'],
'upload_workflow_id' => ['required', 'string'],
'theme_id_top_right' => ['required', 'numeric'],
'theme_id_top_left' => ['required', 'numeric'],
'theme_id_bottom_left' => ['required', 'numeric'],
'theme_id_bottom_right' => ['required', 'numeric'],
'archive_path' => ['required', 'string'],
'assistants_group_name' => ['required', 'string'],
'opencast_purge_end_date' => ['required', 'date'],
'opencast_purge_events_per_minute' => ['required', 'numeric'],
'enable_themes_support' => ['required', 'boolean'],
'available_themes' => ['nullable', 'array'], // Allow empty array
'available_themes.*.id' => ['required_with:enable_themes_support', 'numeric'],
'available_themes.*.name' => ['required_with:enable_themes_support', 'string'],
'available_themes.*.watermarkPosition' => ['nullable', 'string'],
];
}

protected function prepareForValidation(): void
{
// Only set available_themes to an empty array if it's null or not an array
if (! $this->has('available_themes') || ! is_array($this->input('available_themes'))) {
$this->merge([
'available_themes' => [],
'enable_themes_support' => $this->enable_themes_support === 'on',
]);
} else {
$this->merge([
'enable_themes_support' => $this->enable_themes_support === 'on',
]);
}
}
}
2 changes: 1 addition & 1 deletion app/Livewire/ClipsDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function userClipsQuery($search)

protected function adminOrDefaultQuery($search)
{
if (auth()->user()->can('administrate-portal-pages')) {
if (auth()->user()->can('administrate-assistant-pages')) {
$query = Clip::search($search);
// First, filter the clips that have assets
if ($this->withAssets) {
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/SeriesDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function userSeriesQuery($search)

protected function adminOrDefaultQuery($search)
{
if (auth()->user()->can('administrate-portal-pages')) {
if (auth()->user()->can('administrate-assistant-pages')) {
$query = Series::query()->withLastPublicClip();
$query->with(['presenters'])
->where(function ($q) use ($search) {
Expand Down
5 changes: 3 additions & 2 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public function boot()
//user
Gate::define('show-users', [UserPolicy::class, 'show']);
Gate::define('access-dashboard', [UserPolicy::class, 'dashboard']);
Gate::define('administrate-backend-pages', fn (User $user) => $user->isModerator());
Gate::define('administrate-portal-pages', fn (User $user) => $user->isAssistant() || $user->isAdmin());
Gate::define('administrate-moderator-pages',
fn (User $user) => $user->isModerator() || $user->isAssistant() || $user->isAdmin());
Gate::define('administrate-assistant-pages', fn (User $user) => $user->isAssistant() || $user->isAdmin());
Gate::define('administrate-admin-portal-pages', fn (User $user) => $user->isAdmin());
Gate::define('administrate-superadmin-portal-pages', fn (User $user) => $user->isSuperAdmin());

Expand Down
2 changes: 2 additions & 0 deletions app/Providers/LiveStreamingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public function register()
$settingsData['wowza']['server2']['api_password'],
$authType,
],
'timeout' => '10',
'connect_timeout' => '10',
]);
});
}
Expand Down
18 changes: 10 additions & 8 deletions app/Providers/OpenSearchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,20 @@ public function register(): void
$this->settingsData['username'],
$this->settingsData['password'],
],
'timeout' => '10',
'connect_timeout' => '10',
]);
});
}

/**
* Bootstrap services.
*/
public function boot(): void
{
//
}

private function getConfig()
{
$setting = Setting::firstOrCreate(
Expand All @@ -52,12 +62,4 @@ private function getConfig()

return $setting->data;
}

/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}
2 changes: 2 additions & 0 deletions app/Providers/OpencastServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public function register(): void
$settingData['username'],
$settingData['password'],
],
'timeout' => '10',
'connect_timeout' => '10',
]);
});
}
Expand Down
2 changes: 2 additions & 0 deletions app/Providers/StreamingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function register()
$settingsData['wowza']['server1']['api_password'],
$authType,
],
'timeout' => '5',
'connect_timeout' => '5',
]);
});
}
Expand Down
60 changes: 57 additions & 3 deletions app/Services/OpencastService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ public function __construct(private OpencastClient $client)
public function getSeriesInfo(Series $series): Collection
{
$opencastSeriesInfo = collect();
if ($health = $this->getHealth()->contains('pass')) {
$opencastSeriesInfo->put('health', $health)
->put('metadata', $this->getSeries($series))
$health = $this->getHealth();
$opencastSeriesInfo->put('health', $health);
if ($health->contains('pass')) {
$opencastSeriesInfo->put('metadata', $this->getSeries($series))
->put('theme', $this->getSeriesTheme($series))
->put(
OpencastWorkflowState::RECORDING->lower(),
$this->getEventsByStatus(OpencastWorkflowState::RECORDING, $series)
Expand Down Expand Up @@ -117,6 +119,35 @@ public function getSeries(Series $series): Collection
return $seriesInfo;
}

public function getSeriesTheme(Series $series): Collection
{
$seriesTheme = collect();

try {
$this->response = $this->client->get("admin-ng/series/{$series->opencast_series_id}/theme.json");
$seriesTheme = collect(json_decode((string) $this->response->getBody(), true));
} catch (GuzzleException $exception) {
Log::error($exception->getMessage());
}

return $seriesTheme;
}

public function getThemes(): Collection
{
$themes = collect();

try {
$this->response = $this->client->get('admin-ng/themes/themes.json');
$themesArr = json_decode((string) $this->response->getBody(), true);
$themes = collect($themesArr['results']);
} catch (GuzzleException $exception) {
Log::error($exception->getMessage());
}

return $themes;
}

/**
* Return opencast events based on status
*/
Expand Down Expand Up @@ -307,6 +338,29 @@ public function updateSeries(Series $series): Response|ResponseInterface
return $this->response;
}

public function updateSeriesTheme(Series $series, $themeID)
{
try {
$this->response =
$this->client->put(
"admin-ng/series/{$series->opencast_series_id}/theme",
[
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
],
'form_params' => [
'themeId' => $themeID,
],
]
);
} catch (GuzzleException $exception) {
Log::error($exception->getMessage());
}

return $this->response;

}

/**
* forms the data to update an existing series
*/
Expand Down
12 changes: 10 additions & 2 deletions app/Services/WowzaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ class WowzaService

private Setting $streamingSettings;

private StreamingClient $streamingClient;

private LiveStreamingClient $liveStreamingClient;

private array $clients;

public function __construct(
private StreamingClient $streamingClient,
private LiveStreamingClient $liveStreamingClient
StreamingClient $streamingClient,
LiveStreamingClient $liveStreamingClient
) {
$this->streamingClient = $streamingClient;
$this->liveStreamingClient = $liveStreamingClient;
$this->clients = [
'stream' => $streamingClient,
'livestream' => $liveStreamingClient,
Expand Down
Loading

0 comments on commit 3559296

Please sign in to comment.