Add a new config MAX_SERVER_TAGS_ALLOWED to limit the number of tags on server node. #8192

pull/8246/head
Aditya Toshniwal 2024-12-06 12:16:15 +05:30
parent 1cf9ced260
commit 60078c37a3
5 changed files with 14 additions and 3 deletions

View File

@ -940,6 +940,11 @@ SERVER_HEARTBEAT_TIMEOUT = 30 # In seconds
#############################################################################
ENABLE_SERVER_PASS_EXEC_CMD = False
#############################################################################
# Maximum number of Tags allowed on a server node
##############################################################################
MAX_SERVER_TAGS_ALLOWED = 5
#############################################################################
# Number of records to fetch in one batch for server logs.
##############################################################################

View File

@ -502,7 +502,6 @@ def utils():
# This will be opposite of use_space option
editor_indent_with_tabs = False if editor_use_spaces else True
prefs = Preferences.module('browser')
# Try to fetch current libpq version from the driver
try:
from config import PG_DEFAULT_DRIVER
@ -574,6 +573,7 @@ def utils():
restricted_shared_storage_list=[] if current_user.has_role(
"Administrator") else restricted_shared_storage_list,
enable_server_passexec_cmd=config.ENABLE_SERVER_PASS_EXEC_CMD,
max_server_tags_allowed=config.MAX_SERVER_TAGS_ALLOWED,
),
200, {'Content-Type': MIMETYPE_APP_JS})

View File

@ -398,10 +398,10 @@ export default class ServerSchema extends BaseUISchema {
helpMessage: gettext('If it is set to 0, every query is prepared the first time it is executed. If it is set to blank, prepared statements are disabled on the connection.')
},
{
id: 'tags', label: '',
id: 'tags', label: gettext('Tags'),
type: 'collection', group: gettext('Tags'),
schema: this.tagsSchema, mode: ['edit', 'create'], uniqueCol: ['text'],
canAdd: true, canEdit: false, canDelete: true,
canAdd: true, canEdit: false, canDelete: true, maxCount: pgAdmin.Browser.utils.max_server_tags_allowed,
},
];
}

View File

@ -100,6 +100,7 @@ define('pgadmin.browser.utils',
pg_libpq_version: {{pg_libpq_version|e}},
support_ssh_tunnel: '{{ support_ssh_tunnel }}' == 'True',
logout_url: '{{logout_url}}',
max_server_tags_allowed: {{max_server_tags_allowed}},
counter: {total: 0, loaded: 0},
registerScripts: function (ctx) {

View File

@ -252,6 +252,11 @@ export function validateCollectionSchema(
const rows = sessData[field.id] || [];
const currPath = accessPath.concat(field.id);
if(rows.length > field.maxCount) {
setError(currPath, gettext('Maximum %s \'%s\' allowed',field.maxCount, field.label));
return true;
}
// Loop through data.
for(const [rownum, row] of rows.entries()) {
if(validateSchema(