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

Add tests, fix PHPStan issues in tests, move misplaced integration test. Some minor bugfixes #2569

Merged
merged 15 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions sourcecode/apis/contentauthor/app/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
*
* @property Collection<Collaborator> $collaborators
*
* @method null|self noMaxScore()
* @method null|self ofBulkCalculated($type)
* @method static Builder|null|self noMaxScore()
* @method static Builder|null|self ofBulkCalculated($type)
* @method static self find($id, $columns = ['*'])
* @method static self findOrFail($id, $columns = ['*'])
*/
Expand Down
2 changes: 1 addition & 1 deletion sourcecode/apis/contentauthor/app/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function getOwnerData(): ResourceUserDataObject

if ($ownerData) {
$user->firstname = $ownerData->getFirstName() ?? '';
$user->lastName = $ownerData->getLastName() ?? '';
$user->lastname = $ownerData->getLastName() ?? '';
$user->email = $ownerData->getEmail() ?? '';
}

Expand Down
2 changes: 1 addition & 1 deletion sourcecode/apis/contentauthor/app/H5PContentsMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function convertToMetadataObject($title = null): H5PMetadataObject
'licenseVersion' => $this->license_version,
'licenseExtras' => $this->license_extras,
'authorComments' => $this->author_comments,
'changes' => $this->changes,
'changes' => $this->getAttribute('changes'), // 'changes' conflicts with Eloquent variable that holds changed model attributes
'defaultLanguage' => $this->default_language,
]);
}
Expand Down
25 changes: 24 additions & 1 deletion sourcecode/apis/contentauthor/app/H5PLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -26,7 +27,29 @@
* @see H5PLibrary::scopeVersion()
* @method static Builder|static version($majorVersion, $minorVersion)
*
* @method static find($id, $columns = ['*'])
* @method static static find($id, $columns = ['*'])
*
* @property int $id
* @property Carbon $created_at
* @property Carbon $updated_at
* @property string $name H5P machinename
* @property string $title
* @property int $major_version
* @property int $minor_version
* @property int $patch_version
* @property int $runnable
* @property int $restricted
* @property int $fullscreen
* @property string $embed_types
* @property string $preloaded_js
* @property string $preloaded_css
* @property string $drop_library_css
* @property string $semantics
* @property string $tutorial_url
* @property int $has_icon
* @property string $metadata_settings
* @property string $add_to
* @property bool $patch_version_in_folder_name
*/
class H5PLibrary extends Model
{
Expand Down
3 changes: 3 additions & 0 deletions sourcecode/apis/contentauthor/app/H5PLibraryLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace App;

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

class H5PLibraryLanguage extends Model
{
use HasFactory;

protected $table = 'h5p_libraries_languages';

protected $fillable = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ public function handle($request, Closure $next)
return $next($request);
}
}
Log::error(__METHOD__ . ': Access denied. H5P: ' . $this->request->h5p
. ' is not owned or shared with user:' . Session::get('authId', 'not-logged-in-user'));
Log::error([
'user' => Session::get('userId', 'not-logged-in-user'),
'url' => request()->url(),
'request' => request()->all()
]);
Log::error(
__METHOD__ . ': Access denied. H5P: ' . $this->request->h5p
. ' is not owned or shared with user:' . Session::get('authId', 'not-logged-in-user'),
[
'user' => Session::get('userId', 'not-logged-in-user'),
'url' => request()->url(),
'request' => request()->all()
]
);
abort(403, 'Access denied, you are not the owner of the resource or it is not shared with you.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct()

public function setId($id, $hashId = true)
{
$this->id = $this->libraryId . '-' . $hashId ? md5($id) : $id;
$this->id = $this->libraryId . '-' . ($hashId ? md5($id) : $id);

return $this;
}
Expand Down
24 changes: 6 additions & 18 deletions sourcecode/apis/contentauthor/app/Libraries/H5P/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,27 +414,21 @@ public function getWhitelist($isLibrary, $defaultContentWhitelist, $defaultLibra
/**
* Is the library a patched version of an existing library?
*
* @param object $library
* An associateve array containing:
* - machineName: The library machineName
* - majorVersion: The librarys majorVersion
* - minorVersion: The librarys minorVersion
* - patchVersion: The librarys patchVersion
* @return boolean
* @param array{machineName: string, majorVersion: int, minorVersion: int, patchVersion: int} $library
* @return bool
chrieinv marked this conversation as resolved.
Show resolved Hide resolved
* TRUE if the library is a patched version of an existing library
* FALSE otherwise
* TODO: Implement this for real....
*/
public function isPatchedLibrary($library)
public function isPatchedLibrary($library): bool
{
return H5PLibrary::fromLibrary([
$library['machineName'],
$library['majorVersion'],
$library['minorVersion']
])
->where('patch_version', "<", $library['patchVersion'])
->get()
->isNotEmpty();
->exists();
}

/**
Expand Down Expand Up @@ -1156,16 +1150,10 @@ public function getNumContent($libraryId, $skip = null)
* Determines if content slug is used.
*
* @param string $slug
* @return boolean
*/
public function isContentSlugAvailable($slug)
public function isContentSlugAvailable($slug): bool
{
$sql = "select slug from h5p_contents where slug=?";
$res = $this->db->prepare($sql)->execute([$slug])->fetch(PDO::FETCH_ASSOC);
if (sizeof($res) > 0) {
return false;
}
return true;
return H5PContent::where('slug', $slug)->doesntExist();
}

/**
Expand Down
1 change: 1 addition & 0 deletions sourcecode/apis/contentauthor/app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/**
* A dummy user that is not actually bound to a database table.
*
* @property string $auth_id
* @property string $name
* @property string $email
* @property string $password
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use App\H5PLibraryLanguage;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @template-extends Factory<H5PLibraryLanguage>
*/
class H5PLibraryLanguageFactory extends Factory
{
public function definition(): array
{
return [
'library_id' => $this->faker->numberBetween(),
'language_code' => $this->faker->unique()->languageCode(),
'translation' => '',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace Database\Factories;

use App\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @template-extends Factory<User>
*/
class UserFactory extends Factory
{
public function definition(): array
Expand Down
Loading