|
3 | 3 | namespace Tests\Feature\Fieldtypes; |
4 | 4 |
|
5 | 5 | use PHPUnit\Framework\Attributes\Test; |
| 6 | +use Statamic\Facades\Blueprint; |
6 | 7 | use Statamic\Facades\Collection; |
7 | 8 | use Statamic\Facades\Entry; |
8 | 9 | use Statamic\Facades\Form; |
@@ -199,6 +200,74 @@ public function it_returns_an_empty_listing_when_the_user_cannot_view_any_of_the |
199 | 200 | $this->assertEmpty($response->json('meta.columns')); |
200 | 201 | } |
201 | 202 |
|
| 203 | + #[Test] |
| 204 | + public function it_does_not_expose_columns_from_an_unviewable_taxonomy_blueprint() |
| 205 | + { |
| 206 | + Taxonomy::make('secret')->title('Secret')->save(); |
| 207 | + Taxonomy::make('topics')->title('Topics')->save(); |
| 208 | + Blueprint::make('secret') |
| 209 | + ->setNamespace('taxonomies.secret') |
| 210 | + ->setContents(['fields' => [ |
| 211 | + ['handle' => 'classified', 'field' => ['type' => 'text']], |
| 212 | + ]]) |
| 213 | + ->save(); |
| 214 | + Blueprint::make('topics') |
| 215 | + ->setNamespace('taxonomies.topics') |
| 216 | + ->setContents(['fields' => [ |
| 217 | + ['handle' => 'summary', 'field' => ['type' => 'text']], |
| 218 | + ]]) |
| 219 | + ->save(); |
| 220 | + |
| 221 | + // The user can view the second configured taxonomy but not the first. |
| 222 | + $this->setTestRoles(['test' => ['access cp', 'view topics terms']]); |
| 223 | + $user = User::make()->assignRole('test')->save(); |
| 224 | + |
| 225 | + $config = base64_encode(json_encode([ |
| 226 | + 'type' => 'terms', |
| 227 | + 'taxonomies' => ['secret', 'topics'], |
| 228 | + ])); |
| 229 | + |
| 230 | + $response = $this |
| 231 | + ->actingAs($user) |
| 232 | + ->getJson("/cp/fieldtypes/relationship?config={$config}") |
| 233 | + ->assertOk(); |
| 234 | + |
| 235 | + $columns = collect($response->json('meta.columns'))->pluck('field')->all(); |
| 236 | + |
| 237 | + // Columns come from the viewable taxonomy, never the unviewable first one. |
| 238 | + $this->assertNotContains('classified', $columns); |
| 239 | + $this->assertContains('summary', $columns); |
| 240 | + } |
| 241 | + |
| 242 | + #[Test] |
| 243 | + public function an_authorized_user_still_gets_the_full_taxonomy_columns() |
| 244 | + { |
| 245 | + Taxonomy::make('secret')->title('Secret')->save(); |
| 246 | + Blueprint::make('secret') |
| 247 | + ->setNamespace('taxonomies.secret') |
| 248 | + ->setContents(['fields' => [ |
| 249 | + ['handle' => 'classified', 'field' => ['type' => 'text']], |
| 250 | + ]]) |
| 251 | + ->save(); |
| 252 | + |
| 253 | + $this->setTestRoles(['test' => ['access cp', 'view secret terms']]); |
| 254 | + $user = User::make()->assignRole('test')->save(); |
| 255 | + |
| 256 | + $config = base64_encode(json_encode([ |
| 257 | + 'type' => 'terms', |
| 258 | + 'taxonomies' => ['secret'], |
| 259 | + ])); |
| 260 | + |
| 261 | + $response = $this |
| 262 | + ->actingAs($user) |
| 263 | + ->getJson("/cp/fieldtypes/relationship?config={$config}") |
| 264 | + ->assertOk(); |
| 265 | + |
| 266 | + $columns = collect($response->json('meta.columns'))->pluck('field')->all(); |
| 267 | + |
| 268 | + $this->assertContains('classified', $columns); |
| 269 | + } |
| 270 | + |
202 | 271 | #[Test] |
203 | 272 | public function it_scopes_collection_listing_to_viewable_collections() |
204 | 273 | { |
|
0 commit comments