-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ror registry data set cache; update bi-weekly; api lookup feature; mi…
…gration / install; translations
- Loading branch information
Showing
60 changed files
with
1,341 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?php | ||
/** | ||
* @file api/v1/rors/PKPRorController.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class PKPRorController | ||
* | ||
* @ingroup api_v1_rors | ||
* | ||
* @brief Controller class to handle API requests for ror operations. | ||
* | ||
*/ | ||
|
||
namespace PKP\API\v1\rors; | ||
|
||
use APP\facades\Repo; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Facades\Route; | ||
use PKP\core\PKPBaseController; | ||
use PKP\core\PKPRequest; | ||
use PKP\plugins\Hook; | ||
use PKP\security\authorization\ContextRequiredPolicy; | ||
use PKP\security\authorization\PolicySet; | ||
use PKP\security\authorization\RoleBasedHandlerOperationPolicy; | ||
use PKP\security\authorization\UserRolesRequiredPolicy; | ||
use PKP\security\Role; | ||
|
||
class PKPRorController extends PKPBaseController | ||
{ | ||
/** @var int The default number of rors to return in one request */ | ||
public const DEFAULT_COUNT = 30; | ||
|
||
/** @var int The maximum number of rors to return in one request */ | ||
public const MAX_COUNT = 100; | ||
|
||
/** | ||
* @copydoc \PKP\core\PKPBaseController::getHandlerPath() | ||
*/ | ||
public function getHandlerPath(): string | ||
{ | ||
return 'rors'; | ||
} | ||
|
||
/** | ||
* @copydoc \PKP\core\PKPBaseController::getRouteGroupMiddleware() | ||
*/ | ||
public function getRouteGroupMiddleware(): array | ||
{ | ||
return [ | ||
'has.user', | ||
'has.context', | ||
self::roleAuthorizer([ | ||
Role::ROLE_ID_MANAGER, | ||
]), | ||
]; | ||
} | ||
|
||
/** | ||
* @copydoc \PKP\core\PKPBaseController::getGroupRoutes() | ||
*/ | ||
public function getGroupRoutes(): void | ||
{ | ||
Route::get('{rorId}', $this->get(...)) | ||
->name('ror.getRor') | ||
->whereNumber('rorId'); | ||
|
||
Route::get('', $this->getMany(...)) | ||
->name('ror.getMany'); | ||
} | ||
|
||
/** | ||
* @copydoc \PKP\core\PKPBaseController::authorize() | ||
*/ | ||
public function authorize(PKPRequest $request, array &$args, array $roleAssignments): bool | ||
{ | ||
$this->addPolicy(new UserRolesRequiredPolicy($request), true); | ||
|
||
$rolePolicy = new PolicySet(PolicySet::COMBINING_PERMIT_OVERRIDES); | ||
|
||
$this->addPolicy(new ContextRequiredPolicy($request)); | ||
|
||
foreach ($roleAssignments as $role => $operations) { | ||
$rolePolicy->addPolicy(new RoleBasedHandlerOperationPolicy($request, $role, $operations)); | ||
} | ||
|
||
$this->addPolicy($rolePolicy); | ||
|
||
return parent::authorize($request, $args, $roleAssignments); | ||
} | ||
|
||
/** | ||
* Get a single ror | ||
*/ | ||
public function get(Request $illuminateRequest): JsonResponse | ||
{ | ||
if (!Repo::ror()->exists((int) $illuminateRequest->route('rorId'), $this->getRequest()->getContext()->getId())) { | ||
return response()->json([ | ||
'error' => __('api.rors.404.rorNotFound') | ||
], Response::HTTP_OK); | ||
} | ||
|
||
$ror = Repo::ror()->get((int) $illuminateRequest->route('rorId')); | ||
|
||
return response()->json(Repo::ror()->getSchemaMap()->map($ror), Response::HTTP_OK); | ||
} | ||
|
||
/** | ||
* Get a collection of rors | ||
* | ||
* @hook API::rors::params [[$collector, $illuminateRequest]] | ||
*/ | ||
public function getMany(Request $illuminateRequest): JsonResponse | ||
{ | ||
$collector = Repo::ror()->getCollector() | ||
->limit(self::DEFAULT_COUNT) | ||
->offset(0); | ||
|
||
foreach ($illuminateRequest->query() as $param => $val) { | ||
switch ($param) { | ||
case 'count': | ||
$collector->limit(min((int) $val, self::MAX_COUNT)); | ||
break; | ||
case 'offset': | ||
$collector->offset((int) $val); | ||
break; | ||
case 'searchPhrase': | ||
$collector->searchPhrase($val); | ||
break; | ||
} | ||
} | ||
|
||
Hook::call('API::rors::params', [$collector, $illuminateRequest]); | ||
|
||
$rors = $collector->getMany(); | ||
|
||
return response()->json([ | ||
'itemsMax' => $collector->getCount(), | ||
'items' => Repo::ror()->getSchemaMap()->summarizeMany($rors->values())->values(), | ||
], Response::HTTP_OK); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* @file classes/migration/install/RorsMigration.php | ||
* | ||
* Copyright (c) 2014-2024 Simon Fraser University | ||
* Copyright (c) 2000-2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class RorsMigration | ||
* | ||
* @brief Describe database table structures. | ||
* | ||
*/ | ||
|
||
namespace PKP\migration\install; | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
use PKP\migration\Migration; | ||
|
||
class RorsMigration extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('rors', function (Blueprint $table) { | ||
$table->comment('Ror registry dataset cache'); | ||
$table->bigInteger('ror_id')->autoIncrement(); | ||
$table->string('ror')->nullable(false); | ||
$table->string('display_locale', 28)->default(''); | ||
$table->smallInteger('is_active')->nullable(false)->default(0); | ||
|
||
$table->unique(['ror'], 'rors_unique'); | ||
$table->index(['display_locale'], 'rors_display_locale'); | ||
$table->index(['is_active'], 'rors_is_active'); | ||
}); | ||
|
||
Schema::create('ror_settings', function (Blueprint $table) { | ||
$table->comment('More data about Ror registry dataset cache'); | ||
$table->bigInteger('ror_setting_id')->autoIncrement(); | ||
$table->bigInteger('ror_id'); | ||
$table->string('locale', 28)->default(''); | ||
$table->string('setting_name', 255); | ||
$table->mediumText('setting_value')->nullable(); | ||
|
||
$table->index(['ror_id'], 'ror_settings_ror_id'); | ||
$table->unique(['ror_id', 'locale', 'setting_name'], 'ror_settings_unique'); | ||
$table->foreign('ror_id') | ||
->references('ror_id')->on('rors')->cascadeOnDelete(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migration. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::drop('ror_settings'); | ||
Schema::drop('rors'); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
classes/migration/upgrade/v3_4_0/I7135_CreateNewRorRegistryCacheTables.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* @file classes/migration/upgrade/v3_4_0/I7135_CreateNewRorRegistryCacheTables.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class I7135_CreateNewRorRegistryCacheTables | ||
* | ||
* @brief Describe database table structures. | ||
*/ | ||
|
||
namespace PKP\migration\upgrade\v3_4_0; | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema as Schema; | ||
use PKP\install\DowngradeNotSupportedException; | ||
use PKP\migration\Migration; | ||
|
||
class I7135_CreateNewRorRegistryCacheTables extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('rors', function (Blueprint $table) { | ||
$table->comment('Ror registry dataset cache'); | ||
$table->bigInteger('ror_id')->autoIncrement(); | ||
$table->string('ror')->nullable(false); | ||
$table->string('display_locale', 28)->default(''); | ||
$table->smallInteger('is_active')->nullable(false)->default(0); | ||
|
||
$table->unique(['ror'], 'rors_unique'); | ||
$table->index(['display_locale'], 'rors_display_locale'); | ||
$table->index(['is_active'], 'rors_is_active'); | ||
}); | ||
|
||
Schema::create('ror_settings', function (Blueprint $table) { | ||
$table->comment('More data about Ror registry dataset cache'); | ||
$table->bigInteger('ror_setting_id')->autoIncrement(); | ||
$table->bigInteger('ror_id'); | ||
$table->string('locale', 28)->default(''); | ||
$table->string('setting_name', 255); | ||
$table->mediumText('setting_value')->nullable(); | ||
|
||
$table->index(['ror_id'], 'ror_settings_ror_id'); | ||
$table->unique(['ror_id', 'locale', 'setting_name'], 'ror_settings_unique'); | ||
$table->foreign('ror_id') | ||
->references('ror_id')->on('rors')->cascadeOnDelete(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the downgrades | ||
* | ||
* @throws DowngradeNotSupportedException | ||
*/ | ||
public function down(): void | ||
{ | ||
throw new DowngradeNotSupportedException(); | ||
} | ||
} |
Oops, something went wrong.