Skip to content

Commit

Permalink
Split Releases page into active and archived
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Verga <mattia.verga@tiscali.it>
  • Loading branch information
mattiaverga committed Apr 29, 2023
1 parent dfaa5c1 commit c8a46fd
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 13 deletions.
6 changes: 6 additions & 0 deletions bodhi-server/bodhi/server/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ class ListReleaseSchema(PaginatedSchema):
missing=None,
)

active = colander.SchemaNode(
colander.Boolean(true_choices=('true', '1')),
location="querystring",
missing=True,
)


class SaveReleaseSchema(CSRFProtectedSchema, colander.MappingSchema):
"""An API schema for bodhi.server.services.releases.save_release()."""
Expand Down
25 changes: 17 additions & 8 deletions bodhi-server/bodhi/server/services/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _get_status_counts(basequery, status):
'{}_updates_total'.format(status.description): basequery.count(),
}

def get_update_counts(releaseid):
def get_update_counts(releaseid, stable_only: bool = False):
"""
Return counts for the various states and types of updates in the given release.
Expand All @@ -257,19 +257,28 @@ def get_update_counts(releaseid):
release = Release.get(releaseid)
basequery = Update.query.filter(Update.release == release)
counts = {}
counts.update(_get_status_counts(basequery, UpdateStatus.pending))
counts.update(_get_status_counts(basequery, UpdateStatus.testing))
if not stable_only:
counts.update(_get_status_counts(basequery, UpdateStatus.pending))
counts.update(_get_status_counts(basequery, UpdateStatus.testing))
counts.update(_get_status_counts(basequery, UpdateStatus.stable))

return counts

data = request.validated

release_updates_counts = {}
releases = Release.all_releases()
for release in (releases['current'] + releases['pending'] + releases['archived']
+ releases['frozen']):
release_updates_counts[release["name"]] = get_update_counts(release["name"])

return {"release_updates_counts": release_updates_counts}
active = data.get('active')
if active is False:
for release in (releases['archived'] + releases['disabled']):
release_updates_counts[release["name"]] = get_update_counts(release["name"],
stable_only=True)
else:
for release in (releases['current'] + releases['pending'] + releases['frozen']):
release_updates_counts[release["name"]] = get_update_counts(release["name"])

return {"release_updates_counts": release_updates_counts,
"active": active}


@releases.get(accept=('application/json', 'text/json'),
Expand Down
20 changes: 16 additions & 4 deletions bodhi-server/bodhi/server/templates/releases.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,27 @@
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h3 class="fw-bold m-0">Releases</h3>
% if active:
<h3 class="fw-bold m-0 mb-2">Active Releases</h3>
<span>See here for <a href="${request.route_url('releases')}?active=false">Archived and disabled Releases</a></span>
% else:
<h3 class="fw-bold m-0 mb-2">Archived and disabled Releases</h3>
<span>See here for <a href="${request.route_url('releases')}">Active Releases</a></span>
% endif
</div>
</div>
</div>
</div>
<div class="container pt-2">
${release_list('current', stable_only=False)}
${release_list('pending', stable_only=False)}
${release_list('archived', stable_only=True)}
% if active:
${release_list('current', stable_only=False)}
${release_list('pending', stable_only=False)}
% else:
${release_list('archived', stable_only=True)}
% if request.releases['disabled']:
${release_list('disabled', stable_only=True)}
% endif
% endif
</div>

<%block name="javascript">
Expand Down
34 changes: 34 additions & 0 deletions bodhi-server/tests/services/test_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,19 @@ def _add_updates(updateslist, user, release, packagesuffix):
branch='f37', state=ReleaseState.frozen)
self.db.add(release)

release = Release(
name='F25', long_name='Fedora 25',
id_prefix='FEDORA', version='25',
dist_tag='f25', stable_tag='f25-updates',
testing_tag='f25-updates-testing',
candidate_tag='f25-updates-candidate',
pending_signing_tag='f25-updates-testing-signing',
pending_testing_tag='f25-updates-testing-pending',
pending_stable_tag='f25-updates-pending',
override_tag='f25-override',
branch='f25', state=ReleaseState.archived)
self.db.add(release)

currentrelease = self.db.query(Release).filter_by(name='F17').one()
addedupdates = [[UpdateStatus.pending,
[[UpdateType.security, 5],
Expand Down Expand Up @@ -646,6 +659,15 @@ def _add_updates(updateslist, user, release, packagesuffix):
with fml_testing.mock_sends():
_add_updates(addedupdates3, user2, frozenrelease, "fc37")

archivedrelease = self.db.query(Release).filter_by(name='F25').one()
addedupdates4 = [[UpdateStatus.stable,
[[UpdateType.security, 19],
[UpdateType.bugfix, 18],
[UpdateType.enhancement, 17],
[UpdateType.newpackage, 16]]]]
with fml_testing.mock_sends():
_add_updates(addedupdates4, user2, archivedrelease, "fc25")

self.db.flush()
# Clear the caches
Release.get_tags.cache_clear()
Expand Down Expand Up @@ -679,3 +701,15 @@ def test_release_counts(self):

# Assert that stable updates counts in a frozen release are displayed properly
assert '?releases=F37&amp;status=stable">97' in res

# Assert that archived release is not showed
assert '?releases=F25&amp;status=stable' not in res

def test_archived_release_page(self):
"""Test the release page update counts"""
res = self.app.get('/releases/?active=false', headers={'Accept': 'text/html'}, status=200)
# Assert that archived release is showed
assert '?releases=F25&amp;status=stable">70' in res

# Assert that current release is not showed
assert '?releases=F17&amp;status=stable' not in res
4 changes: 3 additions & 1 deletion devel/ci/integration/tests/test_bodhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ def test_get_notfound_view(bodhi_container):
def test_get_releases_view(bodhi_container, db_container):
"""Test ``/releases`` path"""
# Fetch releases from DB
query = """SELECT long_name FROM releases"""
query = (
"SELECT long_name FROM releases "
"WHERE state NOT IN ('disabled', 'archived')")
db_ip = db_container.get_IPv4s()[0]
conn = psycopg2.connect("dbname=bodhi2 user=postgres host={}".format(db_ip))
with conn:
Expand Down
1 change: 1 addition & 0 deletions news/PR5264.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Releases list webpage now hide inactive (disabled or archived) releases by default

0 comments on commit c8a46fd

Please sign in to comment.