Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove create and edit for Link content type #2616

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 0 additions & 165 deletions sourcecode/apis/contentauthor/app/Http/Controllers/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,182 +3,18 @@
namespace App\Http\Controllers;

use App\ACL\ArticleAccess;
use App\Events\LinkWasSaved;
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;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Session;
use Illuminate\View\View;

class LinkController extends Controller
{
use LtiTrait;
use ReturnToCore;
use ArticleAccess;

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']]);
}

public function create(Request $request)
{
if (!$this->canCreate()) {
abort(403);
}

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

$licenses = License::getLicenses($ltiRequest);
$license = License::getDefaultLicense($ltiRequest);

$emails = '';
$link = new Link();
$redirectToken = $request->get('redirectToken');
$userPublishEnabled = $adapter->isUserPublishEnabled();
$canPublish = true;
$isPublished = false;
$canList = true;

return view('link.create')->with(compact('licenses', 'license', 'emails', 'link', 'redirectToken', 'userPublishEnabled', 'canPublish', 'isPublished', 'canList'));
}

/**
* Store a newly created resource in storage.
*/
public function store(LinksRequest $request): JsonResponse
{
if (!$this->canCreate()) {
abort(403);
}

$inputs = $request->all();
$metadata = json_decode($inputs['linkMetadata']);

$link = new Link();
$link->link_type = $inputs['linkType'];
$link->link_url = $inputs['linkUrl'];
$link->owner_id = Session::get('authId');
$link->link_text = !empty($inputs['linkText']) ? $inputs['linkText'] : null;
$link->title = $metadata->title;
$link->metadata = !empty($inputs['linkMetadata']) ? $inputs['linkMetadata'] : null;
$link->is_published = $link::isUserPublishEnabled() ? $request->input('isPublished', 1) : 1;
$link->license = $inputs['license'] ?? '';
$link->save();

event(new LinkWasSaved($link, VersionData::CREATE));

$url = $this->getRedirectToCoreUrl($link->toLtiContent(), $request->get('redirectToken'));

return response()->json(['url' => $url], Response::HTTP_CREATED);
}

public function edit(Request $request, $id)
{
$link = Link::findOrFail($id);
/** @var H5PAdapterInterface $adapter */
$adapter = app(H5PAdapterInterface::class);

$isOwner = $link->isOwner(Session::get('authId', 'qawsed'));

if (!$link->shouldCreateFork(Session::get('authId', false))) {
$locked = $link->hasLock();
if ($locked) { // Article is locked, add some info to the response
$now = Carbon::now();
$expires = Carbon::createFromTimestamp($locked->updated_at->timestamp)->addHour();
$lockHeadline = trans('lock.article-is-locked');
$lockMessage = trans(
'lock.article-will-expire',
[
'expires' => $expires->diffInMinutes($now),
'editor' => $locked->getEditor(),
]
);
$editUrl = route('link.edit', $id);
$pollUrl = route('lock.status', $id);

return view('content-lock.locked')->with(compact('lockHeadline', 'lockMessage', 'editUrl', 'pollUrl'));
} else {
$link->lock();
}
}

$emails = ""; //$this->getCollaboratorsEmails($link);
$ltiRequest = $this->lti->getRequest($request);
$licenses = License::getLicenses($ltiRequest);
$license = $link->license;
$redirectToken = $request->get('redirectToken');
$userPublish = $adapter->isUserPublishEnabled();
$canPublish = $link->canPublish($request);
$isPublished = $link->is_published;
$canList = $link->canList($request);

return view('link.edit')->with(compact('link', 'isOwner', 'emails', 'license', 'licenses', 'id', 'redirectToken', 'userPublish', 'canPublish', 'canList', 'isPublished'));
}

public function update(LinksRequest $request, $id)
{
$link = new Link();
$oldLink = $link::findOrFail($id);

if (!$this->canCreate()) {
abort(403);
}

$inputs = $request->all();

$oldLicense = $oldLink->getContentLicense();
$reason = $oldLink->shouldCreateFork(Session::get('authId', false)) ? VersionData::COPY : VersionData::UPDATE;

if ($reason === VersionData::COPY && !$request->input("license", false)) {
$request->merge(["license" => $oldLicense]);
}

// If you are a collaborator, use the old license
if ($oldLink->isCollaborator()) {
$request->merge(["license" => $oldLicense]);
}

$link = $oldLink;
if ($oldLink->requestShouldBecomeNewVersion($request)) {
switch ($reason) {
case VersionData::UPDATE:
$link = $oldLink->makeCopy();
break;
case VersionData::COPY:
$link = $oldLink->makeCopy(Session::get('authId'));
break;
}
}

$metadata = json_decode($inputs['linkMetadata']);
$link->link_url = $inputs['linkUrl'];
$link->link_text = !empty($inputs['linkText']) ? $inputs['linkText'] : null;
$link->title = $metadata->title;
$link->metadata = !empty($inputs['linkMetadata']) ? $inputs['linkMetadata'] : null;
$link->is_published = $link::isUserPublishEnabled() ? $request->input('isPublished', 1) : 1;
$link->license = $inputs['license'] ?? $oldLink->license;

$link->save();

event(new LinkWasSaved($link, $reason));

$url = $this->getRedirectToCoreUrl($link->toLtiContent(), $request->get('redirectToken'));

return response()->json(['url' => $url], Response::HTTP_OK);
}

