applications: add/display authors and license metadata (#84609)
gitea/hobo/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-12-12 09:51:25 +01:00
parent a35ab6d8fa
commit b27942fad9
6 changed files with 81 additions and 2 deletions

View File

@ -32,7 +32,7 @@ class InstallForm(forms.Form):
class MetadataForm(forms.ModelForm):
class Meta:
model = Application
fields = ['name', 'slug', 'description', 'documentation_url', 'icon', 'visible']
fields = ['name', 'slug', 'description', 'documentation_url', 'authors', 'license', 'icon', 'visible']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

View File

@ -0,0 +1,32 @@
# Generated by Django 3.2.16 on 2023-12-12 08:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('applications', '0014_check_install'),
]
operations = [
migrations.AddField(
model_name='application',
name='authors',
field=models.TextField(blank=True, verbose_name='Authors'),
),
migrations.AddField(
model_name='application',
name='license',
field=models.CharField(
blank=True,
choices=[
('', 'Unspecified'),
('agplv3+', 'GNU Affero General Public License v3 or later (AGPLv3+)'),
('gplv3+', 'GNU General Public License v3 or later (GPLv3+)'),
('mit', 'MIT License'),
],
max_length=200,
verbose_name='License',
),
),
]

View File

@ -99,6 +99,19 @@ class Application(models.Model):
)
description = models.TextField(verbose_name=_('Description'), blank=True)
documentation_url = models.URLField(_('Documentation URL'), blank=True)
authors = models.TextField(verbose_name=_('Authors'), blank=True)
license = models.CharField(
verbose_name=_('License'),
max_length=200,
choices=[
('', _('Unspecified')),
# from trove_classifiers License values
('agplv3+', _('GNU Affero General Public License v3 or later (AGPLv3+)')),
('gplv3+', _('GNU General Public License v3 or later (GPLv3+)')),
('mit', _('MIT License')),
],
blank=True,
)
editable = models.BooleanField(default=True)
visible = models.BooleanField(
verbose_name=_('Visible'),
@ -322,6 +335,8 @@ class Version(models.Model):
'slug': app.slug,
'description': app.description,
'documentation_url': app.documentation_url,
'license': app.license,
'authors': app.authors,
'icon': os.path.basename(app.icon.name) if app.icon.name else None,
'visible': app.visible,
'version_number': self.number,

View File

@ -18,7 +18,7 @@
<span class="actions">
<a class="extra-actions-menu-opener"></a>
{% if app.editable %}
<a rel="popup" href="{% url 'application-metadata' app_slug=app.slug %}">{% trans 'Metadata' %}</a>
<a href="{% url 'application-metadata' app_slug=app.slug %}">{% trans 'Metadata' %}</a>
{% else %}
<a rel="popup" href="{% url 'application-update' app_slug=app.slug %}">{% trans 'Update' %}</a>
{% endif %}
@ -67,6 +67,14 @@
{% block sidebar %}
<aside id="sidebar">
{% if not app.editable %}
<div class="meta">
{% if app.description %}<p class="description">{{ app.description }}</p>{% endif %}
{% if app.documentation_url %}<p class="documentation"><a href="{{ app.documentation_url }}">{% trans "Documentation" %}</a></p>{% endif %}
{% if app.authors %}<p class="authors">{% trans "Created by:" %} {{ app.authors|linebreaksbr }}</p>{% endif %}
{% if app.license %}<p class="license">{% trans "License:" %} {{ app.get_license_display }}</p>{% endif %}
</div>
{% endif %}
{% if app.editable %}
<h3>{% trans "Add" %}</h3>
{% for service, types in types_by_service.items %}

View File

@ -262,6 +262,10 @@ ul#id_scopes li {
width: 100%;
}
#id_authors {
height: 4em;
}
a.button.button-paragraph {
box-sizing: border-box;
display: block;

View File

@ -1890,3 +1890,23 @@ def test_deploy_application_parameters(app, admin_user, settings, app_bundle_par
parameter = Parameter.objects.all().first()
resp = app.get(f'/applications/manifest/test/edit-parameter/{parameter.id}/', status=404)
resp = app.get(f'/applications/manifest/test/delete-parameter/{parameter.id}/', status=404)
def test_non_editable_application_metadata(app, admin_user):
Application.objects.create(
name='Test',
slug='test',
editable=False,
documentation_url='https://example.net',
license='agplv3+',
authors='author1',
)
login(app)
resp = app.get('/applications/manifest/test/')
assert resp.pyquery('.meta .documentation a').attr.href == 'https://example.net'
assert resp.pyquery('.meta .authors').text() == 'Created by: author1'
assert (
resp.pyquery('.meta .license').text()
== 'License: GNU Affero General Public License v3 or later (AGPLv3+)'
)