diff --git a/docs/settings.md b/docs/settings.md index af4179d5..ba08de12 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -147,6 +147,27 @@ UMAP_EXTRA_URLS = { How many datalayer versions to keep. 10 by default. + +#### UMAP_DEFAULT_EDIT_STATUS + +Define the map default edit status. +Possible values: + +- 1 (Everyone) +- 2 (Editors only) +- 3 (Owner only) + + +#### UMAP_DEFAULT_SHARE_STATUS + +Define the map default share status. +Possible values: + +- 1 (Everyone (public)) +- 2 (Anyone with link) +- 3 (Editors only) + + #### UMAP_DEMO_SITE Set to True if you want to display a message saying that your instance is not diff --git a/umap/migrations/0011_alter_map_edit_status_alter_map_share_status.py b/umap/migrations/0011_alter_map_edit_status_alter_map_share_status.py new file mode 100644 index 00000000..ab054e4d --- /dev/null +++ b/umap/migrations/0011_alter_map_edit_status_alter_map_share_status.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.2 on 2023-08-07 06:07 + +from django.db import migrations, models +import umap.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('umap', '0010_alter_map_edit_status_alter_map_share_status'), + ] + + operations = [ + migrations.AlterField( + model_name='map', + name='edit_status', + field=models.SmallIntegerField(choices=[(1, 'Everyone'), (2, 'Editors only'), (3, 'Owner only')], default=umap.models.get_default_edit_status, verbose_name='edit status'), + ), + migrations.AlterField( + model_name='map', + name='share_status', + field=models.SmallIntegerField(choices=[(1, 'Everyone (public)'), (2, 'Anyone with link'), (3, 'Editors only'), (9, 'Blocked')], default=umap.models.get_default_share_status, verbose_name='share status'), + ), + ] diff --git a/umap/models.py b/umap/models.py index 1364975d..9ef8ca10 100644 --- a/umap/models.py +++ b/umap/models.py @@ -36,6 +36,14 @@ User.add_to_class("get_url", get_user_url) User.add_to_class("get_stars_url", get_user_stars_url) +def get_default_share_status(): + return settings.UMAP_DEFAULT_SHARE_STATUS or Map.PUBLIC + + +def get_default_edit_status(): + return settings.UMAP_DEFAULT_EDIT_STATUS or Map.OWNER + + class NamedModel(models.Model): name = models.CharField(max_length=200, verbose_name=_("name")) @@ -168,10 +176,10 @@ class Map(NamedModel): settings.AUTH_USER_MODEL, blank=True, verbose_name=_("editors") ) edit_status = models.SmallIntegerField( - choices=EDIT_STATUS, default=OWNER, verbose_name=_("edit status") + choices=EDIT_STATUS, default=get_default_edit_status, verbose_name=_("edit status") ) share_status = models.SmallIntegerField( - choices=SHARE_STATUS, default=PUBLIC, verbose_name=_("share status") + choices=SHARE_STATUS, default=get_default_share_status, verbose_name=_("share status") ) settings = models.JSONField( blank=True, null=True, verbose_name=_("settings"), default=dict diff --git a/umap/settings/base.py b/umap/settings/base.py index a8f719c3..cb1c2fcf 100644 --- a/umap/settings/base.py +++ b/umap/settings/base.py @@ -244,6 +244,8 @@ USER_MAPS_URL = 'user_maps' DATABASES = { 'default': env.db(default='postgis://localhost:5432/umap') } +UMAP_DEFAULT_SHARE_STATUS = None +UMAP_DEFAULT_EDIT_STATUS = None UMAP_READONLY = env('UMAP_READONLY', default=False) UMAP_GZIP = True diff --git a/umap/tests/test_map.py b/umap/tests/test_map.py index f54a8afa..ae193700 100644 --- a/umap/tests/test_map.py +++ b/umap/tests/test_map.py @@ -106,3 +106,19 @@ def test_publicmanager_should_get_only_public_maps(map, user, licence): assert map in Map.public.all() assert open_map not in Map.public.all() assert private_map not in Map.public.all() + + +def test_can_change_default_edit_status(user, settings): + map = MapFactory(owner=user) + assert map.edit_status == Map.OWNER + settings.UMAP_DEFAULT_EDIT_STATUS = Map.EDITORS + map = MapFactory(owner=user) + assert map.edit_status == Map.EDITORS + + +def test_can_change_default_share_status(user, settings): + map = MapFactory(owner=user) + assert map.share_status == Map.PUBLIC + settings.UMAP_DEFAULT_SHARE_STATUS = Map.PRIVATE + map = MapFactory(owner=user) + assert map.share_status == Map.PRIVATE