Skip to content

Commit f142baa

Browse files
authored
Merge pull request #12 from iMattPro/updates
Process logs with username instead of user id
2 parents 5b072fa + 15a2376 commit f142baa

9 files changed

Lines changed: 245 additions & 63 deletions

File tree

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## 0.3.0-dev - 2026-05-12
6+
7+
### Added
8+
9+
- Added support for permanently deleting consent log records with the same optional filters used for CSV exports.
10+
- Added timestamps to exported consent log CSV file names so repeated exports are easier to distinguish.
11+
12+
### Changed
13+
14+
- Exporting or deleting consent logs by user now lets you pick that user by username instead of user ID.
15+
- Updated the language explaining the *Date from* and *Date to* fields in the ACP Consent Logs page.
16+
- Updated the developer documentation with clearer consent integration guidance, including iframe-specific patterns.
17+
- Allowed the extension to install on phpBB 4 while retaining support for phpBB 3.3 and later.
18+
19+
### Fixed
20+
21+
- Fixed consent decisions that require a page reload so they are still logged before the browser refreshes.
22+
- Fixed consent log CSV downloads to use binary-safe output handling for better compatibility with spreadsheet applications.
23+
524
## 0.2.0-dev - 2026-05-09
625

726
### Added

adm/style/consentmanager_acp_export.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,24 @@ <h3>{{ lang('WARNING') }}</h3>
1717
<dl>
1818
<dt>
1919
<label for="export_date_from">{{ lang('ACP_CONSENTMANAGER_EXPORT_DATE_FROM') ~ lang('COLON') }}</label>
20-
<br><span>{{ lang('ACP_CONSENTMANAGER_EXPORT_DATE_EXPLAIN') }}</span>
20+
<br><span>{{ lang('ACP_CONSENTMANAGER_EXPORT_DATE_FROM_EXPLAIN') }}</span>
2121
</dt>
2222
<dd><input type="date" id="export_date_from" name="export_date_from" value="{{ EXPORT_DATE_FROM|e('html') }}"></dd>
2323
</dl>
2424
<dl>
25-
<dt><label for="export_date_to">{{ lang('ACP_CONSENTMANAGER_EXPORT_DATE_TO') ~ lang('COLON') }}</label></dt>
25+
<dt>
26+
<label for="export_date_to">{{ lang('ACP_CONSENTMANAGER_EXPORT_DATE_TO') ~ lang('COLON') }}</label>
27+
<br><span>{{ lang('ACP_CONSENTMANAGER_EXPORT_DATE_TO_EXPLAIN') }}</span>
28+
</dt>
2629
<dd><input type="date" id="export_date_to" name="export_date_to" value="{{ EXPORT_DATE_TO|e('html') }}"></dd>
2730
</dl>
2831
<dl>
2932
<dt>
30-
<label for="export_user_id">{{ lang('ACP_CONSENTMANAGER_EXPORT_USER_ID') ~ lang('COLON') }}</label>
31-
<br><span>{{ lang('ACP_CONSENTMANAGER_EXPORT_USER_ID_EXPLAIN') }}</span>
33+
<label for="export_username">{{ lang('USERNAME') ~ lang('COLON') }}</label>
34+
<br><span>{{ lang('ACP_CONSENTMANAGER_EXPORT_USERNAME_EXPLAIN') }}</span>
3235
</dt>
33-
<dd><input type="number" id="export_user_id" name="export_user_id" min="0" value="{{ EXPORT_USER_ID }}"></dd>
36+
<dd><input type="text" id="export_username" name="export_username" value="{{ EXPORT_USERNAME|e('html') }}" class="text narrow"></dd>
37+
<dd>[ <a href="{{ U_FIND_USERNAME }}" onclick="find_username(this.href); return false;">{{ lang('FIND_USERNAME') }}</a> ]</dd>
3438
</dl>
3539
<dl>
3640
<dt>

