Skip to content

Commit

Permalink
Refs #253. Fixed backwards forms compatibility for OpenTeraPlus <= 1.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Oct 7, 2024
1 parent 5b90d8a commit 398a7a6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
3 changes: 2 additions & 1 deletion teraserver/python/modules/FlaskModule/API/user/UserLogin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def _common_login_response(self, parser):
response['user_uuid'] = current_user.user_uuid
response['user_token'] = self._generate_user_token()

self._send_login_success_message()

except OutdatedClientVersionError as e:
self._user_logout()

Expand All @@ -90,7 +92,6 @@ def _common_login_response(self, parser):
raise e
else:
# Everything went well, return response
self._send_login_success_message()
return response, 200


Expand Down
24 changes: 18 additions & 6 deletions teraserver/python/modules/FlaskModule/API/user/UserQueryForms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from flask_restx import Resource
from modules.LoginModule.LoginModule import user_multi_auth, current_user
from modules.FlaskModule.FlaskModule import user_api_ns as api
from modules.DatabaseModule.DBManager import DBManager
from flask_babel import gettext

from opentera.db.models.TeraSessionType import TeraSessionType
from opentera.db.models.TeraParticipantGroup import TeraParticipantGroup
Expand All @@ -26,7 +24,11 @@
from opentera.forms.TeraTestTypeForm import TeraTestTypeForm

from opentera.redis.RedisRPCClient import RedisRPCClient

import json
from flask_babel import gettext
from flask_restx import Resource
from flask import request

get_parser = api.parser()
get_parser.add_argument(name='type', type=str, help='Data type of the required form. Currently, the '
Expand Down Expand Up @@ -75,9 +77,19 @@ def get(self):
args = get_parser.parse_args()
user_access = DBManager.userAccess(current_user)

# if args['type'] == 'user_profile':
# return jsonify(TeraUserForm.get_user_profile_form())
# If we have no arguments, return error
show_2fa_fields = True
if 'X-Client-Name' in request.headers and 'X-Client-Version' in request.headers:
client_name = request.headers['X-Client-Name']
client_version = request.headers['X-Client-Version']
client_version_parts = client_version.split('.')
if client_name == 'OpenTeraPlus':
# TODO: Remove when all OpenTeraPlus clients are updated at least to 1.3.0 version
if len(client_version_parts) >= 2:
if int(client_version_parts[1]) < 3 and int(client_version_parts[0]) == 1:
show_2fa_fields = False
else:
show_2fa_fields = False

if 'type' not in args:
return gettext('Missing type'), 400
Expand All @@ -86,10 +98,10 @@ def get(self):
return gettext('Missing arguments'), 400

if args['type'] == 'user':
return TeraUserForm.get_user_form()
return TeraUserForm.get_user_form(show_2fa_fields=show_2fa_fields)

if args['type'] == 'site':
return TeraSiteForm.get_site_form()
return TeraSiteForm.get_site_form(show_2fa_fields=show_2fa_fields)

if args['type'] == 'device':
return TeraDeviceForm.get_device_form()
Expand Down
8 changes: 5 additions & 3 deletions teraserver/python/opentera/forms/TeraSiteForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
class TeraSiteForm:

@staticmethod
def get_site_form():
def get_site_form(**kwargs):
form = TeraForm("site")
show_2fa_fields = kwargs.get('show_2fa_fields', True)

# Sections
section = TeraFormSection("informations", gettext("Information"))
Expand All @@ -15,8 +16,9 @@ def get_site_form():
# Items
section.add_item(TeraFormItem("id_site", gettext("Site ID"), "hidden", True))
section.add_item(TeraFormItem("site_name", gettext("Site Name"), "text", True))
section.add_item(TeraFormItem("site_2fa_required", gettext("Users Require 2FA"), "boolean",
False, item_default=False))
if show_2fa_fields:
section.add_item(TeraFormItem("site_2fa_required", gettext("Users Require 2FA"), "boolean",
False, item_default=False))
section.add_item(TeraFormItem("site_role", gettext("Site Role"), "hidden", False))

return form.to_dict()
29 changes: 16 additions & 13 deletions teraserver/python/opentera/forms/TeraUserForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
class TeraUserForm:

@staticmethod
def get_user_form():
def get_user_form(**kwargs):
form = TeraForm("user")
show_2fa_fields = kwargs.get('show_2fa_fields', True)

# Sections
section = TeraFormSection("informations", gettext("Information"))
Expand All @@ -20,18 +21,20 @@ def get_user_form():
section.add_item(TeraFormItem("user_username", gettext("Username"), "text", True))
section.add_item(TeraFormItem("user_enabled", gettext("User Enabled"), "boolean",
True, item_default=True))
section.add_item(TeraFormItem("user_force_password_change", gettext("Force password change"),
"boolean", False, item_default=False))
section.add_item(TeraFormItem("user_2fa_enabled", gettext("2FA Enabled"), "boolean",
False, item_default=False))

section.add_item(TeraFormItem("user_2fa_otp_enabled", gettext("2FA OTP Enabled"), "boolean",
False, item_default=False,
item_condition=TeraFormItemCondition("user_2fa_enabled", "=", True)))
section.add_item(TeraFormItem("user_2fa_email_enabled", gettext("2FA Email Enabled"), "hidden",
False, item_default=False,
# item_condition = TeraFormItemCondition("user_2fa_enabled", "=", True)
))

if show_2fa_fields:
section.add_item(TeraFormItem("user_force_password_change", gettext("Force password change"),
"boolean", False, item_default=False))
section.add_item(TeraFormItem("user_2fa_enabled", gettext("2FA Enabled"), "boolean",
False, item_default=False))

section.add_item(TeraFormItem("user_2fa_otp_enabled", gettext("2FA OTP Enabled"), "boolean",
False, item_default=False,
item_condition=TeraFormItemCondition("user_2fa_enabled", "=", True)))
section.add_item(TeraFormItem("user_2fa_email_enabled", gettext("2FA Email Enabled"), "hidden",
False, item_default=False,
# item_condition = TeraFormItemCondition("user_2fa_enabled", "=", True)
))

# section.add_item(TeraFormItem("user_2fa_otp_secret", gettext("OTP Secret"), "hidden"))
section.add_item(TeraFormItem("user_firstname", gettext("First Name"), "text", True))
Expand Down

0 comments on commit 398a7a6

Please sign in to comment.