|
| 1 | +<?php namespace Database\Migrations\Config; |
| 2 | +/** |
| 3 | + * Copyright 2026 OpenStack Foundation |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + **/ |
| 14 | + |
| 15 | +use Doctrine\Migrations\AbstractMigration; |
| 16 | +use Doctrine\DBAL\Schema\Schema; |
| 17 | +use App\Security\MemberScopes; |
| 18 | +use App\Models\Foundation\Main\IGroup; |
| 19 | + |
| 20 | +/** |
| 21 | + * Migration to seed the get-member-by-external-id endpoint. |
| 22 | + * |
| 23 | + * Adds: |
| 24 | + * - 1 api_endpoints row (get-member-by-external-id) |
| 25 | + * - 1 endpoint_api_scopes association (ReadMemberData) |
| 26 | + * - 3 endpoint_api_authz_groups rows (super-admins, administrators, summit-front-end-administrators) |
| 27 | + * |
| 28 | + * All INSERTs are idempotent via WHERE NOT EXISTS. |
| 29 | + */ |
| 30 | +final class Version20260410172200 extends AbstractMigration |
| 31 | +{ |
| 32 | + use APIEndpointsMigrationHelper; |
| 33 | + |
| 34 | + private const API_NAME = 'members'; |
| 35 | + private const ENDPOINT_NAME = 'get-member-by-external-id'; |
| 36 | + private const ENDPOINT_ROUTE = '/api/v1/members/external/{external_id}'; |
| 37 | + |
| 38 | + public function getDescription(): string |
| 39 | + { |
| 40 | + return 'Seed get-member-by-external-id endpoint with scope and authz groups'; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @param Schema $schema |
| 45 | + */ |
| 46 | + public function up(Schema $schema): void |
| 47 | + { |
| 48 | + $scope = MemberScopes::ReadMemberData; |
| 49 | + |
| 50 | + // 1. Insert the endpoint |
| 51 | + $this->addSql($this->insertEndpoint( |
| 52 | + self::API_NAME, |
| 53 | + self::ENDPOINT_NAME, |
| 54 | + self::ENDPOINT_ROUTE, |
| 55 | + 'GET' |
| 56 | + )); |
| 57 | + |
| 58 | + // 2. Insert endpoint_api_scopes association |
| 59 | + $this->addSql($this->insertEndpointScope(self::API_NAME, self::ENDPOINT_NAME, $scope)); |
| 60 | + |
| 61 | + // 3. Insert endpoint_api_authz_groups |
| 62 | + $authzGroups = [ |
| 63 | + IGroup::SuperAdmins, |
| 64 | + IGroup::Administrators, |
| 65 | + IGroup::SummitAdministrators, |
| 66 | + ]; |
| 67 | + |
| 68 | + foreach ($authzGroups as $groupSlug) { |
| 69 | + $this->addSql($this->insertEndpointAuthzGroup(self::API_NAME, self::ENDPOINT_NAME, $groupSlug)); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @param Schema $schema |
| 75 | + */ |
| 76 | + public function down(Schema $schema): void |
| 77 | + { |
| 78 | + $scope = MemberScopes::ReadMemberData; |
| 79 | + |
| 80 | + // Reverse order: authz groups → endpoint scopes → endpoint |
| 81 | + $authzGroups = [ |
| 82 | + IGroup::SuperAdmins, |
| 83 | + IGroup::Administrators, |
| 84 | + IGroup::SummitAdministrators, |
| 85 | + ]; |
| 86 | + |
| 87 | + foreach ($authzGroups as $groupSlug) { |
| 88 | + $this->addSql($this->deleteEndpointAuthzGroup(self::API_NAME, self::ENDPOINT_NAME, $groupSlug)); |
| 89 | + } |
| 90 | + |
| 91 | + $this->addSql($this->deleteScopesEndpoints(self::API_NAME, [$scope])); |
| 92 | + $this->addSql($this->deleteEndpoint(self::API_NAME, self::ENDPOINT_NAME)); |
| 93 | + } |
| 94 | +} |
0 commit comments