Skip to content

Commit a25e5c0

Browse files
Copilotswissspidy
andauthored
Add wp user privacy-request commands for GDPR personal data management (#611)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent fa8d791 commit a25e5c0

5 files changed

Lines changed: 931 additions & 1 deletion

File tree

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@
239239
"user meta patch",
240240
"user meta pluck",
241241
"user meta update",
242+
"user privacy-request",
243+
"user privacy-request complete",
244+
"user privacy-request create",
245+
"user privacy-request delete",
246+
"user privacy-request erase",
247+
"user privacy-request export",
248+
"user privacy-request list",
242249
"user remove-cap",
243250
"user remove-role",
244251
"user reset-password",

entity-command.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@
9595
)
9696
);
9797
WP_CLI::add_command( 'user meta', 'User_Meta_Command' );
98+
WP_CLI::add_command(
99+
'user privacy-request',
100+
'User_Privacy_Request_Command',
101+
array(
102+
'before_invoke' => function () {
103+
if ( Utils\wp_version_compare( '4.9.6', '<' ) ) {
104+
WP_CLI::error( 'Requires WordPress 4.9.6 or greater.' );
105+
}
106+
},
107+
)
108+
);
98109
WP_CLI::add_command( 'user session', 'User_Session_Command' );
99110
WP_CLI::add_command( 'user term', 'User_Term_Command' );
100111

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
Feature: Manage user privacy requests
2+
3+
@require-wp-4.9.6
4+
Scenario: Create and list privacy requests
5+
Given a WP install
6+
7+
When I run `wp user privacy-request create admin@example.com export_personal_data --porcelain`
8+
Then STDOUT should be a number
9+
And save STDOUT as {REQUEST_ID}
10+
11+
When I run `wp user privacy-request list --format=csv --fields=ID,user_email,action_name,status`
12+
Then STDOUT should contain:
13+
"""
14+
{REQUEST_ID},admin@example.com,export_personal_data,request-pending
15+
"""
16+
17+
When I run `wp user privacy-request list --format=ids`
18+
Then STDOUT should contain:
19+
"""
20+
{REQUEST_ID}
21+
"""
22+
23+
When I run `wp user privacy-request list --format=count`
24+
Then STDOUT should be:
25+
"""
26+
1
27+
"""
28+
29+
@require-wp-4.9.6
30+
Scenario: Create requests with confirmed status
31+
Given a WP install
32+
33+
When I run `wp user privacy-request create admin@example.com export_personal_data --status=confirmed --porcelain`
34+
Then STDOUT should be a number
35+
And save STDOUT as {REQUEST_ID}
36+
37+
When I run `wp user privacy-request list --format=csv --fields=ID,status`
38+
Then STDOUT should contain:
39+
"""
40+
{REQUEST_ID},request-confirmed
41+
"""
42+
43+
@require-wp-4.9.6
44+
Scenario: Filter privacy request list by action type
45+
Given a WP install
46+
47+
When I run `wp user privacy-request create admin@example.com export_personal_data --porcelain`
48+
Then save STDOUT as {EXPORT_ID}
49+
50+
When I run `wp user privacy-request create admin@example.com remove_personal_data --porcelain`
51+
Then save STDOUT as {ERASE_ID}
52+
53+
When I run `wp user privacy-request list --action-type=export_personal_data --format=ids`
54+
Then STDOUT should contain:
55+
"""
56+
{EXPORT_ID}
57+
"""
58+
And STDOUT should not contain:
59+
"""
60+
{ERASE_ID}
61+
"""
62+
63+
When I run `wp user privacy-request list --action-type=remove_personal_data --format=ids`
64+
Then STDOUT should contain:
65+
"""
66+
{ERASE_ID}
67+
"""
68+
And STDOUT should not contain:
69+
"""
70+
{EXPORT_ID}
71+
"""
72+
73+
@require-wp-4.9.6
74+
Scenario: Filter privacy request list by status
75+
Given a WP install
76+
77+
When I run `wp user privacy-request create admin@example.com export_personal_data --status=confirmed --porcelain`
78+
Then save STDOUT as {CONFIRMED_ID}
79+
80+
When I run `wp user privacy-request create admin@example.com remove_personal_data --porcelain`
81+
Then save STDOUT as {PENDING_ID}
82+
83+
When I run `wp user privacy-request list --status=request-confirmed --format=ids`
84+
Then STDOUT should contain:
85+
"""
86+
{CONFIRMED_ID}
87+
"""
88+
And STDOUT should not contain:
89+
"""
90+
{PENDING_ID}
91+
"""
92+
93+
When I run `wp user privacy-request list --status=request-pending --format=ids`
94+
Then STDOUT should contain:
95+
"""
96+
{PENDING_ID}
97+
"""
98+
And STDOUT should not contain:
99+
"""
100+
{CONFIRMED_ID}
101+
"""
102+
103+
@require-wp-4.9.6
104+
Scenario: Delete privacy requests
105+
Given a WP install
106+
107+
When I run `wp user privacy-request create admin@example.com export_personal_data --porcelain`
108+
Then save STDOUT as {REQUEST_ID}
109+
110+
When I run `wp user privacy-request delete {REQUEST_ID}`
111+
Then STDOUT should contain:
112+
"""
113+
Success: Deleted 1 of 1 privacy requests.
114+
"""
115+
116+
When I run `wp user privacy-request list --format=count`
117+
Then STDOUT should be:
118+
"""
119+
0
120+
"""
121+
122+
When I try `wp user privacy-request delete 9999`
123+
Then STDERR should contain:
124+
"""
125+
Warning: Could not find privacy request with ID 9999.
126+
"""
127+
128+
@require-wp-4.9.6
129+
Scenario: Complete privacy requests
130+
Given a WP install
131+
132+
When I run `wp user privacy-request create admin@example.com export_personal_data --status=confirmed --porcelain`
133+
Then save STDOUT as {REQUEST_ID}
134+
135+
When I run `wp user privacy-request complete {REQUEST_ID}`
136+
Then STDOUT should contain:
137+
"""
138+
Success: Completed 1 of 1 privacy requests.
139+
"""
140+
141+
When I run `wp user privacy-request list --status=request-completed --format=ids`
142+
Then STDOUT should contain:
143+
"""
144+
{REQUEST_ID}
145+
"""
146+
147+
When I try `wp user privacy-request complete 9999`
148+
Then STDERR should contain:
149+
"""
150+
Warning: Could not find privacy request with ID 9999.
151+
"""
152+
153+
@require-wp-4.9.6
154+
Scenario: Erase personal data for a request
155+
Given a WP install
156+
157+
When I run `wp user privacy-request create admin@example.com remove_personal_data --status=confirmed --porcelain`
158+
Then save STDOUT as {REQUEST_ID}
159+
160+
When I run `wp user privacy-request erase {REQUEST_ID}`
161+
Then STDOUT should contain:
162+
"""
163+
Success: Erased personal data for request {REQUEST_ID}.
164+
"""
165+
166+
When I run `wp user privacy-request list --status=request-completed --format=ids`
167+
Then STDOUT should contain:
168+
"""
169+
{REQUEST_ID}
170+
"""
171+
172+
@require-wp-4.9.6
173+
Scenario: Erase command fails for non-erasure requests
174+
Given a WP install
175+
176+
When I run `wp user privacy-request create admin@example.com export_personal_data --status=confirmed --porcelain`
177+
Then save STDOUT as {REQUEST_ID}
178+
179+
When I try `wp user privacy-request erase {REQUEST_ID}`
180+
Then STDERR should contain:
181+
"""
182+
Error: Request {REQUEST_ID} is not a 'remove_personal_data' request.
183+
"""
184+
185+
@require-wp-4.9.6
186+
Scenario: Export personal data for a request
187+
Given a WP install
188+
189+
When I run `wp user privacy-request create admin@example.com export_personal_data --status=confirmed --porcelain`
190+
Then save STDOUT as {REQUEST_ID}
191+
192+
When I run `wp user privacy-request export {REQUEST_ID}`
193+
Then STDOUT should contain:
194+
"""
195+
Success: Exported personal data to:
196+
"""
197+
And STDOUT should contain:
198+
"""
199+
.zip
200+
"""
201+
202+
When I run `wp user privacy-request list --status=request-completed --format=ids`
203+
Then STDOUT should contain:
204+
"""
205+
{REQUEST_ID}
206+
"""
207+
208+
@require-wp-4.9.6
209+
Scenario: Export command fails for non-export requests
210+
Given a WP install
211+
212+
When I run `wp user privacy-request create admin@example.com remove_personal_data --status=confirmed --porcelain`
213+
Then save STDOUT as {REQUEST_ID}
214+
215+
When I try `wp user privacy-request export {REQUEST_ID}`
216+
Then STDERR should contain:
217+
"""
218+
Error: Request {REQUEST_ID} is not an 'export_personal_data' request.
219+
"""
220+
221+
@require-wp-4.9.6
222+
Scenario: Create request without porcelain flag
223+
Given a WP install
224+
225+
When I run `wp user privacy-request create admin@example.com export_personal_data`
226+
Then STDOUT should contain:
227+
"""
228+
Created privacy request
229+
"""
230+
231+
@require-wp-4.9.6
232+
Scenario: Create request with invalid email address
233+
Given a WP install
234+
235+
When I try `wp user privacy-request create not-an-email export_personal_data`
236+
Then STDERR should contain:
237+
"""
238+
Error: Invalid email address.
239+
"""
240+
241+
@require-wp-4.9.6
242+
Scenario: Create request with invalid action type
243+
Given a WP install
244+
245+
When I try `wp user privacy-request create admin@example.com invalid_action`
246+
Then STDERR should contain:
247+
"""
248+
Error: Invalid value specified for positional arg.
249+
"""
250+
251+
@require-wp-4.9.6
252+
Scenario: Create request with invalid status
253+
Given a WP install
254+
255+
When I try `wp user privacy-request create admin@example.com export_personal_data --status=invalid`
256+
Then STDERR should contain:
257+
"""
258+
Error: Parameter errors:
259+
Invalid value specified for 'status' (The initial status of the request.)
260+
"""

phpcs.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<exclude-pattern>*/src/Signup_Command\.php$</exclude-pattern>
7272
<exclude-pattern>*/src/Site(_Meta|_Option)?_Command\.php$</exclude-pattern>
7373
<exclude-pattern>*/src/Term(_Meta)?_Command\.php$</exclude-pattern>
74-
<exclude-pattern>*/src/User(_Application_Password|_Meta|_Session|_Term)?_Command\.php$</exclude-pattern>
74+
<exclude-pattern>*/src/User(_Application_Password|_Meta|_Privacy_Request|_Session|_Term)?_Command\.php$</exclude-pattern>
7575
</rule>
7676

7777
<!-- Whitelisting to provide backward compatibility to classes possibly extending this class. -->

0 commit comments

Comments
 (0)