Commit dfbc39f
authored
Gate RS comment moderation on the moderate_comments capability (#23123)
* Gate RS comment moderation on the moderate_comments capability
Non-admin users were shown fully active moderation controls in the new
RS comments screens; tapping them only failed server-side with a 403.
Fetch the current user's moderate_comments capability via wordpress-rs
(reusing SiteCapabilityChecker) and, when absent, disable and dim the
moderation controls on both the detail footer and the list's batch
actions. Like, copy/share link and reply stay active. The capability
handlers are also guarded in the ViewModels as defense-in-depth.
SiteCapabilityChecker now keys its cache by the local site id instead of
site.siteId, which is 0 for every app-password self-hosted site and would
otherwise collide their capabilities.
* Suppress ReturnCount detekt warning on onEditClicked
* Gray out disabled moderation controls in RS comment footer
Show the accent tint only on enabled on-toggles (approved/liked) and let
disabled moderation controls fall back to the grayed-out disabled color,
including the destructive red menu items, so a non-moderator no longer sees
tappable-looking controls.
* Address RS comment moderation review findings
- Always attempt the implicit approve when replying to an unapproved
comment, rather than gating on the async-fetched canModerate flag: a
moderator replying before the capability resolved (e.g. from a
notification with the reply field focused) would otherwise silently
drop the approve. approveAfterReply() reverts on server rejection, so a
non-moderator's reply self-heals either way.
- Don't cache a failed capability fetch: return a fail-closed value for
that call but retry on the next one, so a transient error no longer
disables moderation for the whole session.
- Use a ConcurrentHashMap for the capability cache now that the singleton
is read/written from multiple ViewModels on the default dispatcher.
- Rework SiteCapabilityCheckerTest with a success-path mock covering the
capability mapping, single-fetch caching, per-site keying, and the
failed-fetch-is-retried behavior.
* Assign moderation capability directly to the field
Drop the shadowing local and the qualified receiver in
loadModerationCapability by assigning the fetch result straight to the
canModerate field.
* Drop data-class mocks from SiteCapabilityCheckerTest
The success-path mock helper mocked wordpress-rs data classes, tripping
the DoNotMockDataClass lint rule (Debug-variant lint, which CI runs for
PRs). Revert to failure-path-only tests: they cover the fail-closed and
no-cache-on-failure behavior without mocking data classes. The success
path can't be unit-tested here (UserCapabilitiesMap.hasCap is native) and
is covered by the ViewModel tests.
* Gate RS comments on application password only, like RS posts/pages
shouldUseRsComments admitted WP.com-accessed sites too; the RS posts and
pages gates both use application password only. Drop the isUsingWpComRestApi
branch so the three RS gates are consistent — RS comments are now used only
for self-hosted sites with an application password (still behind the
RS_UNIFIED_COMMENTS flag, matching the pages gate).1 parent f01ecdc commit dfbc39f
13 files changed
Lines changed: 336 additions & 64 deletions
File tree
- WordPress/src
- main/java/org/wordpress/android/ui
- commentsrs
- screens
- comments/unified
- compose
- mysite
- items/listitem
- test/java/org/wordpress/android/ui
- commentsrs
- comments/viewmodels
- mysite/items/listitem
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
753 | 753 | | |
754 | 754 | | |
755 | 755 | | |
756 | | - | |
757 | | - | |
758 | | - | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
759 | 760 | | |
760 | 761 | | |
761 | 762 | | |
| |||
Lines changed: 32 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
105 | 112 | | |
106 | 113 | | |
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
110 | 117 | | |
111 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
112 | 127 | | |
113 | 128 | | |
114 | 129 | | |
| |||
226 | 241 | | |
227 | 242 | | |
228 | 243 | | |
| 244 | + | |
229 | 245 | | |
230 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
231 | 250 | | |
232 | 251 | | |
233 | 252 | | |
| |||
273 | 292 | | |
274 | 293 | | |
275 | 294 | | |
276 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
277 | 301 | | |
278 | 302 | | |
279 | 303 | | |
| |||
314 | 338 | | |
315 | 339 | | |
316 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
317 | 344 | | |
318 | 345 | | |
319 | 346 | | |
| |||
445 | 472 | | |
446 | 473 | | |
447 | 474 | | |
448 | | - | |
| 475 | + | |
| 476 | + | |
449 | 477 | | |
450 | 478 | | |
451 | 479 | | |
| |||
466 | 494 | | |
467 | 495 | | |
468 | 496 | | |
469 | | - | |
| 497 | + | |
| 498 | + | |
470 | 499 | | |
471 | 500 | | |
472 | 501 | | |
| |||
Lines changed: 48 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
43 | 50 | | |
44 | 51 | | |
45 | 52 | | |
| |||
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
| 58 | + | |
51 | 59 | | |
52 | 60 | | |
53 | 61 | | |
| |||
59 | 67 | | |
60 | 68 | | |
61 | 69 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
66 | 74 | | |
67 | 75 | | |
68 | 76 | | |
69 | 77 | | |
70 | | - | |
| 78 | + | |
| 79 | + | |
71 | 80 | | |
72 | 81 | | |
73 | 82 | | |
74 | 83 | | |
75 | 84 | | |
76 | 85 | | |
77 | 86 | | |
78 | | - | |
| 87 | + | |
79 | 88 | | |
80 | 89 | | |
81 | 90 | | |
| |||
93 | 102 | | |
94 | 103 | | |
95 | 104 | | |
| 105 | + | |
96 | 106 | | |
97 | 107 | | |
98 | 108 | | |
| |||
108 | 118 | | |
109 | 119 | | |
110 | 120 | | |
| 121 | + | |
111 | 122 | | |
112 | 123 | | |
113 | 124 | | |
| |||
117 | 128 | | |
118 | 129 | | |
119 | 130 | | |
| 131 | + | |
| 132 | + | |
120 | 133 | | |
121 | 134 | | |
122 | 135 | | |
123 | | - | |
124 | 136 | | |
125 | 137 | | |
126 | 138 | | |
| |||
131 | 143 | | |
132 | 144 | | |
133 | 145 | | |
134 | | - | |
| 146 | + | |
135 | 147 | | |
136 | 148 | | |
137 | 149 | | |
138 | 150 | | |
139 | | - | |
| 151 | + | |
140 | 152 | | |
141 | 153 | | |
142 | 154 | | |
143 | 155 | | |
144 | | - | |
| 156 | + | |
145 | 157 | | |
146 | 158 | | |
147 | 159 | | |
| |||
157 | 169 | | |
158 | 170 | | |
159 | 171 | | |
160 | | - | |
| 172 | + | |
161 | 173 | | |
162 | 174 | | |
163 | 175 | | |
| |||
170 | 182 | | |
171 | 183 | | |
172 | 184 | | |
| 185 | + | |
173 | 186 | | |
174 | 187 | | |
175 | 188 | | |
176 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
177 | 193 | | |
178 | 194 | | |
179 | 195 | | |
| |||
182 | 198 | | |
183 | 199 | | |
184 | 200 | | |
185 | | - | |
186 | 201 | | |
187 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
188 | 205 | | |
189 | | - | |
190 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
191 | 215 | | |
192 | 216 | | |
193 | | - | |
| 217 | + | |
194 | 218 | | |
195 | 219 | | |
196 | 220 | | |
| |||
210 | 234 | | |
211 | 235 | | |
212 | 236 | | |
213 | | - | |
| 237 | + | |
214 | 238 | | |
215 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
216 | 243 | | |
217 | 244 | | |
218 | 245 | | |
| |||
222 | 249 | | |
223 | 250 | | |
224 | 251 | | |
| 252 | + | |
225 | 253 | | |
226 | 254 | | |
227 | 255 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| |||
281 | 282 | | |
282 | 283 | | |
283 | 284 | | |
284 | | - | |
| 285 | + | |
| 286 | + | |
285 | 287 | | |
286 | 288 | | |
287 | 289 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| |||
Lines changed: 13 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
131 | 133 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
0 commit comments