Restriction by other restrictions met at least once
availability_oncemet
Availability condition ("Once met") that wraps nested access restrictions and permanently remembers, per user and per activity/section, that they were fulfilled once. Includes an unlock report (unlocks.php) where staff can view and reset unlocks, event logging, event-driven cleanup observers and a full Privacy API provider.
The review found no security, code-quality or compliance findings.
- The only standalone entry point,
unlocks.php, callsrequire_login()andrequire_capability('availability/oncemet:viewunlocks')in the right context. It also checks that the requested instance id really exists in that item's availability JSON before it reads or deletes anything. - The reset action needs a sesskey and the separate
resetunlockcapability. Separate-groups limits are applied again in the SQL that does the delete. - All SQL uses placeholders. The only string fragments in SQL are fixed column names,
get_in_or_equal()output,core_user\fieldsoutput andflexible_table::get_sql_sort(). - Output goes through
s(),format_string(),info::format_info()and core renderers. Event descriptions are escaped by the core log reports. - The Privacy API provider is complete, observers clean up orphaned records, and unit and Behat test coverage is extensive.
availability_oncemet is a small availability condition (about 1,900 lines of production PHP plus a YUI form module). It wraps nested restrictions and stores a permanent per-user "unlock" once those restrictions have been met. It adds an unlock report where staff can review and reset unlocks, two log events, event observers that remove orphaned unlock records, and a full Privacy API provider.
The security posture is strong. The unlock report checks login, capability, context and sesskey correctly, and it only works on instance ids that are really stored on the requested item. Resets also respect separate-groups mode in the SQL that deletes the records. All database access uses the $DB API with bound parameters, and every place that writes HTML escapes or formats its values. The YUI module only puts plugin language strings into HTML and sets URLs as attributes.
The review found no issues worth reporting. The code was checked against Moodle 5.3 core (core_availability\tree, flexible_table, checkbox_toggleall, format_info, and the log reports' description escaping), and it uses these APIs as intended. Unit tests cover the condition logic, observers, events, privacy provider and report helpers, and Behat scenarios cover the UI.
Findings
Database writes on a read path. condition::is_available() inserts a record into availability_oncemet and fires unlock_gained the first time a user meets the nested restrictions. This can happen while availability is being checked for any user, including from scheduled tasks or staff reports. This is the documented design and each user/instance pair is written at most once. On large courses the first evaluation after a Once met restriction is added will still cause a burst of inserts and log entries, which site administrators may want to know about.
Adapted TinyMCE snippet. yui/src/form/js/form.js includes a short UUID v4 helper adapted from TinyMCE (GPL-2.0-or-later, which TinyMCE in Moodle core also uses). It carries an attribution comment and is deliberately not declared in thirdpartylibs.xml, because it is a small part of an otherwise first-party file. This matches how core handles adapted snippets and is not reported as a missing declaration.