mcp_rights_records()
Description
Read native licence or consent records with separate resource and catalogue permissions and an explicit column allowlist.Parameters
| Column | Type | Default | Description |
|---|---|---|---|
| $consent | bool | Select the consent catalogue when true, otherwise the licence catalogue. | |
| $args: | array | $consent ? 'consentmanager' : 'licensemanager'; if !in_array$plugin | |
| $GLOBALS['plugins'] | |||
| true | |||
| $args | array | Validated tool arguments. |
Return
| array | Structured MCP result or permission/availability error. |
Location
include/mcp_management_functions.php lines 99 to 162
Definition
function mcp_rights_records(bool $consent, array $args): array
{
$plugin = $consent ? 'consentmanager' : 'licensemanager';
if (!in_array($plugin, $GLOBALS['plugins'], true)) {
return mcp_error_result('This plugin is unavailable to your account.', 'feature_unavailable');
}
$ref = $args['ref'] ?? null;
if ($ref !== null) {
mcp_visible_resource($ref);
}
if ($consent) {
require_once dirname(__DIR__) . '/plugins/consentmanager/include/consent_functions.php';
$catalogue = consentmanager_check_read();
$allowed = $ref === null ? $catalogue : consentmanager_check_read($ref);
$table = 'consent';
$columns = 'r.date_of_consent, r.consent_usage' . ($catalogue ? ', r.name' : '');
$withdrawn = "WHEN EXISTS (SELECT 1 FROM consent_request cr WHERE cr.consent = r.ref AND cr.withdrawn IS NOT NULL) THEN 'withdrawn'";
} else {
require_once dirname(__DIR__) . '/plugins/licensemanager/include/license_functions.php';
$catalogue = checkperm('a') || checkperm('lm');
$allowed = $ref === null ? $catalogue : licensemanager_check_read($ref);
$table = 'license';
$columns = 'r.holder, r.description, r.outbound, r.license_usage';
$withdrawn = '';
}
if (!$allowed) {
return mcp_error_result('Record access is unavailable to your account.', 'permission_denied');
}
$range = mcp_event_dates($args, 'r.expires');
$where = $range->sql;
$params = $range->parameters;
if ($ref !== null) {
$where .= " AND EXISTS (SELECT 1 FROM resource_{$table} links WHERE links.{$table} = r.ref AND links.resource = ?)";
array_push($params, 'i', $ref);
}
if (isset($args['record'])) {
$where .= ' AND r.ref = ?';
array_push($params, 'i', $args['record']);
}
if (isset($args['query'])) {
$search_columns = $consent ? ['r.consent_usage'] : ['r.holder', 'r.description', 'r.license_usage'];
if ($consent && $catalogue) {
$search_columns[] = 'r.name';
}
$where .= ' AND (' . implode(' OR ', array_map(static fn($column) => $column . ' LIKE ?', $search_columns)) . ')';
$params = array_merge($params, ps_param_fill(array_fill(0, count($search_columns), '%' . $args['query'] . '%'), 's'));
}
if (($args['association'] ?? '') === 'unlinked') {
if ($ref !== null || !$catalogue || !checkperm('a')) {
return mcp_error_result('Installation-wide record access is required.', 'permission_denied');
}
$where .= " AND NOT EXISTS (SELECT 1 FROM resource_{$table} links WHERE links.{$table} = r.ref)";
}
$state = "CASE {$withdrawn} WHEN r.expires IS NULL THEN 'undated' WHEN r.expires < CURDATE() THEN 'expired' ELSE 'current' END";
$sql = " FROM (SELECT r.ref, r.expires, {$columns}, {$state} AS status FROM {$table} r WHERE {$where}) records";
if (isset($args['status'])) {
$sql .= ' WHERE status = ?';
array_push($params, 's', $args['status']);
}
if (($args['result'] ?? '') === 'summary') {
return mcp_query_page('SELECT status, COUNT(*) AS records' . $sql . ' GROUP BY status ORDER BY status', $params, $args);
}
return mcp_query_page('SELECT *' . $sql . ' ORDER BY ref', $params, $args, ['scope' => $ref === null ? 'catalogue' : 'resource']);
}
This article was last updated 4th December 2026 11:35 Europe/London time based on the source file dated 4th December 2026 09:40 Europe/London time.