Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore the production_entities_enabled feature #1293

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions assets/js/components/mock/service_create_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ <h2>General</h2>
<p class="parsley-errors"></p>
<input type="text" id="dashboard_bundle_service_type_general_teamName"
name="dashboard_bundle_service_type[general][teamName]" required="required"/></div>
<div class="form-row"><label for="dashboard_bundle_service_type_general_productionEntitiesEnabled">Production
entities enabled</label>
<p class="parsley-errors"></p>
<input type="checkbox" id="dashboard_bundle_service_type_general_productionEntitiesEnabled"
name="dashboard_bundle_service_type[general][productionEntitiesEnabled]" value="1"/>
</div>
<div class="form-row"><label for="dashboard_bundle_service_type_general_privacyQuestionsEnabled">Privacy
questions enabled</label>
<p class="parsley-errors"></p>
Expand Down
6 changes: 6 additions & 0 deletions assets/js/components/mock/service_edit_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ <h2>General</h2>
<input type="text" id="dashboard_bundle_edit_service_type_general_teamName"
name="dashboard_bundle_edit_service_type[general][teamName]" required="required"
value="team-23"/></div>
<div class="form-row"><label for="dashboard_bundle_edit_service_type_general_productionEntitiesEnabled">Production
entities enabled</label>
<p class="parsley-errors"></p>
<input type="checkbox" id="dashboard_bundle_edit_service_type_general_productionEntitiesEnabled"
name="dashboard_bundle_edit_service_type[general][productionEntitiesEnabled]" value="1"/>
</div>
<div class="form-row"><label for="dashboard_bundle_edit_service_type_general_privacyQuestionsEnabled">Privacy
questions enabled</label>
<p class="parsley-errors"></p>
Expand Down
24 changes: 18 additions & 6 deletions migrations/Version20240514071702.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<?php

/**
* Copyright 2024 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace Surfnet\ServiceProviderDashboard\Migrations;
Expand All @@ -14,18 +30,14 @@ final class Version20240514071702 extends AbstractMigration
{
public function getDescription(): string
{
return 'Drops the `production_entities_enabled` column from the `service` entity';
return 'This migration is preserved to keep the migration history intact. This migration was used to drop the `production_entities_enabled` field in the services table. However, the feature removal got dropped and we don\'t want to cause data loss.';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE service DROP production_entities_enabled');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE service ADD production_entities_enabled TINYINT(1) NOT NULL');
}
}
}
33 changes: 33 additions & 0 deletions migrations/Version20241031120000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Surfnet\ServiceProviderDashboard\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20241031120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Restores the `production_entities_enabled` column to the `service` table if got removed by retracted migration Version20240514071702';
}

public function up(Schema $schema): void
{
// Check if the column exists
$columns = $this->connection->createSchemaManager()->listTableColumns('service');
$columnExists = false;
foreach ($columns as $column) {
if ($column->getName() === 'production_entities_enabled') {
$columnExists = true;
break;
}
}

if (!$columnExists) {
$this->addSql('ALTER TABLE service ADD production_entities_enabled TINYINT(1) NOT NULL DEFAULT 0');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class CreateServiceCommand implements Command
*/
private $institutionId;

private bool $productionEntitiesEnabled = false;

private bool $privacyQuestionsEnabled = true;

Expand Down Expand Up @@ -103,6 +104,11 @@ public function setName($name): void
$this->name = $name;
}

public function setProductionEntitiesEnabled(bool $enabled): void
{
$this->productionEntitiesEnabled = $enabled;
}

public function setPrivacyQuestionsEnabled(bool $privacyQuestionsEnabled): void
{
$this->privacyQuestionsEnabled = $privacyQuestionsEnabled;
Expand Down Expand Up @@ -160,6 +166,11 @@ public function getName()
return $this->name;
}

public function isProductionEntitiesEnabled(): bool
{
return $this->productionEntitiesEnabled;
}

