feat: add a setting to prevent users from editing their profile

In some situations, the profile comes from the OAuth provider and shouldn’t be modified by users.
This commit is contained in:
David Larlet 2024-09-12 14:23:50 -04:00
parent 289bef7ba8
commit d159fdc2cb
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
5 changed files with 17 additions and 3 deletions

View file

@ -144,6 +144,12 @@ Should uMap allows user without an account to create maps (default is False).
Can be set through env var: `UMAP_ALLOW_ANONYMOUS=1` Can be set through env var: `UMAP_ALLOW_ANONYMOUS=1`
#### UMAP_ALLOW_EDIT_PROFILE
Should uMap allows users to edit their profile (default is True).
Can be unset through env var: `UMAP_ALLOW_EDIT_PROFILE=0`
#### UMAP_CUSTOM_TEMPLATES #### UMAP_CUSTOM_TEMPLATES
To be used when you want to override some HTML templates: To be used when you want to override some HTML templates:

View file

@ -12,6 +12,7 @@ def settings(request):
"UMAP_READONLY": djsettings.UMAP_READONLY, "UMAP_READONLY": djsettings.UMAP_READONLY,
"UMAP_DEMO_SITE": djsettings.UMAP_DEMO_SITE, "UMAP_DEMO_SITE": djsettings.UMAP_DEMO_SITE,
"UMAP_HOST_INFOS": djsettings.UMAP_HOST_INFOS, "UMAP_HOST_INFOS": djsettings.UMAP_HOST_INFOS,
"UMAP_ALLOW_EDIT_PROFILE": djsettings.UMAP_ALLOW_EDIT_PROFILE,
} }

View file

@ -240,6 +240,7 @@ USER_URL_FIELD = "username"
# Miscellaneous project settings # Miscellaneous project settings
# ============================================================================= # =============================================================================
UMAP_ALLOW_ANONYMOUS = env.bool("UMAP_ALLOW_ANONYMOUS", default=False) UMAP_ALLOW_ANONYMOUS = env.bool("UMAP_ALLOW_ANONYMOUS", default=False)
UMAP_ALLOW_EDIT_PROFILE = env.bool("UMAP_ALLOW_EDIT_PROFILE", default=True)
UMAP_EXTRA_URLS = { UMAP_EXTRA_URLS = {
"routing": "http://www.openstreetmap.org/directions?engine=osrm_car&route={lat},{lng}&locale={locale}#map={zoom}/{lat}/{lng}", # noqa "routing": "http://www.openstreetmap.org/directions?engine=osrm_car&route={lat},{lng}&locale={locale}#map={zoom}/{lat}/{lng}", # noqa

View file

@ -7,8 +7,10 @@
{% else %} {% else %}
<a href="{% url 'user_dashboard' %}">{% trans "My Maps" %}</a> <a href="{% url 'user_dashboard' %}">{% trans "My Maps" %}</a>
{% endif %} {% endif %}
<a {% if selected == "profile" %}class="selected"{% endif %} {% if UMAP_ALLOW_EDIT_PROFILE %}
href="{% url 'user_profile' %}">{% trans "My profile" %}</a> <a {% if selected == "profile" %}class="selected"{% endif %}
href="{% url 'user_profile' %}">{% trans "My profile" %}</a>
{% endif %}
<a {% if selected == "teams" %}class="selected"{% endif %} <a {% if selected == "teams" %}class="selected"{% endif %}
href="{% url 'user_teams' %}">{% trans "My teams" %}</a> href="{% url 'user_teams' %}">{% trans "My teams" %}</a>
</h2> </h2>

View file

@ -115,11 +115,15 @@ i18n_urls += decorated_patterns(
name="map_star", name="map_star",
), ),
path("me", views.user_dashboard, name="user_dashboard"), path("me", views.user_dashboard, name="user_dashboard"),
path("me/profile", views.user_profile, name="user_profile"),
path("me/download", views.user_download, name="user_download"), path("me/download", views.user_download, name="user_download"),
path("me/teams", views.UserTeams.as_view(), name="user_teams"), path("me/teams", views.UserTeams.as_view(), name="user_teams"),
path("team/create/", views.TeamNew.as_view(), name="team_new"), path("team/create/", views.TeamNew.as_view(), name="team_new"),
) )
if settings.UMAP_ALLOW_EDIT_PROFILE:
i18n_urls.append(
path("me/profile", login_required(views.user_profile), name="user_profile")
)
i18n_urls += decorated_patterns( i18n_urls += decorated_patterns(
[login_required, team_members_only], [login_required, team_members_only],
path("team/<int:pk>/edit/", views.TeamUpdate.as_view(), name="team_update"), path("team/<int:pk>/edit/", views.TeamUpdate.as_view(), name="team_update"),