diff --git a/controlpanel/api/models/app.py b/controlpanel/api/models/app.py index 21dc8b1a3..e94041b28 100644 --- a/controlpanel/api/models/app.py +++ b/controlpanel/api/models/app.py @@ -249,15 +249,6 @@ def auth0_client_name(self, env_name=None): return settings.AUTH0_CLIENT_NAME_PATTERN.format( app_name=client_name, env=env_name) - @property - def migration_info(self): - # TODO: using app.description for temporary place for storing old app info, - # The content of this field should be removed after app migration is completed. - try: - return json.loads(self.description).get("migration", {}) - except ValueError: - return {} - def app_url_name(self, env_name): format_pattern = settings.APP_URL_NAME_PATTERN.get(env_name.upper()) if not format_pattern: diff --git a/controlpanel/cli/management/commands/post_migration_clearup.py b/controlpanel/cli/management/commands/post_migration_clearup.py new file mode 100644 index 000000000..8315a72c6 --- /dev/null +++ b/controlpanel/cli/management/commands/post_migration_clearup.py @@ -0,0 +1,91 @@ + +# Third-party +from django.core.management.base import BaseCommand + +# First-party/Local +from controlpanel.api.models import App, AppS3Bucket +from controlpanel.api import auth0 + + +class Command(BaseCommand): + help = "Clear up the redundant resources for migrated apps " \ + "- remove the old auth0 related resources " \ + "- remove old auth0 information from control db" \ + "- remove the apps which are not required any more" + + SCRIPT_LOG_FILE_NAME = "./clear_up_auth0_resources_log.txt" + + EXCEPTION_APPS = ["gold-scorecard-form"] + + def add_arguments(self, parser): + parser.add_argument( + "-a", "--apply", action="store_true", help="Apply the actions" + ) + + def _remove_old_auth0_clients(self, app, auth0_instance): + old_client_info = (app.app_conf or {}).get(App.KEY_WORD_FOR_AUTH_SETTINGS, {}).\ + get(App.DEFAULT_AUTH_CATEGORY, {}) + if not old_client_info: + self._log_info(f"No old client for {app.slug} - {app.repo_url}") + return + + self._log_info(f"Removing the old client for {app.slug} - {app.repo_url}") + if self.apply_action: + auth0_instance.clear_up_app(old_client_info) + + def _update_db(self, app): + self._log_info(f"Removing the migration info and old clients for {app.slug} - {app.repo_url}") + app.description = "" + if App.DEFAULT_AUTH_CATEGORY in (app.app_conf or {}).get(App.KEY_WORD_FOR_AUTH_SETTINGS, {}): + del app.app_conf[App.KEY_WORD_FOR_AUTH_SETTINGS][App.DEFAULT_AUTH_CATEGORY] + if self.apply_action: + app.save() + + def _remove_application(self, app): + self._log_info(f"Removing the application {app.slug} - {app.repo_url}") + + """ TODO: how to deal with related bucket? we will output + the related datasets from this script""" + # log the related buckets information into file + related_buckets = AppS3Bucket.objects.filter(app_id=app.id) + for item in related_buckets: + self._log_info(f"The app links the bucket - {item.s3bucket.name}") + # Remove the relationship to avoid removal of the bucket when removing the app + if self.apply_action: + item.delete() + if self.apply_action: + app.delete() + + def _log_info(self, info): + self.stdout.write(info) + with open(self.SCRIPT_LOG_FILE_NAME, "a") as f: + f.write(info) + f.write("\n") + + def _clear_up_resources(self, auth0_instance): + apps = App.objects.all() + counter = 1 + for app in apps: + if app.slug in self.EXCEPTION_APPS: + self._log_info(f"Ignore the application {app.slug}") + continue + + try: + self._log_info(f"{counter}--Processing the application {app.slug}") + + self._remove_old_auth0_clients(app, auth0_instance) + self._update_db(app) + if "moj-analytical-services" in app.repo_url: + self._remove_application(app) + self._log_info(f"{counter}--Done with the application {app.slug}") + counter += 1 + except Exception as ex: + self._log_info(f"Failed to process {app.slug} due to error : {ex.__str__()}") + + def handle(self, *args, **options): + self.stdout.write("start to scan the apps from database.") + auth0_instance = auth0.ExtendedAuth0() + self.apply_action = options.get('apply') or False + self._clear_up_resources(auth0_instance) + self.stdout.write("Clean up action has completed.") + diff --git a/controlpanel/develop/__init__.py b/controlpanel/develop/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/controlpanel/develop/apps.py b/controlpanel/develop/apps.py deleted file mode 100644 index 0aa76d51a..000000000 --- a/controlpanel/develop/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -# Third-party -from django.apps import AppConfig - - -class DevelopConfig(AppConfig): - name = "controlpanel.develop" diff --git a/controlpanel/develop/models.py b/controlpanel/develop/models.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/controlpanel/develop/templates/develop/index.html b/controlpanel/develop/templates/develop/index.html deleted file mode 100644 index f4ff53dec..000000000 --- a/controlpanel/develop/templates/develop/index.html +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - -

