Skip to content

Commit 451d479

Browse files
committed
Added in the means to query with wildcards to spdx and also added in an approved meata field. These has also been added to the model and its scheme defininion
1 parent 84dba06 commit 451d479

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

mu-plugins/osi-api/osi-api.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,16 @@ public function get_license_model( string $id ): ?array {
259259
'name' => $license->post_title,
260260
);
261261
$meta = array(
262+
'spdx_id' => get_post_meta( $license->ID, 'spdx_identifier_display_text', true ),
262263
'version' => get_post_meta( $license->ID, 'version', true ),
263264
'submission_date' => get_post_meta( $license->ID, 'release_date', true ),
264265
'submission_url' => get_post_meta( $license->ID, 'submission_url', true ),
265266
'submitter_name' => get_post_meta( $license->ID, 'submitter', true ),
267+
'approved' => get_post_meta( $license->ID, 'approved', true ) === '1' ? true : false,
266268
'approval_date' => get_post_meta( $license->ID, 'approval_date', true ),
267269
'license_steward_version' => get_post_meta( $license->ID, 'license_steward_version', true ),
268270
'license_steward_url' => get_post_meta( $license->ID, 'license_steward_version_url', true ),
269271
'board_minutes' => get_post_meta( $license->ID, 'link_to_board_minutes_url', true ),
270-
'spdx_id' => get_post_meta( $license->ID, 'spdx_identifier_display_text', true ),
271272
);
272273

273274
// Get the license stewards (terms)
@@ -309,13 +310,24 @@ function ( $category ) {
309310

310311
return array_merge(
311312
$model,
312-
array_map( 'esc_html', $meta ),
313+
array_map( array( $this, 'sanitize_value' ), $meta ),
313314
array( 'stewards' => $license_stewards ),
314315
array( 'keywords' => $license_categories ),
315316
array( '_links' => $links )
316317
);
317318
}
318319

320+
/**
321+
* Sanitize values to ensure all but bools are escaped.
322+
*
323+
* @param mixed $value The value to sanitize.
324+
*
325+
* @return mixed The sanitized value.
326+
*/
327+
public function sanitize_value( $value ) {
328+
return is_bool( $value ) ? $value : esc_html( $value );
329+
}
330+
319331
/**
320332
* Filter to allow the LIKE search of a post title.
321333
*
@@ -453,6 +465,11 @@ public function get_license_schema(): array {
453465
'type' => 'string',
454466
'context' => array( 'view', 'edit' ),
455467
),
468+
'spdx_id' => array(
469+
'description' => 'The SPDX identifier for the license.',
470+
'type' => 'string',
471+
'context' => array( 'view', 'edit' ),
472+
),
456473
'name' => array(
457474
'description' => 'The name of the license.',
458475
'type' => 'string',
@@ -480,6 +497,12 @@ public function get_license_schema(): array {
480497
'type' => 'string',
481498
'context' => array( 'view' ),
482499
),
500+
'approved' => array(
501+
'description' => 'Whether the license is approved.',
502+
'type' => 'boolean',
503+
'default' => false,
504+
'context' => array( 'view', 'edit' ),
505+
),
483506
'approval_date' => array(
484507
'description' => 'Date the license was approved.',
485508
'type' => 'string',

0 commit comments

Comments
 (0)