api: remove deprecated statistics from API listing (#86177)
gitea/authentic/pipeline/head This commit looks good Details

This commit is contained in:
Yann Weber 2024-01-29 15:30:49 +01:00 committed by Yann Weber
parent 3bcba166f5
commit d7bfac4ed5
2 changed files with 39 additions and 62 deletions

View File

@ -1642,7 +1642,7 @@ class StatisticsAPI(ViewSet):
filters.append(group_by_filter)
deprecated = False
else:
deprecated = True
continue # stop listing deprecated statistics (#86177)
filters.extend(self.get_additional_filters(action.filters))
data = {

View File

@ -33,13 +33,12 @@ User = get_user_model()
def test_api_statistics_list(app, admin):
headers = basic_authorization_header(admin)
resp = app.get('/api/statistics/', headers=headers)
assert len(resp.json['data']) == 8
login_stats = {
'name': 'Login count by authentication type',
'url': 'https://testserver/api/statistics/login/',
'id': 'login',
assert len(resp.json['data']) == 2
login_new = {
'deprecated': False,
'filters': [
{
'default': 'month',
'id': 'time_interval',
'label': 'Time interval',
'options': [
@ -48,19 +47,27 @@ def test_api_statistics_list(app, admin):
{'id': 'year', 'label': 'Year'},
],
'required': True,
'default': 'month',
},
{'id': 'service', 'label': 'Service', 'options': []},
{
'has_subfilters': True,
'id': 'group_by',
'label': 'Group by',
'options': [
{'id': 'authentication_type', 'label': 'Authentication type'},
{'id': 'service', 'label': 'Service'},
{'id': 'service_ou', 'label': 'Organizational unit'},
],
},
],
'deprecated': True,
'id': 'login-new',
'name': 'Login count',
'url': 'https://testserver/api/statistics/login_new/',
}
assert login_stats in resp.json['data']
assert {
'name': 'Login count by service',
'url': 'https://testserver/api/statistics/service_login/',
'id': 'service-login',
register_new = {
'deprecated': False,
'filters': [
{
'default': 'month',
'id': 'time_interval',
'label': 'Time interval',
'options': [
@ -69,56 +76,26 @@ def test_api_statistics_list(app, admin):
{'id': 'year', 'label': 'Year'},
],
'required': True,
'default': 'month',
},
{
'has_subfilters': True,
'id': 'group_by',
'label': 'Group by',
'options': [
{'id': 'authentication_type', 'label': 'Authentication type'},
{'id': 'service', 'label': 'Service'},
{'id': 'service_ou', 'label': 'Organizational unit'},
],
},
],
'deprecated': True,
} in resp.json['data']
service = Service.objects.create(name='Service1', slug='service1', ou=get_default_ou())
service = Service.objects.create(name='Service2', slug='service2', ou=get_default_ou())
login_stats['filters'][1]['options'].append({'id': 'service1 default', 'label': 'Service1'})
login_stats['filters'][1]['options'].append({'id': 'service2 default', 'label': 'Service2'})
resp = app.get('/api/statistics/', headers=headers)
assert login_stats == resp.json['data'][0]
# adding second ou doesn't change anything
ou = OU.objects.create(name='Second OU', slug='second')
resp = app.get('/api/statistics/', headers=headers)
assert login_stats in resp.json['data']
# if there are services in two differents OUs, filter is shown
service.ou = ou
service.save()
login_stats['filters'][1]['options'][1]['id'] = 'service2 second'
login_stats['filters'].append(
{
'id': 'services_ou',
'label': 'Services organizational unit',
'options': [
{'id': 'default', 'label': 'Default organizational unit'},
{'id': 'second', 'label': 'Second OU'},
],
}
)
resp = app.get('/api/statistics/', headers=headers)
assert login_stats in resp.json['data']
# same goes with users
User.objects.create(username='john.doe', email='john.doe@example.com', ou=ou)
login_stats['filters'].append(
{
'id': 'users_ou',
'label': 'Users organizational unit',
'options': [
{'id': 'default', 'label': 'Default organizational unit'},
{'id': 'second', 'label': 'Second OU'},
],
}
)
resp = app.get('/api/statistics/', headers=headers)
assert login_stats in resp.json['data']
'id': 'registration-new',
'name': 'Registration count',
'url': 'https://testserver/api/statistics/registration_new/',
}
assert login_new in resp.json['data']
assert register_new in resp.json['data']
actions_id = {elt['id'] for elt in resp.json['data']}
assert {'login-new', 'registration-new'} == actions_id
def test_api_statistics_list_new(app, admin):