Development integration page

-

User: {{ username }}

- -

Status: {{ status | default:"Pending" }}

- -
- {% csrf_token %} - Tool installation - Jupyter Lab
- RStudio
- Airflow
- - -
- - -

Currently installed tools

- - - - - diff --git a/controlpanel/develop/urls.py b/controlpanel/develop/urls.py deleted file mode 100644 index 73f35aad8..000000000 --- a/controlpanel/develop/urls.py +++ /dev/null @@ -1,8 +0,0 @@ -# Third-party -from django.urls import path - -from .views import develop_index - -urlpatterns = [ - path("", develop_index, name="develop_index"), -] diff --git a/controlpanel/develop/views.py b/controlpanel/develop/views.py deleted file mode 100644 index 235537c04..000000000 --- a/controlpanel/develop/views.py +++ /dev/null @@ -1,45 +0,0 @@ -# Standard library -from typing import List - -# Third-party -from django.contrib.auth.decorators import login_required -from django.shortcuts import render - - -def installed_tools(username: str) -> List[str]: - # TODO: Get a list of this user's installed tools and return - # a list of string ["like", "this"] - - return [] - - -def user_selected_tool(username: str, toolname: str) -> str: - # TODO: Create/Ensure instance of the named tool - - return f"Install {toolname} for {username}" - - -@login_required() -def develop_index(request): - status = None - tool = None - - if request.method == "POST": - data = request.POST - - tool = data.get("tool", "") - if not tool: - status = "No tool selected" - else: - status = user_selected_tool(request.user, tool) - - return render( - request, - "develop/index.html", - { - "username": request.user, - "status": status, - "tool": tool, - "installed_tools": installed_tools(request.user), - }, - ) diff --git a/controlpanel/frontend/jinja2/webapp-detail.html b/controlpanel/frontend/jinja2/webapp-detail.html index b6dee5f70..99155982d 100644 --- a/controlpanel/frontend/jinja2/webapp-detail.html +++ b/controlpanel/frontend/jinja2/webapp-detail.html @@ -13,7 +13,6 @@ {% set page_title = app.name %} {% set app_domain = settings.APP_DOMAIN %} {% set app_old_url = "https://" + app.slug + "." + settings.APP_DOMAIN_BEFORE_MIGRATION %} -{% set feature_enabled = settings.features.app_migration.enabled %} {% set app_admins_html %} {% include "modals/app_admins.html" %} @@ -26,53 +25,17 @@ {% block content %}
- {% if feature_enabled %} -
-
- - - Warning - More information and user guidance for the webapp deployment pipeline and related settings will be provided soon. If you have questions about the app migration process, please contact us on the #data-platform-application-migration-support Slack channel. - -
-
-
-
- {% endif %} Webapp

{{ page_title }}

- {% if feature_enabled %} -

Migration status:

- {% if app_migration_status == "in_progress" %} -

