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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Current (in progress)

- Use beta admin as default [#621](https://github.com/datagouv/udata-front/pull/621)
- Fix following cache issue [#631](https://github.com/datagouv/udata-front/pull/631)
- Add dataservice search to header [#622](https://github.com/datagouv/udata-front/pull/622)

Expand Down
14 changes: 14 additions & 0 deletions udata_front/frontend/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ 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
6 changes: 3 additions & 3 deletions udata_front/theme/gouvfr/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
{'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-server-line', 'label': _('A harvester'), 'url': beta_admin_url_for(path='harvesters/new', fallback_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 [])
] + ([{'icon': 'fr-icon-article-line', 'label': _('A post'), 'url': beta_admin_url_for(path='posts/new/', fallback_path='post/new/')}] if current_user.sysadmin else [])
%}

<header role="banner" class="fr-header">
Expand Down Expand Up @@ -90,7 +90,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/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