From 240639e2b779d9acb538f6e544229f75af69feec Mon Sep 17 00:00:00 2001 From: Anish Date: Tue, 7 Nov 2023 02:31:30 +0530 Subject: [PATCH 1/3] add metadata about internal db connection in common_data dict --- mathesar/views.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mathesar/views.py b/mathesar/views.py index c6c8f6a20a..c7fd6953d2 100644 --- a/mathesar/views.py +++ b/mathesar/views.py @@ -1,3 +1,4 @@ +from config.settings.common_settings import DATABASES from django.conf import settings from django.contrib.auth.decorators import login_required from django.shortcuts import render, redirect, get_object_or_404 @@ -153,9 +154,23 @@ def get_base_data_all_routes(request, database=None, schema=None): 'is_authenticated': not request.user.is_anonymous, 'live_demo_mode': get_is_live_demo_mode(), 'current_release_tag_name': __version__, + 'internal_database': get_internal_db_meta(), } +def get_internal_db_meta(): + internal_db = DATABASES['default'] + if internal_db['ENGINE'].startswith('django.db.backends.postgresql'): + return { + 'type': 'postgres', + 'user': internal_db['USER'], + 'host': internal_db['HOST'], + 'port': internal_db['PORT'], + 'database': internal_db['NAME'] + } + return {'type': 'sqlite'} + + def get_common_data(request, database=None, schema=None): return { **get_base_data_all_routes(request, database, schema), From 251d38e01ec1e57f69cb64ee6dfa630cce47ff1c Mon Sep 17 00:00:00 2001 From: Anish Date: Tue, 7 Nov 2023 02:50:48 +0530 Subject: [PATCH 2/3] flake8 fix --- mathesar/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathesar/views.py b/mathesar/views.py index c7fd6953d2..5c7591ce75 100644 --- a/mathesar/views.py +++ b/mathesar/views.py @@ -154,7 +154,7 @@ def get_base_data_all_routes(request, database=None, schema=None): 'is_authenticated': not request.user.is_anonymous, 'live_demo_mode': get_is_live_demo_mode(), 'current_release_tag_name': __version__, - 'internal_database': get_internal_db_meta(), + 'internal_database': get_internal_db_meta(), } From d91aaeef42890fc65f5b23879cf1b8eda853c864 Mon Sep 17 00:00:00 2001 From: Anish Date: Tue, 7 Nov 2023 23:10:41 +0530 Subject: [PATCH 3/3] rm editable from database model --- mathesar/api/db/viewsets/databases.py | 11 ++++------- mathesar/api/exceptions/error_codes.py | 1 - .../validation_exceptions/exceptions.py | 11 ----------- mathesar/api/serializers/databases.py | 4 ++-- mathesar/install.py | 4 +--- mathesar/migrations/0010_remove_editable.py | 17 +++++++++++++++++ mathesar/models/base.py | 1 - mathesar/views.py | 1 - 8 files changed, 24 insertions(+), 26 deletions(-) create mode 100644 mathesar/migrations/0010_remove_editable.py diff --git a/mathesar/api/db/viewsets/databases.py b/mathesar/api/db/viewsets/databases.py index 546d4cca70..a122b6d77d 100644 --- a/mathesar/api/db/viewsets/databases.py +++ b/mathesar/api/db/viewsets/databases.py @@ -16,7 +16,6 @@ from db.types.base import get_available_known_db_types from db.types.install import uninstall_mathesar_from_database from mathesar.api.serializers.db_types import DBTypeSerializer -from mathesar.api.exceptions.validation_exceptions.exceptions import EditingDBCredentialsNotAllowed class DatabaseViewSet(AccessViewSetMixin, viewsets.ModelViewSet): @@ -48,12 +47,10 @@ def create(self, request): def partial_update(self, request, pk=None): db_object = self.get_object() - if db_object.editable: - serializer = DatabaseSerializer(db_object, data=request.data, partial=True) - serializer.is_valid(raise_exception=True) - serializer.save() - return Response(serializer.data) - raise EditingDBCredentialsNotAllowed() + serializer = DatabaseSerializer(db_object, data=request.data, partial=True) + serializer.is_valid(raise_exception=True) + serializer.save() + return Response(serializer.data) def destroy(self, request, pk=None): db_object = self.get_object() diff --git a/mathesar/api/exceptions/error_codes.py b/mathesar/api/exceptions/error_codes.py index 7fbce4ad86..7eccbf23c9 100644 --- a/mathesar/api/exceptions/error_codes.py +++ b/mathesar/api/exceptions/error_codes.py @@ -42,7 +42,6 @@ class ErrorCodes(Enum): BadDBCredentials = 4428 ColumnSizeMismatch = 4401 DistinctColumnNameRequired = 4402 - EditingNotAllowed = 4429 MappingsNotFound = 4417 MultipleDataFiles = 4400 MoneyDisplayOptionConflict = 4407 diff --git a/mathesar/api/exceptions/validation_exceptions/exceptions.py b/mathesar/api/exceptions/validation_exceptions/exceptions.py index 51f0b2232b..c4a6f19a1b 100644 --- a/mathesar/api/exceptions/validation_exceptions/exceptions.py +++ b/mathesar/api/exceptions/validation_exceptions/exceptions.py @@ -181,14 +181,3 @@ def __init__( field=None, ): super().__init__(None, self.error_code, message, field) - - -class EditingDBCredentialsNotAllowed(MathesarValidationException): - error_code = ErrorCodes.EditingNotAllowed.value - - def __init__( - self, - message="Cannot edit the DB credentials created from .env", - field=None - ): - super().__init__(None, self.error_code, message, field) diff --git a/mathesar/api/serializers/databases.py b/mathesar/api/serializers/databases.py index 0b6962bac6..aeab5f7514 100644 --- a/mathesar/api/serializers/databases.py +++ b/mathesar/api/serializers/databases.py @@ -13,8 +13,8 @@ class DatabaseSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer) class Meta: model = Database - fields = ['id', 'name', 'db_name', 'deleted', 'editable', 'supported_types_url', 'username', 'password', 'host', 'port'] - read_only_fields = ['id', 'deleted', 'supported_types_url', 'editable'] + fields = ['id', 'name', 'db_name', 'deleted', 'supported_types_url', 'username', 'password', 'host', 'port'] + read_only_fields = ['id', 'deleted', 'supported_types_url'] extra_kwargs = { 'password': {'write_only': True} } diff --git a/mathesar/install.py b/mathesar/install.py index f0a59a28bb..b83ec0be37 100644 --- a/mathesar/install.py +++ b/mathesar/install.py @@ -42,8 +42,7 @@ def main(skip_static_collection=False): username=credentials["USER"], password=credentials["PASSWORD"], host=credentials["HOST"], - port=credentials["PORT"], - editable=False + port=credentials["PORT"] ).save() except IntegrityError as e: if e.args[0].startswith( @@ -58,7 +57,6 @@ def main(skip_static_collection=False): db_model.password = credentials["PASSWORD"] db_model.host = credentials["HOST"] db_model.port = credentials["PORT"] - db_model.editable = False db_model.save() else: raise e diff --git a/mathesar/migrations/0010_remove_editable.py b/mathesar/migrations/0010_remove_editable.py new file mode 100644 index 0000000000..75b33d3411 --- /dev/null +++ b/mathesar/migrations/0010_remove_editable.py @@ -0,0 +1,17 @@ +# Generated by Django 3.1.14 on 2023-11-07 17:14 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('mathesar', '0009_merge_20231025_1733'), + ] + + operations = [ + migrations.RemoveField( + model_name='database', + name='editable', + ), + ] diff --git a/mathesar/models/base.py b/mathesar/models/base.py index c0dc50caa6..212466a679 100644 --- a/mathesar/models/base.py +++ b/mathesar/models/base.py @@ -116,7 +116,6 @@ class Database(ReflectionManagerMixin, BaseModel): password = EncryptedCharField(max_length=255) host = models.CharField(max_length=255) port = models.IntegerField() - editable = models.BooleanField(default=True) current_objects = models.Manager() # TODO does this need to be defined, given that ReflectionManagerMixin defines an identical attribute? objects = DatabaseObjectManager() diff --git a/mathesar/views.py b/mathesar/views.py index 5c7591ce75..c677fdfe1f 100644 --- a/mathesar/views.py +++ b/mathesar/views.py @@ -88,7 +88,6 @@ def get_database_list(request): 'host': db.host, 'name': db.name, 'db_name': db.db_name, - 'editable': db.editable, 'error': 'Error connecting to the database' }) return database_serializer.data + failed_db_data