This app is currently being migrated. It has been deployed onto Cloud Platform for testing, and the original version is still available on the Alpha cluster.

- -

- The above information about old app will be removed once the migration process is completed. -

- {% elif app_migration_status == "done" %} -

- The migration for this app has been completed -

- {% else %} -

- The migration process for this app has not been started yet! -

- {% endif %} - {% else %} - {% if app.description %} -

- {{ app.description }} -

- {% endif %} + {% if app.description %} +

+ {{ app.description }} +

{% endif %} - {% if feature_enabled and repo_access_error_msg %} + {% if repo_access_error_msg %}
@@ -91,14 +54,6 @@

{% endif %} - {% if not app_migration_info and app_old_url %} -

Deployed URL

-

If the app was successfully built on the alpha (original) cluster, it can be accessed here:

-

- {{ app_old_url }} -

- {% endif %} -

Source Code Repository

{% if app.repo_url %} @@ -108,53 +63,49 @@

Source Code Repository

{% endif %}

- {% if feature_enabled %} - -

App logs

-

- {{ settings.KIBANA_BASE_URL }} -

+

App logs

+

+ {{ settings.KIBANA_BASE_URL }} +

-

App resources usage dashboard

-

- {{ settings.GRAFANA_BASE_URL }} -

+

App resources usage dashboard

+

+ {{ settings.GRAFANA_BASE_URL }} +

-

Deployment Pipeline

-

Github workflows on app's repo are used for deploying the app.

-

You are required to be member of admin team for this app repo in order to be able to maintain the deployments settings

- {% endif %} +

Deployment Pipeline

+

Github workflows on app's repo are used for deploying the app.

+

You are required to be member of admin team for this app repo in order to be able to maintain the deployments settings

- {% if feature_enabled %} - {% if github_settings_access_error_msg %} - - {% endif %} - {% for env_name, deployment_setting in deployments_settings.items() %} -

Deployment settings under {{ env_name }}

- {% if deployment_setting.get('is_redundant') and request.user.has_perm('api.update_app', app) %} -
-

It appears this deployment environment is redundant and can be removed

-
- {{ csrf_input }} - -
-
- {% else %} - {{ app_deployment_settings(app, env_name, app_domain, deployment_setting, request, csrf_input) }} - {% endif %} - {% endfor %} + {% if github_settings_access_error_msg %} + {% endif %} + {% for env_name, deployment_setting in deployments_settings.items() %} +

Deployment settings under {{ env_name }}

+ {% if deployment_setting.get('is_redundant') and request.user.has_perm('api.update_app', app) %} +
+

It appears this deployment environment is redundant and can be removed

+
+ {{ csrf_input }} + +
+
+ {% else %} + {{ app_deployment_settings(app, env_name, app_domain, deployment_setting, request, csrf_input) }} + {% endif %} + {% endfor %} +
diff --git a/controlpanel/frontend/jinja2/webapp-update-ip-allowlists.html b/controlpanel/frontend/jinja2/webapp-update-ip-allowlists.html index d3ecc5626..d772af857 100644 --- a/controlpanel/frontend/jinja2/webapp-update-ip-allowlists.html +++ b/controlpanel/frontend/jinja2/webapp-update-ip-allowlists.html @@ -14,8 +14,6 @@ {% endif %} - {% if app_migration_feature_enabled %} -
{{ csrf_input }} @@ -44,12 +42,6 @@ contact the Analytical Platform team via our support Slack channel.

- {% else %} - -

IP allowlists for {{app.name}}

-

This feature is not yet available for general use.

