From 93f5ccd71267a69a18882f1a3eeafdc7b901c699 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= <francois.agneray@lam.fr>
Date: Tue, 22 Mar 2022 10:08:31 +0100
Subject: [PATCH] #34 => done

---
 .../components/instance-form.component.html    |  4 ++++
 .../components/instance-form.component.ts      |  1 +
 client/src/app/app-config.service.ts           |  1 -
 .../search/containers/result.component.html    |  2 +-
 .../search/containers/result.component.ts      |  4 ----
 .../src/app/metamodel/models/instance.model.ts |  1 +
 conf-dev/create-db.sh                          |  2 +-
 docker-compose.yml                             |  3 +--
 server/app/settings.php                        |  1 -
 server/src/Action/ClientSettingsAction.php     |  1 -
 server/src/Action/InstanceAction.php           |  1 +
 server/src/Action/InstanceListAction.php       |  1 +
 server/src/Entity/Instance.php                 | 18 ++++++++++++++++++
 13 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/client/src/app/admin/instance/components/instance-form.component.html b/client/src/app/admin/instance/components/instance-form.component.html
index 50d0b6e9..9243f79a 100644
--- a/client/src/app/admin/instance/components/instance-form.component.html
+++ b/client/src/app/admin/instance/components/instance-form.component.html
@@ -101,6 +101,10 @@
             </div>
         </accordion-group>
         <accordion-group heading="Functionalities" [isOpen]="true">
+            <div class="custom-control custom-switch mb-2">
+                <input class="custom-control-input" type="checkbox" id="samp_enabled" name="samp_enabled" formControlName="samp_enabled">
+                <label class="custom-control-label" for="samp_enabled">Samp enabled</label>
+            </div>
             <div class="custom-control custom-switch mb-2">
                 <input class="custom-control-input" type="checkbox" id="search_by_criteria_allowed" name="search_by_criteria_allowed" formControlName="search_by_criteria_allowed" (change)="checkDisableSearchByCriteriaAllowed()">
                 <label class="custom-control-label" for="search_by_criteria_allowed">Classic search allowed</label>