config/services.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ services:
4040
- '@phpbb.consentmanager.cache'
4141
- '@text_formatter.cache'
4242
- '@user'
43+
- '%core.root_path%'
44+
- '%core.php_ext%'
4345
- '%tables.phpbb.consentmanager.consent_logs%'
4446

4547
phpbb.consentmanager.media_manager:
@@ -65,6 +67,8 @@ services:
6567
- '@phpbb.consentmanager.acp_manager'
6668
- '@request'
6769
- '@template'
70+
- '%core.root_path%'
71+
- '%core.php_ext%'
6872

6973
phpbb.consentmanager.controller.log:
7074
class: phpbb\consentmanager\controller\log_controller

controller/acp_controller.php

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class acp_controller
2929
/** @var template */
3030
protected $template;
3131

32+
/** @var string */
33+
protected $root_path;
34+
35+
/** @var string */
36+
protected $php_ext;
37+
3238
/** @var string */
3339
protected $u_action = '';
3440

@@ -39,13 +45,17 @@ class acp_controller
3945
* @param acp_manager $acp_manager ACP manager service
4046
* @param request $request Request service
4147
* @param template $template Template service
48+
* @param string $root_path phpBB root path
49+
* @param string $php_ext PHP file extension
4250
*/
43-
public function __construct(language $language, acp_manager $acp_manager, request $request, template $template)
51+
public function __construct(language $language, acp_manager $acp_manager, request $request, template $template, $root_path, $php_ext)
4452
{
4553
$this->language = $language;
4654
$this->acp_manager = $acp_manager;
4755
$this->request = $request;
4856
$this->template = $template;
57+
$this->root_path = $root_path;
58+
$this->php_ext = $php_ext;
4959

5060
$this->language->add_lang('acp_consentmanager', 'phpbb/consentmanager');
5161
}
@@ -176,9 +186,9 @@ public function handle_logs()
176186
*/
177187
protected function parse_export_filters(array $form_data, array &$errors)
178188
{
179-
$date_from_str = trim($form_data['export_date_from']);
180-
$date_to_str = trim($form_data['export_date_to']);
181-
$user_id = $form_data['export_user_id'];
189+
$date_from_str = $form_data['export_date_from'];
190+
$date_to_str = $form_data['export_date_to'];
191+
$username = $form_data['export_username'];
182192
$consent_ver = $form_data['export_consent_version'];
183193

184194
$filters = [];
@@ -213,9 +223,18 @@ protected function parse_export_filters(array $form_data, array &$errors)
213223
}
214224
}
215225

216-
if ($user_id > 0)
226+
if ($username !== '')
217227
{
218-
$filters['user_id'] = $user_id;
228+
$user_id = $this->acp_manager->get_user_id_by_username($username);
229+
230+
if ($user_id === false)
231+
{
232+
$errors[] = $this->language->lang('ACP_CONSENTMANAGER_EXPORT_INVALID_USERNAME', $username);
233+
}
234+
else
235+
{
236+
$filters['user_id'] = $user_id;
237+
}
219238
}
220239

221240
if ($consent_ver > 0)
@@ -251,9 +270,9 @@ protected function send_csv_download(array $filters)
251270
protected function get_logs_form_data()
252271
{
253272
return [
254-
'export_date_from' => $this->request->variable('export_date_from', ''),
255-
'export_date_to' => $this->request->variable('export_date_to', ''),
256-
'export_user_id' => $this->request->variable('export_user_id', 0),
273+
'export_date_from' => trim($this->request->variable('export_date_from', '')),
274+
'export_date_to' => trim($this->request->variable('export_date_to', '')),
275+
'export_username' => trim($this->request->variable('export_username', '')),
257276
'export_consent_version' => $this->request->variable('export_consent_version', 0),
258277
];
259278
}
@@ -277,12 +296,21 @@ protected function assign_export_template_vars(array $form_data, array $errors =
277296
'ERROR_MSG' => implode('<br>', $errors),
278297
'EXPORT_DATE_FROM' => $form_data['export_date_from'],
279298
'EXPORT_DATE_TO' => $form_data['export_date_to'],
280-
'EXPORT_USER_ID' => $form_data['export_user_id'],
299+
'EXPORT_USERNAME' => $form_data['export_username'],
281300
'EXPORT_CONSENT_VER' => $form_data['export_consent_version'],
301+
'U_FIND_USERNAME' => $this->get_find_username_url(),
282302
'U_ACTION' => $this->u_action,
283303
]);
284304
}
285305