/**
Expand All @@ -187,7 +23,6 @@ public function update(LinksRequest $request, $id)
public function doShow($id, $context, $preview = false): View
{
$customCSS = $this->lti->getRequest(request())?->getLaunchPresentationCssUrl();
/** @var Link $link */
$link = Link::findOrFail($id);
if (!$link->canShow($preview)) {
return view('layouts.draft-resource', [
Expand Down
12 changes: 12 additions & 0 deletions sourcecode/apis/contentauthor/app/Http/Libraries/LtiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ trait LtiTrait
{
public function ltiShow($id)
{
if (!method_exists($this, 'doShow')) {
abort(500, 'Requested action is not available');
chrieinv marked this conversation as resolved.
Show resolved Hide resolved
}

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

if (!$ltiRequest) {
Expand All @@ -23,6 +27,10 @@ public function ltiShow($id)

public function ltiCreate(Request $request)
{
if (!method_exists($this, 'create')) {
abort(500, 'Requested action is not available');
}

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

if (!$ltiRequest) {
Expand All @@ -37,6 +45,10 @@ public function ltiCreate(Request $request)

public function ltiEdit(Request $request, $id)
{
if (!method_exists($this, 'edit')) {
abort(500, 'Requested action is not available');
}

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

if (!$ltiRequest) {
Expand Down
2 changes: 1 addition & 1 deletion sourcecode/apis/contentauthor/app/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @property string $owner_id
* @property int $deleted_at
* @property string $link_text
* @property string $metadata
* @property ?string $metadata
*
* @property Collection<Collaborator> $collaborators
*
Expand Down
10 changes: 0 additions & 10 deletions sourcecode/apis/contentauthor/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,6 @@ parameters:
count: 1
path: app/Http/Controllers/ArticleCopyrightController.php

-
message: "#^Call to an undefined method App\\\\Http\\\\Controllers\\\\GameController\\:\\:create\\(\\)\\.$#"
count: 1
path: app/Http/Controllers/GameController.php

-
message: "#^Called 'isNotEmpty' on Laravel collection, but could have been retrieved as a query\\.$#"
count: 1
Expand Down Expand Up @@ -340,11 +335,6 @@ parameters:
count: 1
path: app/Http/Controllers/HealthController.php

-
message: "#^Call to function is_null\\(\\) with string will always evaluate to false\\.$#"
count: 1
path: app/Http/Controllers/LinkController.php

-
message: "#^Call to function is_null\\(\\) with League\\\\Fractal\\\\Manager will always evaluate to false\\.$#"
count: 1
Expand Down

This file was deleted.

42 changes: 0 additions & 42 deletions sourcecode/apis/contentauthor/resources/views/link/edit.blade.php

This file was deleted.

4 changes: 1 addition & 3 deletions sourcecode/apis/contentauthor/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
Route::post('/h5p/{id}', [H5PController::class, 'ltiShow'])->middleware(['core.behavior-settings:view', 'lti.redirect-to-editor'])->name('h5p.ltishow');
Route::post('/game/{id}', [GameController::class, 'ltiShow'])->middleware(['lti.redirect-to-editor']);

Route::post('/link/create', [LinkController::class, 'ltiCreate']);
Route::post('/link/{id}', [LinkController::class, 'ltiShow'])->middleware(['lti.redirect-to-editor']);

Route::post('questionset/create', [QuestionSetController::class, 'ltiCreate']);
Expand All @@ -83,14 +82,13 @@

Route::group(['middleware' => ['core.ownership']], function () {
Route::post('h5p/{id}/edit', [H5PController::class, 'ltiEdit'])->middleware(['core.behavior-settings:editor'])->name('h5p.ltiedit');
Route::post('link/{id}/edit', [LinkController::class, 'ltiEdit']);
});
});

Route::get('/slo', [SingleLogoutController::class, 'index'])->name('slo'); // Single logout route

Route::resource('/article', ArticleController::class, ['except' => ['destroy']]);
Route::resource('/link', LinkController::class, ['except' => ['destroy']]);
Route::resource('/link', LinkController::class, ['only' => ['show']]);

Route::post('/article/create/upload', [ArticleUploadController::class, 'uploadToNewArticle'])->name('article-upload.new');
Route::post('/article/{id}/upload', [ArticleUploadController::class, 'uploadToExistingArticle'])->name('article-upload.existing');
Expand Down
Loading