Skip to content

Commit

Permalink
v1.2: Enforce entity presence based on selected place
Browse files Browse the repository at this point in the history
Added validation to ensure at least one entity is selected if the place is not "All". Updated JSON data handling in JS and corrected reference mismatch in tools module.
  • Loading branch information
Aidaho12 committed Oct 23, 2024
1 parent 2ea44fa commit ea9a920
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ class Configuration(object):
JWT_IDENTITY_CLAIM = 'user_id'
JWT_ERROR_MESSAGE_KEY = 'error'
FLASK_PYDANTIC_VALIDATION_ERROR_RAISE = True
JSONIFY_PRETTYPRINT_REGULAR = False
13 changes: 13 additions & 0 deletions app/modules/roxywi/class_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ def timeout_must_be_lower_interval(cls, values):
raise ValueError('timeout value must be less than interval')
return values

@root_validator(pre=True)
@classmethod
def check_must_has_entities_if_not_all_place(cls, values):
place = ''
entities = []
if 'place' in values:
place = values['place']
if 'entities' in values:
entities = values['entities']
if place != 'all' and len(entities) == 0:
raise ValueError('Check must have at least on entity, if place is not "All"')
return values


class HttpCheckRequest(BaseCheckRequest):
url: AnyUrl
Expand Down
4 changes: 2 additions & 2 deletions app/modules/tools/smon.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ def show_status_page(slug: str) -> str:
check_type = s.check_type
en = s.enabled
multi_check_id = s.multi_check_id
if s.group_id:
group = smon_sql.get_smon_group_name_by_id(s.group_id)
if s.check_group_id:
group = smon_sql.get_smon_group_name_by_id(s.check_group_id)
else:
group = 'No group'

Expand Down
8 changes: 7 additions & 1 deletion app/static/js/rmon/smon.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ function addNewSmonServer(dialog_id, smon_id=0, edit=false) {
let entity_id = elem.id.split('-')[1]
entities.push(entity_id);
});
if ($('#new-smon-place option:selected').val() !== 'all') {
if (entities.length === 0) {
toastr.warning('Check must have at least one entity');
return false;
}
}
let jsonData = {
'name': $('#new-smon-name').val(),
'ip': $('#new-smon-ip').val(),
Expand All @@ -106,7 +112,7 @@ function addNewSmonServer(dialog_id, smon_id=0, edit=false) {
'enabled': enable,
'url': $('#new-smon-url').val(),
'body': $('#new-smon-body').val(),
'check_group_id': $('#new-smon-group').val(),
'check_group': $('#new-smon-group').val(),
'description': $('#new-smon-description').val(),
'tg': $('#new-smon-telegram').val(),
'slack': $('#new-smon-slack').val(),
Expand Down

0 comments on commit ea9a920

Please sign in to comment.