Repository: privacyidea/privacyidea

Issue:
add policy for audit_page_size
Add a policy `audit_page_size`, that defines how many audit entries are displayed. Analogous to `token_page_size`.


Discussion:

Resolving patch:
diff --git a/privacyidea/api/lib/postpolicy.py b/privacyidea/api/lib/postpolicy.py
--- a/privacyidea/api/lib/postpolicy.py
+++ b/privacyidea/api/lib/postpolicy.py
@@ -71,6 +71,7 @@
 optional = True
 required = False
 DEFAULT_LOGOUT_TIME = 120
+DEFAULT_AUDIT_PAGE_SIZE = 10
 DEFAULT_PAGE_SIZE = 15
 DEFAULT_TOKENTYPE = "hotp"
 DEFAULT_TIMEOUT_ACTION = "lockscreeen"
@@ -487,6 +488,8 @@ def get_webui_settings(request, response):
                                         user=loginname, realm=realm).action_values(unique=True)
         timeout_action_pol = Match.generic(g, scope=SCOPE.WEBUI, action=ACTION.TIMEOUT_ACTION,
                                            user=loginname, realm=realm).action_values(unique=True)
+        audit_page_size_pol = Match.generic(g, scope=SCOPE.WEBUI, action=ACTION.AUDITPAGESIZE,
+                                            user=loginname, realm=realm).action_values(unique=True)
         token_page_size_pol = Match.generic(g, scope=SCOPE.WEBUI, action=ACTION.TOKENPAGESIZE,
                                             user=loginname, realm=realm).action_values(unique=True)
         user_page_size_pol = Match.generic(g, scope=SCOPE.WEBUI, action=ACTION.USERPAGESIZE,
@@ -536,9 +539,12 @@ def get_webui_settings(request, response):
         qr_image_android = create_img(DEFAULT_ANDROID_APP_URL) if qr_android_authenticator else None
         qr_image_ios = create_img(DEFAULT_IOS_APP_URL) if qr_ios_authenticator else None
         qr_image_custom = create_img(list(qr_custom_authenticator_url)[0]) if qr_custom_authenticator_url else None
+        audit_page_size = DEFAULT_AUDIT_PAGE_SIZE
         token_page_size = DEFAULT_PAGE_SIZE
         user_page_size = DEFAULT_PAGE_SIZE
         default_tokentype = DEFAULT_TOKENTYPE
+        if len(audit_page_size_pol) == 1:
+            audit_page_size = int(list(audit_page_size_pol)[0])
         if len(token_page_size_pol) == 1:
             token_page_size = int(list(token_page_size_pol)[0])
         if len(user_page_size_pol) == 1:
@@ -571,6 +577,7 @@ def get_webui_settings(request, response):
             content["result"]["value"]["indexedsecret_force_attribute"] = 1
 
         content["result"]["value"]["logout_time"] = logout_time
+        content["result"]["value"]["audit_page_size"] = audit_page_size
         content["result"]["value"]["token_page_size"] = token_page_size
         content["result"]["value"]["user_page_size"] = user_page_size
         content["result"]["value"]["policy_template_url"] = policy_template_url
diff --git a/privacyidea/lib/policy.py b/privacyidea/lib/policy.py
--- a/privacyidea/lib/policy.py
+++ b/privacyidea/lib/policy.py
@@ -228,6 +228,7 @@ class ACTION(object):
     AUDIT = "auditlog"
     AUDIT_AGE = "auditlog_age"
     AUDIT_DOWNLOAD = "auditlog_download"
+    AUDITPAGESIZE = "audit_page_size"
     AUTHITEMS = "fetch_authentication_items"
     AUTHMAXSUCCESS = "auth_max_success"
     AUTHMAXFAIL = "auth_max_fail"
@@ -2432,6 +2433,11 @@ def get_static_policy_definitions(scope=None):
                 'desc': _("Set how many users should be displayed in the user "
                           "view on one page.")
             },
+            ACTION.AUDITPAGESIZE: {
+                'type': 'int',
+                'desc': _("Set how many audit entries should be displayed in the audit "
+                          "view on one page.")
+            },
             ACTION.CUSTOM_MENU: {
                 'type': 'str',
                 'desc': _("Use your own html template for the web UI menu.")


Test patch:
diff --git a/tests/test_api_roles.py b/tests/test_api_roles.py
--- a/tests/test_api_roles.py
+++ b/tests/test_api_roles.py
@@ -1006,6 +1006,8 @@ def test_41_webui_settings(self):
             ACTION.USERPAGESIZE, 20))
         set_policy(name="webui3", scope=SCOPE.WEBUI, action="{0!s}={1!s}".format(
             ACTION.LOGOUTTIME, 200))
+        set_policy(name="webui4", scope=SCOPE.WEBUI, action="{0!s}={1!s}".format(
+            ACTION.AUDITPAGESIZE, 20))
         with self.app.test_request_context('/auth',
                                            method='POST',
                                            data={"username": "selfservice@realm1",
@@ -1016,6 +1018,7 @@ def test_41_webui_settings(self):
             self.assertTrue(result.get("status"), res.data)
             # Test logout time
             self.assertEqual(result.get("value").get("logout_time"), 200)
+            self.assertEqual(result.get("value").get("audit_page_size"), 20)
             self.assertEqual(result.get("value").get("token_page_size"), 20)
             self.assertEqual(result.get("value").get("user_page_size"), 20)
             self.assertEqual(result.get("value").get("policy_template_url"),