Skip to content

Commit

Permalink
Add a new config MAX_SERVER_TAGS_ALLOWED to limit the number of tags …
Browse files Browse the repository at this point in the history
…on server node. #8192
  • Loading branch information
adityatoshniwal committed Dec 6, 2024
1 parent 1cf9ced commit 60078c3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions web/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,11 @@
#############################################################################
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.
##############################################################################
Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
];
}
Expand Down
1 change: 1 addition & 0 deletions web/pgadmin/browser/templates/browser/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions web/pgadmin/static/js/SchemaView/SchemaState/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 60078c3

Please sign in to comment.