Only show open announcements

This commit is contained in:
Peter Pfeufer 2021-01-25 21:13:43 +01:00
parent 74eb8621d9
commit 40824156bf
No known key found for this signature in database
GPG Key ID: 6051D2C6AD4EBC27

View File

@ -27,7 +27,7 @@ GITLAB_AUTH_REPOSITORY_TAGS_URL = (
) )
GITLAB_AUTH_ANNOUNCEMENT_ISSUES_URL = ( GITLAB_AUTH_ANNOUNCEMENT_ISSUES_URL = (
'https://gitlab.com/api/v4/projects/allianceauth%2Fallianceauth/issues' 'https://gitlab.com/api/v4/projects/allianceauth%2Fallianceauth/issues'
'?labels=announcement' '?labels=announcement&state=opened'
) )
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -36,7 +36,7 @@ logger = logging.getLogger(__name__)
@register.inclusion_tag('allianceauth/admin-status/overview.html') @register.inclusion_tag('allianceauth/admin-status/overview.html')
def status_overview() -> dict: def status_overview() -> dict:
response = { response = {
'notifications': list(), 'notifications': list(),
'current_version': __version__, 'current_version': __version__,
'task_queue_length': -1, 'task_queue_length': -1,
} }
@ -51,7 +51,7 @@ def _fetch_celery_queue_length() -> int:
app = app_or_default(None) app = app_or_default(None)
with app.connection_or_acquire() as conn: with app.connection_or_acquire() as conn:
return conn.default_channel.queue_declare( return conn.default_channel.queue_declare(
queue=getattr(settings, 'CELERY_DEFAULT_QUEUE', 'celery'), queue=getattr(settings, 'CELERY_DEFAULT_QUEUE', 'celery'),
passive=True passive=True
).message_count ).message_count
except amqp.exceptions.ChannelError: except amqp.exceptions.ChannelError:
@ -63,13 +63,13 @@ def _fetch_celery_queue_length() -> int:
def _current_notifications() -> dict: def _current_notifications() -> dict:
"""returns the newest 5 announcement issues""" """returns the newest 5 announcement issues"""
try: try:
notifications = cache.get_or_set( notifications = cache.get_or_set(
'gitlab_notification_issues', 'gitlab_notification_issues',
_fetch_notification_issues_from_gitlab, _fetch_notification_issues_from_gitlab,
NOTIFICATION_CACHE_TIME NOTIFICATION_CACHE_TIME
) )
except requests.RequestException: except requests.RequestException:
logger.exception('Error while getting gitlab notifications') logger.exception('Error while getting gitlab notifications')
top_notifications = [] top_notifications = []
@ -78,19 +78,19 @@ def _current_notifications() -> dict:
top_notifications = notifications[:5] top_notifications = notifications[:5]
else: else:
top_notifications = [] top_notifications = []
response = { response = {
'notifications': top_notifications, 'notifications': top_notifications,
} }
return response return response
def _fetch_notification_issues_from_gitlab() -> list: def _fetch_notification_issues_from_gitlab() -> list:
return _fetch_list_from_gitlab(GITLAB_AUTH_ANNOUNCEMENT_ISSUES_URL, max_pages=10) return _fetch_list_from_gitlab(GITLAB_AUTH_ANNOUNCEMENT_ISSUES_URL, max_pages=10)
def _current_version_summary() -> dict: def _current_version_summary() -> dict:
"""returns the current version info""" """returns the current version info"""
try: try:
tags = cache.get_or_set( tags = cache.get_or_set(
'git_release_tags', _fetch_tags_from_gitlab, TAG_CACHE_TIME 'git_release_tags', _fetch_tags_from_gitlab, TAG_CACHE_TIME
@ -98,16 +98,16 @@ def _current_version_summary() -> dict:
except requests.RequestException: except requests.RequestException:
logger.exception('Error while getting gitlab release tags') logger.exception('Error while getting gitlab release tags')
return {} return {}
if not tags: if not tags:
return {} return {}
( (
latest_major_version, latest_major_version,
latest_minor_version, latest_minor_version,
latest_patch_version, latest_patch_version,
latest_beta_version latest_beta_version
) = _latests_versions(tags) ) = _latests_versions(tags)
current_version = Pep440Version(__version__) current_version = Pep440Version(__version__)
has_latest_major = \ has_latest_major = \
@ -121,7 +121,7 @@ def _current_version_summary() -> dict:
and latest_major_version.base_version <= latest_beta_version.base_version \ and latest_major_version.base_version <= latest_beta_version.base_version \
if latest_beta_version else False if latest_beta_version else False
response = { response = {
'latest_major': has_latest_major, 'latest_major': has_latest_major,
'latest_minor': has_latest_minor, 'latest_minor': has_latest_minor,
'latest_patch': has_latest_patch, 'latest_patch': has_latest_patch,
@ -131,7 +131,7 @@ def _current_version_summary() -> dict:
'latest_minor_version': str(latest_minor_version), 'latest_minor_version': str(latest_minor_version),
'latest_patch_version': str(latest_patch_version), 'latest_patch_version': str(latest_patch_version),
'latest_beta_version': str(latest_beta_version) 'latest_beta_version': str(latest_beta_version)
} }
return response return response
@ -141,14 +141,14 @@ def _fetch_tags_from_gitlab():
def _latests_versions(tags: list) -> tuple: def _latests_versions(tags: list) -> tuple:
"""returns latests version from given tags list """returns latests version from given tags list
Non-compliant tags will be ignored Non-compliant tags will be ignored
""" """
versions = list() versions = list()
betas = list() betas = list()
for tag in tags: for tag in tags:
try: try:
version = Pep440Version(tag.get('name')) version = Pep440Version(tag.get('name'))
except InvalidVersion: except InvalidVersion:
pass pass
else: else:
@ -162,21 +162,21 @@ def _latests_versions(tags: list) -> tuple:
v for v in versions if v.major == latest_version.major v for v in versions if v.major == latest_version.major
]) ])
latest_minor_version = min([ latest_minor_version = min([
v for v in versions v for v in versions
if v.major == latest_version.major and v.minor == latest_version.minor if v.major == latest_version.major and v.minor == latest_version.minor
]) ])
latest_beta_version = max(betas) latest_beta_version = max(betas)
return ( return (
latest_major_version, latest_major_version,
latest_minor_version, latest_minor_version,
latest_patch_version, latest_patch_version,
latest_beta_version latest_beta_version
) )
def _fetch_list_from_gitlab(url: str, max_pages: int = MAX_PAGES) -> list: def _fetch_list_from_gitlab(url: str, max_pages: int = MAX_PAGES) -> list:
"""returns a list from the GitLab API. Supports pageing""" """returns a list from the GitLab API. Supports pageing"""
result = list() result = list()
for page in range(1, max_pages + 1): for page in range(1, max_pages + 1):
request = requests.get( request = requests.get(
url, params={'page': page}, timeout=REQUESTS_TIMEOUT url, params={'page': page}, timeout=REQUESTS_TIMEOUT
@ -190,8 +190,8 @@ def _fetch_list_from_gitlab(url: str, max_pages: int = MAX_PAGES) -> list:
total_pages = None total_pages = None
else: else:
total_pages = None total_pages = None
if not total_pages or page >= total_pages: if not total_pages or page >= total_pages:
break break
return result return result