306+
protected function get_find_username_url()
307+
{
308+
return append_sid(
309+
"{$this->root_path}memberlist.$this->php_ext",
310+
'mode=searchuser&amp;form=acp_consentmanager_export&amp;field=export_username&amp;select_single=true'
311+
);
312+
}
313+
286314
protected function validate_form_key($form_key)
287315
{
288316
if (!check_form_key($form_key))

language/en/acp_consentmanager.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@
4141
'ACP_CONSENTMANAGER_EXPORT_EXPLAIN' => 'Download a CSV file of stored consent log records or permanently delete matching records from the database. All fields are optional; leave them blank to work with the full log.',
4242
'ACP_CONSENTMANAGER_EXPORT_FILTERS' => 'Consent log filters',
4343
'ACP_CONSENTMANAGER_EXPORT_DATE_FROM' => 'Date from',
44+
'ACP_CONSENTMANAGER_EXPORT_DATE_FROM_EXPLAIN' => 'Restrict the export (or deletion) to logs dated on or after this date. Leave blank for no lower date limit.',
4445
'ACP_CONSENTMANAGER_EXPORT_DATE_TO' => 'Date to',
45-
'ACP_CONSENTMANAGER_EXPORT_DATE_EXPLAIN' => 'Use the browser date picker when available. If you cannot pick a date, enter it in YYYY-MM-DD format. Dates are interpreted in UTC. Leave blank to omit this boundary.',
46-
'ACP_CONSENTMANAGER_EXPORT_USER_ID' => 'User ID',
47-
'ACP_CONSENTMANAGER_EXPORT_USER_ID_EXPLAIN' => 'Enter a registered user ID to restrict the export (or delete) to that user’s consent records. Leave blank to include all users.',
46+
'ACP_CONSENTMANAGER_EXPORT_DATE_TO_EXPLAIN' => 'Restrict the export (or deletion) to logs dated on or before this date. Leave blank for no upper date limit.',
47+
'ACP_CONSENTMANAGER_EXPORT_USERNAME_EXPLAIN' => 'Enter a registered username to restrict the export (or deletion) to that user’s consent records. Leave blank to include all users.',
4848
'ACP_CONSENTMANAGER_EXPORT_VERSION' => 'Consent version',
49-
'ACP_CONSENTMANAGER_EXPORT_VERSION_EXPLAIN' => 'Restrict the export (or delete) to a specific consent version. Leave blank for all versions.',
49+
'ACP_CONSENTMANAGER_EXPORT_VERSION_EXPLAIN' => 'Restrict the export (or deletion) to a specific consent version. Leave blank for all versions.',
5050
'ACP_CONSENTMANAGER_EXPORT_DOWNLOAD' => 'Download CSV',
5151
'ACP_CONSENTMANAGER_DELETE' => 'Delete logs',
5252
'ACP_CONSENTMANAGER_DELETE_CONFIRM' => 'Are you sure you want to permanently delete the selected consent log records?',
5353
'ACP_CONSENTMANAGER_DELETE_SUCCESS' => 'The selected consent log records have been deleted.',
54-
'ACP_CONSENTMANAGER_EXPORT_INVALID_DATE_FROM' => 'The "Date from" value is not a valid date. Use the browser date picker when available, or enter the date in YYYY-MM-DD format.',
55-
'ACP_CONSENTMANAGER_EXPORT_INVALID_DATE_TO' => 'The "Date to" value is not a valid date. Use the browser date picker when available, or enter the date in YYYY-MM-DD format.',
56-
'ACP_CONSENTMANAGER_EXPORT_DATE_RANGE_INVALID' => '"Date from" must not be later than "Date to".',
54+
'ACP_CONSENTMANAGER_EXPORT_INVALID_USERNAME' => 'The username “%1$s” could not be found.',
55+
'ACP_CONSENTMANAGER_EXPORT_INVALID_DATE_FROM' => 'The “Date from” value is not a valid date. Use the browser date picker when available, or enter the date in YYYY-MM-DD format.',
56+
'ACP_CONSENTMANAGER_EXPORT_INVALID_DATE_TO' => 'The “Date to” value is not a valid date. Use the browser date picker when available, or enter the date in YYYY-MM-DD format.',
57+
'ACP_CONSENTMANAGER_EXPORT_DATE_RANGE_INVALID' => '“Date from” must not be later than “Date to”.',
5758
]);

