Merge pull request #1245 from umap-project/dynamic-default-status
Allow to configure default share and edit status
This commit is contained in:
commit
48750b3fde
5 changed files with 73 additions and 2 deletions
|
@ -147,6 +147,27 @@ UMAP_EXTRA_URLS = {
|
||||||
|
|
||||||
How many datalayer versions to keep. 10 by default.
|
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
|
#### UMAP_DEMO_SITE
|
||||||
|
|
||||||
Set to True if you want to display a message saying that your instance is not
|
Set to True if you want to display a message saying that your instance is not
|
||||||
|
|
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -36,6 +36,14 @@ User.add_to_class("get_url", get_user_url)
|
||||||
User.add_to_class("get_stars_url", get_user_stars_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):
|
class NamedModel(models.Model):
|
||||||
name = models.CharField(max_length=200, verbose_name=_("name"))
|
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")
|
settings.AUTH_USER_MODEL, blank=True, verbose_name=_("editors")
|
||||||
)
|
)
|
||||||
edit_status = models.SmallIntegerField(
|
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(
|
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(
|
settings = models.JSONField(
|
||||||
blank=True, null=True, verbose_name=_("settings"), default=dict
|
blank=True, null=True, verbose_name=_("settings"), default=dict
|
||||||
|
|
|
@ -244,6 +244,8 @@ USER_MAPS_URL = 'user_maps'
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': env.db(default='postgis://localhost:5432/umap')
|
'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_READONLY = env('UMAP_READONLY', default=False)
|
||||||
UMAP_GZIP = True
|
UMAP_GZIP = True
|
||||||
|
|
|
@ -106,3 +106,19 @@ def test_publicmanager_should_get_only_public_maps(map, user, licence):
|
||||||
assert map in Map.public.all()
|
assert map in Map.public.all()
|
||||||
assert open_map not in Map.public.all()
|
assert open_map not in Map.public.all()
|
||||||
assert private_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
|
||||||
|
|
Loading…
Reference in a new issue