- - {% endif %}
diff --git a/controlpanel/frontend/views/app.py b/controlpanel/frontend/views/app.py index d009bcd74..d4edceadc 100644 --- a/controlpanel/frontend/views/app.py +++ b/controlpanel/frontend/views/app.py @@ -128,9 +128,6 @@ def get_context_data(self, **kwargs): context["repo_access_error_msg"] = access_repo_error_msg context["github_settings_access_error_msg"] = github_settings_access_error_msg - # TODO: The following field should be removed after app migration - context["app_migration_info"] = app.migration_info - context["app_migration_status"] = context["app_migration_info"].get('status', "") return context @@ -223,9 +220,6 @@ class UpdateAppIPAllowlists( def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) context["app"] = self.get_object() - context[ - "app_migration_feature_enabled" - ] = settings.features.app_migration.enabled context["env_name"] = self.request.GET.get("env_name") context["app_ip_allowlists"] = [ { diff --git a/controlpanel/frontend/views/tool.py b/controlpanel/frontend/views/tool.py index 9a475882f..1943d71c4 100644 --- a/controlpanel/frontend/views/tool.py +++ b/controlpanel/frontend/views/tool.py @@ -220,9 +220,6 @@ def get_context_data(self, *args, **kwargs): id_token = user.get_id_token() context = super().get_context_data(*args, **kwargs) - context[ - "ip_range_feature_enabled" - ] = settings.features.app_migration.enabled # noqa: E501 context["user_guidance_base_url"] = settings.USER_GUIDANCE_BASE_URL context["aws_service_url"] = settings.AWS_SERVICE_URL diff --git a/controlpanel/middleware/__init__.py b/controlpanel/middleware/__init__.py index db89777f5..7f5761b18 100644 --- a/controlpanel/middleware/__init__.py +++ b/controlpanel/middleware/__init__.py @@ -1,3 +1,2 @@ # First-party/Local -from controlpanel.middleware.legacy_api_redirect import LegacyAPIRedirectMiddleware from controlpanel.middleware.never_cache import DisableClientSideCachingMiddleware diff --git a/controlpanel/middleware/legacy_api_redirect.py b/controlpanel/middleware/legacy_api_redirect.py deleted file mode 100644 index f4c6cb72a..000000000 --- a/controlpanel/middleware/legacy_api_redirect.py +++ /dev/null @@ -1,41 +0,0 @@ -# Standard library -import re - -# Third-party -import structlog -from django.conf import settings - -API_PATH = re.compile(r"^/(?P[^/]+)") - -log = structlog.getLogger(__name__) - - -class LegacyAPIRedirectMiddleware: - def __init__(self, get_response): - self.get_response = get_response - - def __call__(self, request): - if settings.features.redirect_legacy_api_urls.enabled: - json_requested = request.META.get("HTTP_ACCEPT") == "application/json" - is_api_path = legacy_api_path(request.path_info) - - if is_api_path and json_requested: - log.debug(f"Redirecting legacy API request: {request.path_info}") - request.urlconf = "controlpanel.api.urls" - - return self.get_response(request) - - -def legacy_api_path(path): - match = API_PATH.match(path) - if match: - return match.group("resource") in [ - "apps", - "apps3buckets", - "groups", - "s3buckets", - "userapps", - "users", - "users3buckets", - "tools", - ] diff --git a/controlpanel/settings/common.py b/controlpanel/settings/common.py index 775215e00..f9dfd7a30 100644 --- a/controlpanel/settings/common.py +++ b/controlpanel/settings/common.py @@ -83,7 +83,6 @@ MIDDLEWARE = [ "django_prometheus.middleware.PrometheusBeforeMiddleware", "controlpanel.middleware.DisableClientSideCachingMiddleware", - "controlpanel.middleware.LegacyAPIRedirectMiddleware", "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", diff --git a/controlpanel/settings/development.py b/controlpanel/settings/development.py index 836f1f052..022995e1b 100644 --- a/controlpanel/settings/development.py +++ b/controlpanel/settings/development.py @@ -10,9 +10,6 @@ # Allow all hostnames to access the server ALLOWED_HOSTS = ["localhost", "127.0.0.1", "0.0.0.0"] -# Install the develop pages in development mode -INSTALLED_APPS.append("controlpanel.develop") # noqa: F405 - # Enable Django debug toolbar if os.environ.get("ENABLE_DJANGO_DEBUG_TOOLBAR"): MIDDLEWARE.insert( # noqa: F405, E501 diff --git a/controlpanel/urls.py b/controlpanel/urls.py index 555ccb7b6..f74ded820 100644 --- a/controlpanel/urls.py +++ b/controlpanel/urls.py @@ -20,9 +20,5 @@ path("metrics", exports.ExportToDjangoView, name="prometheus-django-metrics"), ] -if "controlpanel.develop" in settings.INSTALLED_APPS: - urlpatterns += [ - path("develop/", include("controlpanel.develop.urls")), - ] urlpatterns += staticfiles_urlpatterns() diff --git a/settings.yaml b/settings.yaml index 87b607249..948167d1e 100644 --- a/settings.yaml +++ b/settings.yaml @@ -1,9 +1,4 @@ enabled_features: - app_migration: - _DEFAULT: false - _HOST_dev: true - _HOST_prod: true - _HOST_alpha: true redirect_legacy_api_urls: _DEFAULT: true s3_folders: diff --git a/tests/frontend/views/test_app.py b/tests/frontend/views/test_app.py index e3d6b207c..6c34ac3e9 100644 --- a/tests/frontend/views/test_app.py +++ b/tests/frontend/views/test_app.py @@ -482,9 +482,7 @@ def test_delete_customer_by_email(client, app, users, side_effect, expected_mess def test_github_error1_on_app_detail(client, app, users,): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag, \ - patch("controlpanel.api.cluster.App.get_deployment_envs") as get_envs: - feature_flag.return_value = True + with patch("controlpanel.api.cluster.App.get_deployment_envs") as get_envs: error_msg = "Testing github error" get_envs.side_effect = requests.exceptions.HTTPError(error_msg) client.force_login(users["superuser"]) @@ -494,9 +492,7 @@ def test_github_error1_on_app_detail(client, app, users,): def test_github_error2_on_app_detail(client, app, users, repos): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag, \ - patch("controlpanel.api.cluster.App.get_env_secrets") as get_secrets: - feature_flag.return_value = True + with patch("controlpanel.api.cluster.App.get_env_secrets") as get_secrets: error_msg = "Testing github secret error" get_secrets.side_effect = requests.exceptions.HTTPError(error_msg) client.force_login(users["superuser"]) @@ -506,10 +502,8 @@ def test_github_error2_on_app_detail(client, app, users, repos): def test_github_error3_on_app_detail(client, app, users, repos): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag, \ - patch("controlpanel.api.cluster.App.get_env_secrets") as get_secrets, \ + with patch("controlpanel.api.cluster.App.get_env_secrets") as get_secrets, \ patch("controlpanel.api.cluster.App.get_env_vars") as get_env_vars: - feature_flag.return_value = True error_msg = "Testing github env error" get_secrets.return_value = [{"name": "testing_github_secret"}] get_env_vars.side_effect = requests.exceptions.HTTPError(error_msg) @@ -520,49 +514,43 @@ def test_github_error3_on_app_detail(client, app, users, repos): def test_app_detail_display_all_envs(client, app, users, repos): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag: - feature_flag.return_value = True - client.force_login(users["superuser"]) - response = detail(client, app) - assert response.status_code == 200 - - key_words_for_checks = [ - "Deployment settings under dev_env", - "Deployment settings under prod_env", - cluster.App.IP_RANGES, - cluster.App.AUTH0_CLIENT_ID, - cluster.App.AUTH0_CLIENT_SECRET, - cluster.App.AUTH0_DOMAIN, - cluster.App.AUTH0_CONNECTIONS, - cluster.App.AUTHENTICATION_REQUIRED, - cluster.App.AUTH0_PASSWORDLESS, - ] - for key_word in key_words_for_checks: - assert key_word in str(response.content) + client.force_login(users["superuser"]) + response = detail(client, app) + assert response.status_code == 200 + + key_words_for_checks = [ + "Deployment settings under dev_env", + "Deployment settings under prod_env", + cluster.App.IP_RANGES, + cluster.App.AUTH0_CLIENT_ID, + cluster.App.AUTH0_CLIENT_SECRET, + cluster.App.AUTH0_DOMAIN, + cluster.App.AUTH0_CONNECTIONS, + cluster.App.AUTHENTICATION_REQUIRED, + cluster.App.AUTH0_PASSWORDLESS, + ] + for key_word in key_words_for_checks: + assert key_word in str(response.content) def test_app_detail_with_missing_auth_client(client, users, repos_for_missing_auth): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag: - feature_flag.return_value = True - app = mommy.make("api.App") - app.repo_url = "https://github.com/github_org/testing_repo_with_auth" - app.save() + app = mommy.make("api.App") + app.repo_url = "https://github.com/github_org/testing_repo_with_auth" + app.save() - client.force_login(users["superuser"]) - response = detail(client, app) - btn_text = "Create auth0 client" - assert response.status_code == 200 - assert btn_text in str(response.content) + client.force_login(users["superuser"]) + response = detail(client, app) + btn_text = "Create auth0 client" + assert response.status_code == 200 + assert btn_text in str(response.content) def test_app_detail_with_auth_client_redundant(client, users, app, repos_for_redundant_auth): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag: - feature_flag.return_value = True - client.force_login(users["superuser"]) - response = detail(client, app) - btn_text = "Remove auth0 client" - assert response.status_code == 200 - assert btn_text in str(response.content) + client.force_login(users["superuser"]) + response = detail(client, app) + btn_text = "Remove auth0 client" + assert response.status_code == 200 + assert btn_text in str(response.content) @pytest.fixture @@ -585,17 +573,6 @@ def app_being_migrated(users): return app -def test_app_description_display_old_app_info(client, app_being_migrated, users): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag: - feature_flag.return_value = True - client.force_login(users["superuser"]) - response = detail(client, app_being_migrated) - assert response.status_code == 200 - assert app_being_migrated.migration_info["app_name"] in str(response.content) - assert app_being_migrated.migration_info["repo_url"] in str(response.content) - assert app_being_migrated.migration_info["app_url"] in str(response.content) - - def get_auth_settings(content, env_name): soup = BeautifulSoup(content, "html.parser") setting_panel = soup.find("section", {"class": f"{env_name}-settings-panel"}) @@ -610,92 +587,86 @@ def locate_setting_ui(settings, setting_name): def test_app_detail_with_auth_on(client, app, users, repos_with_auth): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag: - feature_flag.return_value = True - client.force_login(users["superuser"]) - response = detail(client, app) - assert response.status_code == 200 - auth_settings = get_auth_settings(response.content, 'dev_env') - settings_for_checks = [ - {"n": cluster.App.IP_RANGES, - "v": app.env_allowed_ip_ranges_names('dev_env'), - "e": True}, - {"n": cluster.App.AUTH0_CLIENT_ID, - "v": settings.SECRET_DISPLAY_VALUE, - "e": False}, - {"n": cluster.App.AUTH0_CLIENT_SECRET, - "v": settings.SECRET_DISPLAY_VALUE, - "e": False}, - {"n": cluster.App.AUTH0_CONNECTIONS, "v": "[]", "e": True}, - {"n": cluster.App.AUTH0_DOMAIN, "v": "http://testing", "e": False}, - {"n": cluster.App.AUTH0_PASSWORDLESS, "v": "False", "e": False}, - {"n": cluster.App.AUTHENTICATION_REQUIRED, "v": "True", "e": True}, - ] - for item in settings_for_checks: - auth_item_ui = locate_setting_ui(auth_settings, item['n']) - if not auth_item_ui: - continue - assert item['v'] in auth_item_ui.text - if item['e']: - assert 'Edit' in auth_item_ui.text - else: - assert 'Edit' not in auth_item_ui.text + client.force_login(users["superuser"]) + response = detail(client, app) + assert response.status_code == 200 + auth_settings = get_auth_settings(response.content, 'dev_env') + settings_for_checks = [ + {"n": cluster.App.IP_RANGES, + "v": app.env_allowed_ip_ranges_names('dev_env'), + "e": True}, + {"n": cluster.App.AUTH0_CLIENT_ID, + "v": settings.SECRET_DISPLAY_VALUE, + "e": False}, + {"n": cluster.App.AUTH0_CLIENT_SECRET, + "v": settings.SECRET_DISPLAY_VALUE, + "e": False}, + {"n": cluster.App.AUTH0_CONNECTIONS, "v": "[]", "e": True}, + {"n": cluster.App.AUTH0_DOMAIN, "v": "http://testing", "e": False}, + {"n": cluster.App.AUTH0_PASSWORDLESS, "v": "False", "e": False}, + {"n": cluster.App.AUTHENTICATION_REQUIRED, "v": "True", "e": True}, + ] + for item in settings_for_checks: + auth_item_ui = locate_setting_ui(auth_settings, item['n']) + if not auth_item_ui: + continue + assert item['v'] in auth_item_ui.text + if item['e']: + assert 'Edit' in auth_item_ui.text + else: + assert 'Edit' not in auth_item_ui.text def test_app_detail_with_auth_off(client, app, users, repos_for_no_auth): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag: - feature_flag.return_value = True - client.force_login(users["superuser"]) - response = detail(client, app) - assert response.status_code == 200 + client.force_login(users["superuser"]) + response = detail(client, app) + assert response.status_code == 200 + + settings_no_displayed = [ + cluster.App.AUTH0_DOMAIN, + cluster.App.AUTH0_CLIENT_ID, + cluster.App.AUTH0_CLIENT_SECRET, + cluster.App.AUTH0_CONNECTIONS, + cluster.App.AUTH0_PASSWORDLESS, + ] - settings_no_displayed = [ - cluster.App.AUTH0_DOMAIN, - cluster.App.AUTH0_CLIENT_ID, - cluster.App.AUTH0_CLIENT_SECRET, - cluster.App.AUTH0_CONNECTIONS, - cluster.App.AUTH0_PASSWORDLESS, - ] - - auth_settings = get_auth_settings(response.content, 'dev_env') - for item in settings_no_displayed: - auth_item_ui = locate_setting_ui(auth_settings, item) - assert auth_item_ui is None - - settings_for_checks = [ - {"n": cluster.App.IP_RANGES, - "v": app.env_allowed_ip_ranges_names('dev_env'), - "e": True}, - {"n": cluster.App.AUTHENTICATION_REQUIRED, "v": "False", "e": True}, - ] - for item in settings_for_checks: - auth_item_ui = locate_setting_ui(auth_settings, item['n']) - if not auth_item_ui: - continue - assert item['v'] in auth_item_ui.text - assert 'Edit' in auth_item_ui.text + auth_settings = get_auth_settings(response.content, 'dev_env') + for item in settings_no_displayed: + auth_item_ui = locate_setting_ui(auth_settings, item) + assert auth_item_ui is None + + settings_for_checks = [ + {"n": cluster.App.IP_RANGES, + "v": app.env_allowed_ip_ranges_names('dev_env'), + "e": True}, + {"n": cluster.App.AUTHENTICATION_REQUIRED, "v": "False", "e": True}, + ] + for item in settings_for_checks: + auth_item_ui = locate_setting_ui(auth_settings, item['n']) + if not auth_item_ui: + continue + assert item['v'] in auth_item_ui.text + assert 'Edit' in auth_item_ui.text def test_app_detail_with_self_define_settings(client, app, users, repos): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag: - feature_flag.return_value = True - client.force_login(users["superuser"]) - response = detail(client, app) - assert response.status_code == 200 + client.force_login(users["superuser"]) + response = detail(client, app) + assert response.status_code == 200 - auth_settings = get_auth_settings(response.content, 'dev_env') - settings_for_checks = [ - {"n": "PARAM_SECRET", "v": settings.SECRET_DISPLAY_VALUE}, - {"n": "PARAM_VAR", "v": "test_var"}, - ] - for item in settings_for_checks: - auth_item_ui = locate_setting_ui(auth_settings, item['n']) - if not auth_item_ui: - continue - setting_link = auth_item_ui.findAll("a")[0]["href"] - assert f"{settings.APP_SELF_DEFINE_SETTING_PREFIX}{item['n']}" in setting_link - assert item['v'] in auth_item_ui.text - assert 'Edit' in auth_item_ui.text + auth_settings = get_auth_settings(response.content, 'dev_env') + settings_for_checks = [ + {"n": "PARAM_SECRET", "v": settings.SECRET_DISPLAY_VALUE}, + {"n": "PARAM_VAR", "v": "test_var"}, + ] + for item in settings_for_checks: + auth_item_ui = locate_setting_ui(auth_settings, item['n']) + if not auth_item_ui: + continue + setting_link = auth_item_ui.findAll("a")[0]["href"] + assert f"{settings.APP_SELF_DEFINE_SETTING_PREFIX}{item['n']}" in setting_link + assert item['v'] in auth_item_ui.text + assert 'Edit' in auth_item_ui.text @pytest.mark.parametrize( @@ -706,36 +677,34 @@ def test_app_detail_with_self_define_settings(client, app, users, repos): ], ) def test_app_settings_permission(client, app, users, repos_with_auth, user, can_edit_connections): - with patch('django.conf.settings.features.app_migration.enabled') as feature_flag: - feature_flag.return_value = True - client.force_login(users[user]) - response = detail(client, app) - assert response.status_code == 200 - auth_settings = get_auth_settings(response.content, 'dev_env') - settings_for_checks = [ - {"n": cluster.App.IP_RANGES, - "v": app.env_allowed_ip_ranges_names('dev_env'), - "e": True}, - {"n": cluster.App.AUTH0_CLIENT_ID, - "v": settings.SECRET_DISPLAY_VALUE, - "e": False}, - {"n": cluster.App.AUTH0_CLIENT_SECRET, - "v": settings.SECRET_DISPLAY_VALUE, - "e": False}, - {"n": cluster.App.AUTH0_CONNECTIONS, "v": "[]", "e": can_edit_connections}, - {"n": cluster.App.AUTH0_DOMAIN, "v": "http://testing", "e": False}, - {"n": cluster.App.AUTH0_PASSWORDLESS, "v": "False", "e": False}, - {"n": cluster.App.AUTHENTICATION_REQUIRED, "v": "True", "e": True}, - ] - for item in settings_for_checks: - auth_item_ui = locate_setting_ui(auth_settings, item['n']) - if not auth_item_ui: - continue - assert item['v'] in auth_item_ui.text - if item['e']: - assert 'Edit' in auth_item_ui.text - else: - assert 'Edit' not in auth_item_ui.text + client.force_login(users[user]) + response = detail(client, app) + assert response.status_code == 200 + auth_settings = get_auth_settings(response.content, 'dev_env') + settings_for_checks = [ + {"n": cluster.App.IP_RANGES, + "v": app.env_allowed_ip_ranges_names('dev_env'), + "e": True}, + {"n": cluster.App.AUTH0_CLIENT_ID, + "v": settings.SECRET_DISPLAY_VALUE, + "e": False}, + {"n": cluster.App.AUTH0_CLIENT_SECRET, + "v": settings.SECRET_DISPLAY_VALUE, + "e": False}, + {"n": cluster.App.AUTH0_CONNECTIONS, "v": "[]", "e": can_edit_connections}, + {"n": cluster.App.AUTH0_DOMAIN, "v": "http://testing", "e": False}, + {"n": cluster.App.AUTH0_PASSWORDLESS, "v": "False", "e": False}, + {"n": cluster.App.AUTHENTICATION_REQUIRED, "v": "True", "e": True}, + ] + for item in settings_for_checks: + auth_item_ui = locate_setting_ui(auth_settings, item['n']) + if not auth_item_ui: + continue + assert item['v'] in auth_item_ui.text + if item['e']: + assert 'Edit' in auth_item_ui.text + else: + assert 'Edit' not in auth_item_ui.text def test_register_app_with_creating_datasource(client, users):