Skip to content
This repository was archived by the owner on Oct 1, 2022. It is now read-only.

Commit dfd99a8

Browse files
committed
Fix bug where submitted_by property of request did not type-check when user mgmt was enabled
1 parent 285c5b4 commit dfd99a8

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

servicex/resources/servicex_resource.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from flask_jwt_extended import get_jwt_identity
3434
from flask_restful import Resource
3535

36-
from servicex.models import TransformationResult
36+
from servicex.models import TransformationResult, UserModel
3737

3838

3939
class ServiceXResource(Resource):
@@ -42,14 +42,17 @@ def _generate_advertised_endpoint(cls, endpoint):
4242
return "http://" + current_app.config['ADVERTISED_HOSTNAME'] + "/" + endpoint
4343

4444
@staticmethod
45-
def get_requesting_user_sub() -> Optional[str]:
45+
def get_requesting_user() -> Optional[UserModel]:
4646
"""
4747
:return: User who submitted request for resource.
4848
If auth is enabled, this cannot be None for JWT-protected resources
4949
which are decorated with @auth_required or @admin_required.
5050
"""
51-
if current_app.config.get('ENABLE_AUTH'):
52-
return get_jwt_identity()
51+
user = None
52+
cfg = current_app.config
53+
if cfg.get('ENABLE_AUTH') and not cfg.get('DISABLE_USER_MGMT'):
54+
user = UserModel.find_by_sub(get_jwt_identity())
55+
return user
5356

5457
@staticmethod
5558
def _generate_file_status_record(dataset_file, status):

servicex/resources/submit_transformation_request.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ def post(self):
149149
app_version=self._get_app_version(),
150150
code_gen_image=current_app.config['CODE_GEN_IMAGE']
151151
)
152-
if current_app.config.get('ENABLE_AUTH') and \
153-
not current_app.config.get('DISABLE_USER_MGMT'):
154-
request_rec.submitted_by = self.get_requesting_user_sub()
152+
user = self.get_requesting_user()
153+
if user is not None:
154+
request_rec.submitted_by = user.id
155155

156156
# If we are doing the xaod_cpp workflow, then the first thing to do is make
157157
# sure the requested selection is correct, and generate the C++ files

0 commit comments

Comments
 (0)