diff --git a/client/src/app/admin/instance/components/instance-form.component.ts b/client/src/app/admin/instance/components/instance-form.component.ts
index 2b2c5c76..7166cfe4 100644
--- a/client/src/app/admin/instance/components/instance-form.component.ts
+++ b/client/src/app/admin/instance/components/instance-form.component.ts
@@ -42,6 +42,7 @@ at facilitating and homogenizing the implementation of astronomical data. It all
 the fast implementation of a project data exchange platform in a dedicated information system.`, [Validators.required]),
             home_component_logo: new FormControl('home_component_logo.png', [Validators.required])
         }),
+        samp_enabled: new FormControl(true),
         search_by_criteria_allowed: new FormControl(true),
         search_by_criteria_label: new FormControl({value: 'Search', disabled: false}),
         search_multiple_allowed: new FormControl(false),
diff --git a/client/src/app/app-config.service.ts b/client/src/app/app-config.service.ts
index 5c27615b..604ad74d 100644
--- a/client/src/app/app-config.service.ts
+++ b/client/src/app/app-config.service.ts
@@ -5,7 +5,6 @@ export class AppConfigService {
     public apiUrl: string;
     public servicesUrl: string;
     public baseHref: string;
-    public sampEnabled: string;
     public authenticationEnabled: boolean;
     public ssoAuthUrl: string;
     public ssoRealm: string;
diff --git a/client/src/app/instance/search/containers/result.component.html b/client/src/app/instance/search/containers/result.component.html
index 3a1eabae..f35f242a 100644
--- a/client/src/app/instance/search/containers/result.component.html
+++ b/client/src/app/instance/search/containers/result.component.html
@@ -25,7 +25,7 @@
                     selected with <span class="font-weight-bold">{{ dataLength | async }}</span> objects found.
                 </div>
             </div>
-            <div *ngIf="sampEnabled()" class="jumbotron mb-4 py-4">
+            <div *ngIf="(instance | async).samp_enabled" class="jumbotron mb-4 py-4">
                 <div class="lead">
                     <ng-container *ngIf="!(sampRegistered | async)">
                         You are not connected to a SAMP-hub
diff --git a/client/src/app/instance/search/containers/result.component.ts b/client/src/app/instance/search/containers/result.component.ts
index 8d93cdba..d42af07b 100644
--- a/client/src/app/instance/search/containers/result.component.ts
+++ b/client/src/app/instance/search/containers/result.component.ts
@@ -75,10 +75,6 @@ export class ResultComponent extends AbstractSearchComponent {
         });
     }
 
-    sampEnabled() {
-        return this.appConfig.sampEnabled;
-    }
-
     /**
      * Dispatches action to register to SAMP.
      */
diff --git a/client/src/app/metamodel/models/instance.model.ts b/client/src/app/metamodel/models/instance.model.ts
index 8e35fa2e..7962ff59 100644
--- a/client/src/app/metamodel/models/instance.model.ts
+++ b/client/src/app/metamodel/models/instance.model.ts
@@ -28,6 +28,7 @@ export interface Instance {
         home_component_text: string;
         home_component_logo: string;
     };
+    samp_enabled: boolean;
     search_by_criteria_allowed: boolean;
     search_by_criteria_label: string;
     search_multiple_allowed: boolean;
diff --git a/conf-dev/create-db.sh b/conf-dev/create-db.sh
index 61395832..83bd0d4d 100644
--- a/conf-dev/create-db.sh
+++ b/conf-dev/create-db.sh
@@ -60,7 +60,7 @@ curl -d '{"label":"Spectra graph","value":"spectra_graph","display":20,"select_n
 curl -d '{"label":"Test","dbname":"anis_test","dbtype":"pdo_pgsql","dbhost":"db","dbport":5432,"dblogin":"anis","dbpassword":"anis"}' --header 'Content-Type: application/json' -X POST http://localhost/database
 
 # Add default instance
-curl -d '{"name":"default","label":"Default instance","description":"Instance for the test","display":10,"data_path":"\/DEFAULT","portal_logo":"","design_color":"#7AC29A","design_background_color":"#ffffff","design_logo":"logo.png","design_favicon":"favicon.ico","home_component":"WelcomeComponent","home_component_config":{"home_component_text":"AstroNomical Information System","home_component_logo":"home_component_logo.png"},"search_by_criteria_allowed":true,"search_by_criteria_label":"Search","search_multiple_allowed":false,"search_multiple_label":"Search multiple","search_multiple_all_datasets_selected":false,"documentation_allowed":false,"documentation_label":"Documentation"}' --header 'Content-Type: application/json' -X POST http://localhost/instance
+curl -d '{"name":"default","label":"Default instance","description":"Instance for the test","display":10,"data_path":"\/DEFAULT","portal_logo":"","design_color":"#7AC29A","design_background_color":"#ffffff","design_logo":"logo.png","design_favicon":"favicon.ico","home_component":"WelcomeComponent","home_component_config":{"home_component_text":"AstroNomical Information System","home_component_logo":"home_component_logo.png"},"samp_enabled":true,"search_by_criteria_allowed":true,"search_by_criteria_label":"Search","search_multiple_allowed":false,"search_multiple_label":"Search multiple","search_multiple_all_datasets_selected":false,"documentation_allowed":false,"documentation_label":"Documentation"}' --header 'Content-Type: application/json' -X POST http://localhost/instance
 
 # Add ANIS, SVOM and IRIS surveys
 curl -d '{"name":"anis_survey","label":"ANIS survey","description":"Survey used for testing","link":"https://anis.lam.fr","manager":"F. Agneray","id_database":1}' --header 'Content-Type: application/json' -X POST http://localhost/survey
diff --git a/docker-compose.yml b/docker-compose.yml
index eb381ed7..06b8074d 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -33,11 +33,10 @@ services:
             LOGGER_LEVEL: "debug"
             SERVICES_URL: "http://localhost:5000"
             BASE_HREF: "/"
-            SAMP_ENABLED: 1
             SSO_AUTH_URL: "http://localhost:8180/auth"
             SSO_REALM: "anis"
             SSO_CLIENT_ID: "anis-client"
-            TOKEN_ENABLED: 1
+            TOKEN_ENABLED: 0
             TOKEN_JWKS_URL: "http://keycloak:8180/auth/realms/anis/protocol/openid-connect/certs"
             TOKEN_ADMIN_ROLES: anis_admin,superuser
             RMQ_HOST: rmq
diff --git a/server/app/settings.php b/server/app/settings.php
index 5ceab1a8..e062e3ef 100644
--- a/server/app/settings.php
+++ b/server/app/settings.php
@@ -35,7 +35,6 @@ return [
     ],
     'services_url' => getenv('SERVICES_URL'),
     'base_href' => getenv('BASE_HREF'),
-    'samp_enabled' => getenv('SAMP_ENABLED'),
     'sso' => [
         'auth_url' => getenv('SSO_AUTH_URL'),
         'realm' => getenv('SSO_REALM'),
diff --git a/server/src/Action/ClientSettingsAction.php b/server/src/Action/ClientSettingsAction.php
index 5b84798e..9ccc6f48 100644
--- a/server/src/Action/ClientSettingsAction.php
+++ b/server/src/Action/ClientSettingsAction.php
@@ -52,7 +52,6 @@ final class ClientSettingsAction
         $payload = json_encode(array(
             'servicesUrl' => $this->settings['services_url'],
             'baseHref' => $this->settings['base_href'],
-            'sampEnabled' => boolval($this->settings['samp_enabled']),
             'authenticationEnabled' => boolval($this->settings['token']['enabled']),
             'ssoAuthUrl' => $this->settings['sso']['auth_url'],
             'ssoRealm' => $this->settings['sso']['realm'],
diff --git a/server/src/Action/InstanceAction.php b/server/src/Action/InstanceAction.php
index ca8600d0..750bd1b7 100644
--- a/server/src/Action/InstanceAction.php
+++ b/server/src/Action/InstanceAction.php
@@ -106,6 +106,7 @@ final class InstanceAction extends AbstractAction
         $instance->setDesignFavicon($parsedBody['design_favicon']);
         $instance->setHomeComponent($parsedBody['home_component']);
         $instance->setHomeComponentConfig($parsedBody['home_component_config']);
+        $instance->setSampEnabled($parsedBody['samp_enabled']);
         $instance->setSearchByCriteriaAllowed($parsedBody['search_by_criteria_allowed']);
         $instance->setSearchByCriteriaLabel($parsedBody['search_by_criteria_label']);
         $instance->setSearchMultipleAllowed($parsedBody['search_multiple_allowed']);
diff --git a/server/src/Action/InstanceListAction.php b/server/src/Action/InstanceListAction.php
index f0b6fe34..628961d4 100644
--- a/server/src/Action/InstanceListAction.php
+++ b/server/src/Action/InstanceListAction.php
@@ -89,6 +89,7 @@ final class InstanceListAction extends AbstractAction
         $instance->setDesignFavicon($parsedBody['design_favicon']);
         $instance->setHomeComponent($parsedBody['home_component']);
         $instance->setHomeComponentConfig($parsedBody['home_component_config']);
+        $instance->setSampEnabled($parsedBody['samp_enabled']);
         $instance->setSearchByCriteriaAllowed($parsedBody['search_by_criteria_allowed']);
         $instance->setSearchByCriteriaLabel($parsedBody['search_by_criteria_label']);
         $instance->setSearchMultipleAllowed($parsedBody['search_multiple_allowed']);
diff --git a/server/src/Entity/Instance.php b/server/src/Entity/Instance.php
index 9786c138..213386f3 100644
--- a/server/src/Entity/Instance.php
+++ b/server/src/Entity/Instance.php
@@ -108,6 +108,13 @@ class Instance implements \JsonSerializable
      */
     protected $homeComponentConfig;
 
+    /**
+     * @var bool
+     *
+     * @Column(type="boolean", name="samp_enabled", nullable=false)
+     */
+    protected $sampEnabled;
+
     /**
      * @var bool
      *
@@ -286,6 +293,16 @@ class Instance implements \JsonSerializable
         $this->homeComponentConfig = $homeComponentConfig;
     }
 
+    public function getSampEnabled()
+    {
+        return $this->sampEnabled;
+    }
+
+    public function setSampEnabled($sampEnabled)
+    {
+        $this->sampEnabled = $sampEnabled;
+    }
+
     public function getSearchByCriteriaAllowed()
     {
         return $this->searchByCriteriaAllowed;
@@ -385,6 +402,7 @@ class Instance implements \JsonSerializable
             'design_favicon' => $this->getDesignFavicon(),
             'home_component' => $this->getHomeComponent(),
             'home_component_config' => $this->getHomeComponentConfig(),
+            'samp_enabled' => $this->getSampEnabled(),
             'search_by_criteria_allowed' => $this->getSearchByCriteriaAllowed(),
             'search_by_criteria_label' => $this->getSearchByCriteriaLabel(),
             'search_multiple_allowed' => $this->getSearchMultipleAllowed(),
-- 
GitLab