Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use beta admin as default #621

Merged
merged 9 commits into from
Feb 5, 2025
Merged
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Current (in progress)

- Nothing yet
- Use beta admin as default [#621](https://github.com/datagouv/udata-front/pull/621)

## 6.1.1 (2025-01-31)

Expand Down
17 changes: 17 additions & 0 deletions udata_front/frontend/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ def in_url(*args, **kwargs):
)


@front.app_template_global()
def beta_admin_url_for(path, fallback_path, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're missing some routes. They have been documented in datagouv/data.gouv.fr#1648 and can be added in future iterations.

Membership Request notification @

url_for('admin.index', path='organization/{id}/'.format(id=org.id), _anchor='membership-requests', _external=True)
are actually not used. I think udata's templates are used and I guess we can't rely on beta_admin_url_for there. Let's ignore it for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I think we'll have to work on the mailing system at some point because it was not thought with this usecase in mind.

'''
A helper to route to the new admin if available.
If NEW_ADMIN_URL is defined, we build the target url pointing to it using `path`.
Else we route to the old admin using `fallback_path`.
Kwargs are forwarded as as params in the first case
and as arguments of url_for in the seconde case.
'''
if current_app.config['NEW_ADMIN_URL']:
scheme, netloc, path, query, fragments = urlsplit(
current_app.config['NEW_ADMIN_URL'] + path
)
return urlunsplit((scheme, netloc, path, url_encode(kwargs), fragments))
return url_for('admin.index', path=fallback_path, **kwargs)


@front.app_template_filter()
@pass_context
def placeholder(ctx, url, name='default', external=False):
Expand Down
8 changes: 4 additions & 4 deletions udata_front/theme/gouvfr/templates/dataset/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<div class="fr-col-auto fr-ml-3v">
<a
class="fr-btn fr-btn--sm fr-btn--secondary fr-btn--secondary-warning-425 fr-icon-pencil-line fr-btn--icon-left"
href="{{ url_for('admin.index', path='dataset/{id}/'.format(id=dataset.id)) }}"
href="{{ beta_admin_url_for(path='datasets/{id}/'.format(id=dataset.id), fallback_path='dataset/{id}/'.format(id=dataset.id)) }}"
>
{{ _('Edit') }}
</a>
Expand Down Expand Up @@ -359,7 +359,7 @@ <h2 class="fr-mt-4w fr-mb-1w subtitle subtitle--uppercase">
<p>
<a
class="fr-btn"
href="{{ url_for('admin.index', path='dataset/{id}/'.format(id=dataset.id)) }}"
href="{{ beta_admin_url_for(path='datasets/{id}/'.format(id=dataset.id), fallback_path='dataset/{id}/'.format(id=dataset.id)) }}"
>
{{ _('Add a file') }}
</a>
Expand Down Expand Up @@ -399,7 +399,7 @@ <h2 class="subtitle subtitle--uppercase fr-col">{{ ngettext('%(num)d Reuse', '%(
{% if not read_only_mode %}
<div class="fr-col-12 fr-col-sm-6 fr-col-md-5 fr-col-lg-4 text-align-right">
<a class="fr-btn fr-btn--sm fr-btn--secondary fr-btn--secondary-grey-500 fr-icon-add-line fr-btn--icon-left"
href="{{ url_for('admin.index', path='reuse/new/', **{'dataset_id': dataset.id}) }}">
href="{{ beta_admin_url_for(path='reuses/new/', fallback_path='reuse/new/', **{'dataset_id': dataset.id}) }}">
{{ _('Add a reuse') }}
</a>
</div>
Expand All @@ -422,7 +422,7 @@ <h2 class="subtitle subtitle--uppercase fr-col">{{ ngettext('%(num)d Reuse', '%(
<p>
<a
class="fr-btn"
href="{{ url_for('admin.index', path='reuse/new/', **{'dataset_id': dataset.id}) }}"
href="{{ beta_admin_url_for(path='reuses/new/', fallback_path='reuse/new/', **{'dataset_id': dataset.id}) }}"
>
{{ _('Publish a reuse') }}
</a>
Expand Down
19 changes: 10 additions & 9 deletions udata_front/theme/gouvfr/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
{% set banner_activated = config['BANNER_ACTIVATED'] %}
{% set read_only_mode = config['READ_ONLY_MODE'] %}
{% set next_url = url_for(request.endpoint, **request.view_args) if not request.routing_exception else url_for('site.home') %}
{% set publish_items = [
{'icon': 'fr-icon-database-line', 'label': _('A dataset'), 'url': url_for('beta.datasets-new')},
{'icon': 'fr-icon-code-s-slash-line', 'label': _('An API'), 'url': url_for('beta.dataservices-new')},
{'icon': 'fr-icon-line-chart-line', 'label': _('A reuse'), 'url': url_for('beta.reuses-new')},
{'icon': 'fr-icon-server-line', 'label': _('A harvester'), 'url': url_for('admin.index', path='harvester/new/')},
{'icon': 'fr-icon-government-line', 'label': _('An organization'), 'url': url_for('beta.organizations-new')},
] + ([{'icon': 'fr-icon-article-line', 'label': _('A post'), 'url': url_for('admin.index', path='post/new/')}] if current_user.sysadmin else [])
%}

{% set dataset_item = [{'icon': 'fr-icon-database-line', 'label': _('A dataset'), 'url': beta_admin_url_for(path='datasets/new', fallback_path='dataset/new/')}] %}
{% set dataservice_item = [{'icon': 'fr-icon-database-line', 'label': _('An API'), 'url': beta_admin_url_for(path='dataservices/new', fallback_path='')}] if config.NEW_ADMIN_URL else [] %}
{% set reuse_item = [{'icon': 'fr-icon-database-line', 'label': _('A reuse'), 'url': beta_admin_url_for(path='reuses/new', fallback_path='reuse/new/')}] %}
{% set harvester_item = [{'icon': 'fr-icon-database-line', 'label': _('A harvester'), 'url': beta_admin_url_for(path='harvesters/new', fallback_path='harvester/new/')}] %}
{% set organization_item = [{'icon': 'fr-icon-database-line', 'label': _('A organization'), 'url': beta_admin_url_for(path='organizations/new', fallback_path='organization/new/')}] %}
{% set post_item = [{'icon': 'fr-icon-database-line', 'label': _('A post'), 'url': beta_admin_url_for(path='posts/new', fallback_path='post/new/')}] if current_user.sysadmin else [] %}

{% set publish_items = dataset_item + dataservice_item + reuse_item + harvester_item + organization_item + post_item %}

<header role="banner" class="fr-header">
{% if read_only_mode %}
Expand Down Expand Up @@ -90,7 +91,7 @@
</li>
<li>
<a
href="{{ url_for('admin.index') }}"
href="{{ url_for('beta.beta-admin') }}"
class="fr-btn fr-icon-svg fr-icon--sm"
>
<span class="fr-mr-1w fr-grid-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
{% if can_edit %}
<a
class="fr-ml-2w fr-btn fr-btn--sm fr-btn--secondary fr-btn--secondary-grey-500 fr-icon-pencil-line fr-btn--icon-left"
href="{{ url_for('admin.index', path='organization/{id}/'.format(id=org.id)) }}"
href="{{ beta_admin_url_for(path='organizations/{id}/profile/'.format(id=org.id), fallback_path='organization/{id}/'.format(id=org.id)) }}"
>
{{ _('Modify organization') }}
</a>
Expand Down
2 changes: 1 addition & 1 deletion udata_front/theme/gouvfr/templates/reuse/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<div class="fr-col-auto fr-ml-3v">
<a
class="fr-btn fr-btn--sm fr-btn--secondary fr-btn--secondary-warning-425 fr-icon-pencil-line fr-btn--icon-left"
href="{{ url_for('admin.index', path='reuse/{id}/'.format(id=reuse.id)) }}"
href="{{ beta_admin_url_for(path='reuses/{id}/'.format(id=reuse.id), fallback_path='reuse/{id}/'.format(id=reuse.id)) }}"
>
{{ _('Edit') }}
</a>
Expand Down
2 changes: 1 addition & 1 deletion udata_front/theme/gouvfr/templates/user/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{% else %}
<a
class="fr-ml-2w fr-btn fr-btn--sm fr-btn--secondary fr-btn--secondary-warning-425 fr-icon-pencil-line fr-btn--icon-left"
href="{{ url_for('admin.index', path='me') }}"
href="{{ beta_admin_url_for(path='me/profile', fallback_path='me') }}"
>
{{ _('Edit') }}
</a>
Expand Down