service/acp_manager.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class acp_manager
4747
/** @var user */
4848
protected $user;
4949

50+
/** @var string */
51+
protected $root_path;
52+
53+
/** @var string */
54+
protected $php_ext;
55+
5056
/** @var string */
5157
protected $consent_logs_table;
5258

@@ -62,9 +68,11 @@ class acp_manager
6268
* @param consent_cache $consent_cache Persistent cache helper
6369
* @param cache_interface $text_formatter_cache Text formatter cache service
6470
* @param user $user Current user
71+
* @param string $root_path phpBB root path
72+
* @param string $php_ext PHP file extension
6573
* @param string $consent_logs_table Consent log table name
6674
*/
67-
public function __construct(config $config, driver_interface $db, db_text $config_text, language $language, phpbb_log $log, consent_manager_interface $consent_manager, consent_cache $consent_cache, cache_interface $text_formatter_cache, user $user, $consent_logs_table)
75+
public function __construct(config $config, driver_interface $db, db_text $config_text, language $language, phpbb_log $log, consent_manager_interface $consent_manager, consent_cache $consent_cache, cache_interface $text_formatter_cache, user $user, $root_path, $php_ext, $consent_logs_table)
6876
{
6977
$this->config = $config;
7078
$this->db = $db;
@@ -75,6 +83,8 @@ public function __construct(config $config, driver_interface $db, db_text $confi
7583
$this->consent_cache = $consent_cache;
7684
$this->text_formatter_cache = $text_formatter_cache;
7785
$this->user = $user;
86+
$this->root_path = $root_path;
87+
$this->php_ext = $php_ext;
7888
$this->consent_logs_table = $consent_logs_table;
7989
}
8090

@@ -169,6 +179,39 @@ public function parse_date_filter($date_str, $end_of_day = false)
169179
: (int) $dt->getTimestamp();
170180
}
171181

182+
/**
183+
* Resolve a phpBB username to its numeric user ID.
184+
*
185+
* @param string $username Submitted username
186+
*
187+
* @return int|false User ID on success, false when no matching user exists
188+
*/
189+
public function get_user_id_by_username($username)
190+
{
191+
$username = trim((string) $username);
192+
193+
if ($username === '')
194+
{
195+
return false;
196+
}
197+
198+
if (!function_exists('user_get_id_name'))
199+
{
200+
include_once($this->root_path . 'includes/functions_user.' . $this->php_ext);
201+
}
202+
203+
$user_id_ary = [];
204+
$username_ary = [$username];
205+
$error = user_get_id_name($user_id_ary, $username_ary, false, true);
206+
207+
if ($error !== false || empty($user_id_ary))
208+
{
209+
return false;
210+
}
211+
212+
return (int) reset($user_id_ary);
213+
}
214+
172215
/**
173216
* Write filtered consent log rows as CSV to the given file handle.
174217
*

0 commit comments

Comments
 (0)