public function isPrivacyQuestionsEnabled(): bool
{
return $this->privacyQuestionsEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function __construct(
#[SpDashboardAssert\UrnFormattedTeamName]
#[Assert\NotBlank]
private string $teamName,
private bool $productionEntitiesEnabled,
private bool $privacyQuestionsEnabled,
private bool $clientCredentialClientsEnabled,
#[Assert\NotBlank]
Expand Down Expand Up @@ -74,6 +75,11 @@ public function setName(string $name): void
$this->name = $name;
}

public function setProductionEntitiesEnabled(bool $enabled): void
{
$this->productionEntitiesEnabled = $enabled;
}

public function setPrivacyQuestionsEnabled(bool $privacyQuestionsEnabled): void
{
$this->privacyQuestionsEnabled = $privacyQuestionsEnabled;
Expand Down Expand Up @@ -189,6 +195,11 @@ public function isPrivacyQuestionsAnswered(): bool
return $this->privacyQuestionsAnswered;
}

public function isProductionEntitiesEnabled(): bool
{
return $this->productionEntitiesEnabled;
}

public function isPrivacyQuestionsEnabled(): bool
{
return $this->privacyQuestionsEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function handle(CreateServiceCommand $command): void
$service->setName($name);
$service->setGuid($command->getGuid());
$service->setTeamName($fullTeamName);
$service->setProductionEntitiesEnabled($command->isProductionEntitiesEnabled());
$service->setPrivacyQuestionsEnabled($command->isPrivacyQuestionsEnabled());
$service->setClientCredentialClientsEnabled($command->isClientCredentialClientsEnabled());
$service->setServiceType($command->getServiceType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function handle(EditServiceCommand $command): void

$service->setName($command->getName());
$service->setGuid($command->getGuid());
$service->setProductionEntitiesEnabled($command->isProductionEntitiesEnabled());
$service->setPrivacyQuestionsEnabled($command->isPrivacyQuestionsEnabled());
$service->setClientCredentialClientsEnabled($command->isClientCredentialClientsEnabled());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(
private readonly bool $privacyQuestionsEnabled,
private readonly EntityList $entityList,
private readonly RouterInterface $router,
private readonly bool $productionEntitiesEnabled = false,
) {
}

Expand All @@ -39,6 +40,7 @@ public static function fromService(DomainService $service, EntityList $entityLis
$service->isPrivacyQuestionsEnabled(),
$entityList,
$router,
$service->isProductionEntitiesEnabled()
);
}

Expand Down Expand Up @@ -71,4 +73,9 @@ public function hasTestEntities() : bool
{
return $this->getEntityList()->hasTestEntities();
}

public function isProductionEntitiesEnabled(): bool
{
return $this->productionEntitiesEnabled || $this->hasTestEntities();
}
}
16 changes: 16 additions & 0 deletions src/Surfnet/ServiceProviderDashboard/Domain/Entity/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Surfnet\ServiceProviderDashboard\Domain\Entity\PrivacyQuestions;
use Gedmo\Mapping\Annotation as Gedmo;
use Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\Repository\ServiceRepository;

/**
* @package Surfnet\ServiceProviderDashboard\Entity
*
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.UnusedPrivateField) - the createdAt field is not used in code, but used by TPM's to check for
* the creation date of a service.
Expand Down Expand Up @@ -89,6 +92,9 @@ class Service
#[ORM\Column(length: 255)]
private $teamName;

#[ORM\Column(type: 'boolean')]
private bool $productionEntitiesEnabled = false;

#[ORM\Column(type: 'boolean')]
private bool $privacyQuestionsEnabled = true;

Expand Down Expand Up @@ -192,6 +198,11 @@ public function setName($name): void
$this->name = $name;
}

public function setProductionEntitiesEnabled(bool $enabled): void
{
$this->productionEntitiesEnabled = $enabled;
}

public function setPrivacyQuestionsEnabled(bool $privacyQuestionsEnabled): void
{
$this->privacyQuestionsEnabled = $privacyQuestionsEnabled;
Expand All @@ -218,6 +229,11 @@ public function setPrivacyQuestions(PrivacyQuestions $privacyQuestions): void
$this->privacyQuestions = $privacyQuestions;
}

public function isProductionEntitiesEnabled(): bool
{
return $this->productionEntitiesEnabled;
}

public function isPrivacyQuestionsEnabled(): bool
{
return $this->privacyQuestionsEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function type(
$entityList = $this->entityService
->getEntityListForService($service)
->sortEntitiesByEnvironment();
$isProductionEnabled = $entityList->hasTestEntities() || $service->isProductionEntitiesEnabled();
$form = $this->createForm(CreateNewEntityType::class, $formId);

$form->handleRequest($request);
Expand Down Expand Up @@ -129,6 +130,7 @@ public function type(
'environment' => $targetEnvironment,
'inputId' => $inputId,
'protocols' => $choices,
'productionEnabled' => $isProductionEnabled,
'entities' => $entityList->getEntities(),
'manageId' => $formId,
]
Expand All @@ -155,7 +157,9 @@ public function create(Request $request, $serviceId, $targetEnvironment, $type):
$hasTestEntities = $this->entityService
->getEntityListForService($service)->hasTestEntities();

if (!$hasTestEntities && $targetEnvironment !== Constants::ENVIRONMENT_TEST) {
if (!$service->isProductionEntitiesEnabled() && !$hasTestEntities
&& $targetEnvironment !== Constants::ENVIRONMENT_TEST
) {
throw $this->createAccessDeniedException(
'You do not have access to create entities without publishing to the test environment first'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public function edit(Request $request, int $serviceId): RedirectResponse|Respons
$service->getGuid(),
$service->getName(),
$service->getTeamName(),
$service->isProductionEntitiesEnabled(),
$service->isPrivacyQuestionsEnabled(),
$service->isClientCredentialClientsEnabled(),
$service->getServiceType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ class WebTestFixtures extends Fixture
public function load(ObjectManager $manager): void
{
$service = $this->createService('SURFnet', self::TEAMNAME_SURF);
$service->setProductionEntitiesEnabled(false);
$manager->persist($service);

$service = $this->createService('Ibuildings B.V.', self::TEAMNAME_IBUILDINGS);
$service->setProductionEntitiesEnabled(true);
$service->setPrivacyQuestionsEnabled(true);
$service->setClientCredentialClientsEnabled(true);
$manager->persist($service);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'attr' => ['class' => 'institution-id-container'],
]
)
->add(
'productionEntitiesEnabled',
CheckboxType::class,
[
'required' => false,
]
)
->add(
'privacyQuestionsEnabled',
CheckboxType::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'attr' => ['class' => 'institution-id-container'],
]
)
->add(
'productionEntitiesEnabled',
CheckboxType::class,
[
'required' => false,
]
)
->add(
'privacyQuestionsEnabled',
CheckboxType::class,
Expand Down
2 changes: 1 addition & 1 deletion templates/EntityModal/addEntityModal.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% set fieldName = manageId ~ '_environment' %}
<li class="add-entity-field">
{% set fieldId = manageId ~ '_prod' %}
<input class="add-entity-radio" type="radio" name={{ fieldName }} id="{{ fieldId }}" value="production"{% if environment is same as('production') %} checked="checked"{% endif %}>
<input class="add-entity-radio" type="radio" name={{ fieldName }} id="{{ fieldId }}" value="production"{% if not productionEnabled %} disabled="disabled"{% endif %}{% if environment is same as('production') and productionEnabled %} checked="checked"{% endif %}>
<label class="add-entity-label" for="{{ fieldId }}">{{ 'entity.add.environment.production'|trans }}</label>
</li>
<li class="add-entity-field">
Expand Down
10 changes: 8 additions & 2 deletions templates/Service/overview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
{% set testId = "add-for-test-" ~ shortName %}
{% set productionId = "add-for-production-" ~ shortName %}
<input type="checkbox" id="{{ testId }}" name="{{ testId }}" />
<input type="checkbox" id="{{ productionId }}" name="{{ productionId }}" />
{% if service.isProductionEntitiesEnabled %}
<input type="checkbox" id="{{ productionId }}" name="{{ productionId }}" />
{% endif %}
<div class="service-status-container">
<h2 class="service-status-title">{{ service.name }}</h2>
<ul class="service-status-title-actions">
Expand Down Expand Up @@ -112,13 +114,15 @@
<td colspan="5" class="no-entities-production">{{ 'service.overview.entitylist.empty'|trans }}</td>
</tr>
{% endif %}
{% if service.isProductionEntitiesEnabled %}
<tr class="service-status-entities-table-add-entity">
<td colspan="5">
<label for="{{ productionId }}" class="link">
{{ 'entity.list.add_to_production'|trans}}
</label>
</td>
</tr>
{% endif %}
</table>

{# Test entities #}
Expand Down Expand Up @@ -178,7 +182,9 @@
</section>
</div>
<div class="blocker">
<div class="modal add-entity-modal" role="dialog" aria-label="{{ 'entity.list.add_to_production'|trans ~ ' for ' ~ shortName }}" data-for="{{ productionId }}">{{ render(controller('Surfnet\\ServiceProviderDashboard\\Infrastructure\\DashboardBundle\\Controller\\EntityCreateController::type', {serviceId: service.id, targetEnvironment: "production", inputId: productionId })) }}</div>
{% if service.isProductionEntitiesEnabled %}
<div class="modal add-entity-modal" role="dialog" aria-label="{{ 'entity.list.add_to_production'|trans ~ ' for ' ~ shortName }}" data-for="{{ productionId }}">{{ render(controller('Surfnet\\ServiceProviderDashboard\\Infrastructure\\DashboardBundle\\Controller\\EntityCreateController::type', {serviceId: service.id, targetEnvironment: "production", inputId: productionId })) }}</div>
{% endif %}
<div class="modal add-entity-modal" role="dialog" aria-label="{{ 'entity.list.add_to_test'|trans ~ ' for ' ~ shortName }}" data-for="{{ testId }}">{{ render(controller('Surfnet\\ServiceProviderDashboard\\Infrastructure\\DashboardBundle\\Controller\\EntityCreateController::type', {serviceId: service.id, targetEnvironment: "test", inputId: testId})) }}</div>
</div>
<p class="service-status-back-to-top">
Expand Down
Loading
Loading