Skip to content

Commit

Permalink
Merge branch 'master' into unit-tests-and-minor-fixes-202310
Browse files Browse the repository at this point in the history
  • Loading branch information
chrieinv authored Nov 7, 2023
2 parents a0a6647 + 11ce612 commit 51ee6c2
Show file tree
Hide file tree
Showing 68 changed files with 787 additions and 402 deletions.
2 changes: 0 additions & 2 deletions sourcecode/apis/contentauthor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ h5p_nodes.sql
content-author-23-05-2016.sql
import.log
laravel.log
lti
!/resources/views/lti
ndladata/cerpus_export_log_package.sql
ndladata/example-package-import-request.xml

Expand Down

This file was deleted.

3 changes: 3 additions & 0 deletions sourcecode/apis/contentauthor/app/H5PLibrariesHubCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

Expand All @@ -16,6 +17,8 @@

class H5PLibrariesHubCache extends Model
{
use HasFactory;

protected $table = 'h5p_libraries_hub_cache';

protected $guarded = [];
Expand Down
3 changes: 3 additions & 0 deletions sourcecode/apis/contentauthor/app/H5PLibraryCapability.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Lang;

class H5PLibraryCapability extends Model
{
use HasFactory;

protected $table = 'h5p_library_capabilities';

protected $appends = ['title', 'description'];
Expand Down
34 changes: 0 additions & 34 deletions sourcecode/apis/contentauthor/app/H5pLti.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Content;
use App\Events\ArticleWasSaved;
use App\Exceptions\UnhandledVersionReasonException;
use App\H5pLti;
use App\Http\Libraries\License;
use App\Http\Libraries\LtiTrait;
use App\Http\Requests\ArticleRequest;
Expand All @@ -18,6 +17,7 @@
use App\Libraries\H5P\Adapters\CerpusH5PAdapter;
use App\Libraries\H5P\Interfaces\H5PAdapterInterface;
use App\Libraries\HTMLPurify\Config\MathMLConfig;
use App\Lti\Lti;
use App\SessionKeys;
use App\Traits\ReturnToCore;
use Cerpus\VersionClient\VersionData;
Expand All @@ -38,16 +38,12 @@ class ArticleController extends Controller
use LtiTrait;
use ReturnToCore;

protected H5pLti $lti;

public function __construct(H5pLti $h5pLti)
public function __construct(private readonly Lti $lti)
{
$this->middleware('core.return', ['only' => ['create', 'edit']]);
$this->middleware('lti.verify-auth', ['only' => ['create', 'edit', 'store', 'update']]);
$this->middleware('core.locale', ['only' => ['create', 'edit', 'store', 'update']]);
$this->middleware('core.behavior-settings:view', ['only' => ['show']]);

$this->lti = $h5pLti;
}

/**
Expand All @@ -69,7 +65,7 @@ public function create(Request $request): View
abort(403);
}

$ltiRequest = $this->lti->getValidatedLtiRequest();
$ltiRequest = $this->lti->getRequest($request);

$license = License::getDefaultLicense($ltiRequest);
$emails = '';
Expand Down Expand Up @@ -160,7 +156,7 @@ public function doShow($id, $context, $preview = false)
{
/** @var Article $article */
$article = Article::findOrFail($id);
$customCSS = !empty($this->lti->getValidatedLtiRequest()) ? $this->lti->getValidatedLtiRequest()->getLaunchPresentationCssUrl() : null;
$customCSS = $this->lti->getRequest(request())?->getLaunchPresentationCssUrl();
if (!$article->canShow($preview)) {
return view('layouts.draft-resource', [
'styles' => !is_null($customCSS) ? [$customCSS] : [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class LoginController extends Controller
|
*/
use AuthenticatesUsers;

/**
* Where to redirect users after login.
*
Expand All @@ -34,22 +35,14 @@ class LoginController extends Controller
*/
public function __construct()
{
$this->middleware('guest')->except('logout', 'ssoFromEdlibAdmin');
$this->middleware('guest')->except('logout');
}

public function username()
{
return 'username';
}

/**
* @throws \Illuminate\Validation\ValidationException
*/
public function ssoFromEdlibAdmin()
{
return redirect('admin');
}

protected function guard(): Guard
{
return Auth::guard('admin');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

use App\ACL\ArticleAccess;
use App\Game;
use App\H5pLti;
use App\Http\Libraries\LtiTrait;
use App\Http\Requests\ApiQuestionsetRequest;
use App\Http\Requests\LTIRequest;
use App\Libraries\Games\GameHandler;
use App\Lti\Lti;
use App\Traits\ReturnToCore;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
Expand All @@ -20,11 +19,8 @@ class GameController extends Controller
use ArticleAccess;
use ReturnToCore;

protected H5pLti $lti;

public function __construct(H5pLti $h5pLti)
public function __construct(private Lti $lti)
{
$this->lti = $h5pLti;
$this->middleware('lti.verify-auth', ['only' => ['create', 'edit', 'store', 'update']]);
$this->middleware('game-access', ['only' => ['ltiEdit']]);
}
Expand All @@ -38,10 +34,8 @@ public function doShow($id, $context, $preview = false)
{
$game = Game::findOrFail($id);
if (!$game->canShow($preview)) {
/** @var Request $request */
$request = \Illuminate\Support\Facades\Request::instance();
$ltiRequest = LTIRequest::fromRequest($request);
$styles = $ltiRequest && $ltiRequest->getLaunchPresentationCssUrl() ? [$ltiRequest->getLaunchPresentationCssUrl()] : [];
$ltiRequest = app()->make(Lti::class)->getRequest(request());
$styles = $ltiRequest?->getLaunchPresentationCssUrl() ? [$ltiRequest->getLaunchPresentationCssUrl()] : [];
return view('layouts.draft-resource', compact('styles'));
}
$gameType = GameHandler::makeGameTypeFromId($game->gametype);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\H5PContent;
use App\H5PFile;
use App\H5PLibrary;
use App\H5pLti;
use App\Http\Libraries\License;
use App\Http\Libraries\LtiTrait;
use App\Http\Requests\H5PStorageRequest;
Expand All @@ -21,20 +20,21 @@
use App\Libraries\H5P\AjaxRequest;
use App\Libraries\H5P\Dataobjects\H5PAlterParametersSettingsDataObject;
use App\Libraries\H5P\h5p;
use App\Libraries\H5P\H5PCopyright;
use App\Libraries\H5P\H5PCreateConfig;
use App\Libraries\H5P\H5PEditConfig;
use App\Libraries\H5P\H5PViewConfig;
use App\Libraries\H5P\H5PCopyright;
use App\Libraries\H5P\H5PExport;
use App\Libraries\H5P\H5PInfo;
use App\Libraries\H5P\H5PLibraryAdmin;
use App\Libraries\H5P\H5PProgress;
use App\Libraries\H5P\H5PViewConfig;
use App\Libraries\H5P\Interfaces\H5PAdapterInterface;
use App\Libraries\H5P\Interfaces\H5PAudioInterface;
use App\Libraries\H5P\Interfaces\H5PImageAdapterInterface;
use App\Libraries\H5P\Interfaces\H5PVideoInterface;
use App\Libraries\H5P\LtiToH5PLanguage;
use App\Libraries\H5P\Storage\H5PCerpusStorage;
use App\Lti\Lti;
use App\SessionKeys;
use App\Traits\ReturnToCore;
use Cerpus\VersionClient\VersionData;
Expand All @@ -56,6 +56,7 @@
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

use function Cerpus\Helper\Helpers\profile as config;
use function request;

class H5PController extends Controller
{
Expand All @@ -67,7 +68,7 @@ class H5PController extends Controller
private bool $sendEmail = true;

public function __construct(
private H5pLti $lti,
private Lti $lti,
private h5p $h5p,
private H5PLibraryAdmin $h5pLibraryAdmin,
) {
Expand All @@ -87,9 +88,10 @@ public function index(): View
public function doShow($id, $context, $preview = false): View
{
$styles = [];
if (!empty($this->lti->getValidatedLtiRequest()) && !is_null($this->lti->getValidatedLtiRequest()->getLaunchPresentationCssUrl())) {
$styles[] = $this->lti->getValidatedLtiRequest()->getLaunchPresentationCssUrl();
Session::flash(SessionKeys::EXT_CSS_URL, $this->lti->getValidatedLtiRequest()->getLaunchPresentationCssUrl());
$style = $this->lti->getRequest(request())?->getLaunchPresentationCssUrl();
if ($style) {
$styles[] = $style;
Session::flash(SessionKeys::EXT_CSS_URL, $style);
}
$h5pContent = H5PContent::findOrFail($id);
if (!$h5pContent->canShow($preview)) {
Expand Down Expand Up @@ -379,14 +381,8 @@ private function getVersionPurpose(Request $request, H5PContent $h5p, $authId):

private function getTargetLanguage(?string $language)
{
$contentLanguage = $language;
if (($ltiRequest = $this->lti->getValidatedLtiRequest()) !== null) {
$ltiLanguage = $ltiRequest->getExtTranslationLanguage();
if (!empty($ltiLanguage)) {
$contentLanguage = $ltiLanguage;
}
}
return $contentLanguage;
return $this->lti->getRequest(request())?->getExtTranslationLanguage()
?? $language;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use App\ACL\ArticleAccess;
use App\Events\LinkWasSaved;
use App\H5pLti;
use App\Http\Libraries\License;
use App\Http\Libraries\LtiTrait;
use App\Http\Requests\LinksRequest;
use App\Libraries\H5P\Interfaces\H5PAdapterInterface;
use App\Link;
use App\Lti\Lti;
use App\Traits\ReturnToCore;
use Carbon\Carbon;
use Cerpus\VersionClient\VersionData;
Expand All @@ -25,15 +25,11 @@ class LinkController extends Controller
use ReturnToCore;
use ArticleAccess;

protected H5pLti $lti;

public function __construct(H5pLti $h5pLti)
public function __construct(private readonly Lti $lti)
{
$this->middleware('core.return', ['only' => ['create', 'edit']]);
$this->middleware('lti.verify-auth', ['only' => ['create', 'edit', 'store', 'update']]);
$this->middleware('core.locale', ['only' => ['create', 'edit', 'store', 'update']]);

$this->lti = $h5pLti;
}

public function create(Request $request)
Expand All @@ -44,7 +40,7 @@ public function create(Request $request)

/** @var H5PAdapterInterface $adapter */
$adapter = app(H5PAdapterInterface::class);
$ltiRequest = $this->lti->getValidatedLtiRequest();
$ltiRequest = $this->lti->getRequest($request);

$licenses = License::getLicenses($ltiRequest);
$license = License::getDefaultLicense($ltiRequest);
Expand Down Expand Up @@ -121,7 +117,7 @@ public function edit(Request $request, $id)
}

$emails = ""; //$this->getCollaboratorsEmails($link);
$ltiRequest = $this->lti->getValidatedLtiRequest();
$ltiRequest = $this->lti->getRequest($request);
$licenses = License::getLicenses($ltiRequest);
$license = $link->license;
$redirectToken = $request->get('redirectToken');
Expand Down Expand Up @@ -190,7 +186,7 @@ public function update(LinksRequest $request, $id)
*/
public function doShow($id, $context, $preview = false): View
{
$customCSS = !empty($this->lti->getValidatedLtiRequest()) ? $this->lti->getValidatedLtiRequest()->getLaunchPresentationCssUrl() : null;
$customCSS = $this->lti->getRequest(request())?->getLaunchPresentationCssUrl();
/** @var Link $link */
$link = Link::findOrFail($id);
if (!$link->canShow($preview)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\ACL\ArticleAccess;
use App\Gametype;
use App\H5PLibrary;
use App\H5pLti;
use App\Http\Libraries\License;
use App\Http\Libraries\LtiTrait;
use App\Http\Requests\ApiQuestionsetRequest;
Expand All @@ -16,6 +15,7 @@
use App\Libraries\H5P\Interfaces\H5PAdapterInterface;
use App\Libraries\H5P\Packages\QuestionSet as QuestionSetPackage;
use App\Libraries\QuestionSet\QuestionSetHandler;
use App\Lti\Lti;
use App\QuestionSet;
use App\SessionKeys;
use App\Traits\FractalTransformer;
Expand All @@ -37,11 +37,8 @@ class QuestionSetController extends Controller
use ArticleAccess;
use FractalTransformer;

protected H5pLti $lti;

public function __construct(H5pLti $h5pLti)
public function __construct(private readonly Lti $lti)
{
$this->lti = $h5pLti;
$this->middleware('lti.verify-auth')->only(['create', 'edit', 'store', 'update']);
$this->middleware('lti.question-set')->only(['ltiCreate']);
$this->middleware('questionset-access', ['only' => ['ltiEdit']]);
Expand Down
Loading

0 comments on commit 51ee6c2

Please sign in to comment.