Skip to content

Commit 450d34e

Browse files
Merge branch 'master' into next_minor
2 parents c389a4f + 4d9140d commit 450d34e

File tree

5 files changed

+46
-14
lines changed

5 files changed

+46
-14
lines changed

package-lock.json

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Caches/PrivilegesCache.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class PrivilegesCache extends Cache {
2525
$privs += $endpoint_object->generate_pfsense_privs();
2626
}
2727

28-
# Obtain privileges for each Endpoint class
29-
foreach (get_classes_from_namespace('\\RESTAPI\\Forms\\') as $endpoint_class) {
30-
$endpoint_object = new $endpoint_class();
31-
$privs += $endpoint_object->generate_pfsense_privs();
28+
# Obtain privileges for each Form class
29+
foreach (get_classes_from_namespace('\\RESTAPI\\Forms\\') as $form_class) {
30+
$form_object = new $form_class();
31+
$privs += $form_object->generate_pfsense_privs();
3232
}
3333

3434
return $privs;

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,17 @@ class Form {
165165
private function generate_verbose_name(): string {
166166
# Separate the class name's words with spaces, allow consecutive capital characters like 'DNS'
167167
$form_name = $this->get_class_shortname();
168-
return preg_replace('/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/', ': ', $form_name);
168+
$verbose_name = preg_replace('/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/', ' ', $form_name);
169+
170+
# Add a colon after the first word if the class name is more than one word
171+
if (str_contains($verbose_name, ' ')) {
172+
$verbose_name = explode(' ', $verbose_name);
173+
$verbose_name[0] .= ': ';
174+
$verbose_name = implode(' ', $verbose_name);
175+
}
176+
177+
# Return the verbose name with the 'Form' suffix removed
178+
return str_replace(' Form', '', $verbose_name);
169179
}
170180

171181
/**
@@ -513,6 +523,7 @@ class Form {
513523
$this->get_priv_name() => [
514524
'name' => 'WebCfg - ' . $this->verbose_name,
515525
'descr' => "Allow access to the $this->url page.",
526+
'match' => [substr($this->url, 1)],
516527
],
517528
];
518529
}

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/IPsecChildSAStatus.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class IPsecChildSAStatus extends Model {
4040

4141
public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) {
4242
# Set model attributes
43-
$this->internal_callable = 'get_ipsec_child SA_statuses';
43+
$this->internal_callable = 'get_ipsec_sa_statuses';
4444
$this->parent_model_class = 'IPsecSAStatus';
4545
$this->verbose_name = 'IPsec Child SA Status';
4646
$this->many = true;

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APICoreModelTestCase.inc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,4 +1248,23 @@ class APICoreModelTestCase extends RESTAPI\Core\TestCase {
12481248
$dhcp_server->staticmap->value = [];
12491249
$dhcp_server->update(apply: true);
12501250
}
1251+
1252+
/**
1253+
* Checks that all Model classes with an internal_callable assigned have an existing callable assigned.
1254+
*/
1255+
public function test_model_internal_callables_exist(): void {
1256+
# Loop through all Model classes
1257+
foreach (Model::get_all_model_classes() as $model_class) {
1258+
# Create a new instance of the Model class
1259+
$model_obj = new $model_class(skip_init: true);
1260+
1261+
# Skip models that don't have an internal callable assigned
1262+
if (!$model_obj->internal_callable) {
1263+
continue;
1264+
}
1265+
1266+
# Ensure the internal callable exists
1267+
$this->assert_is_true(method_exists($model_obj, $model_obj->internal_callable));
1268+
}
1269+
}
12511270
}

0 commit comments

Comments
 (0)