From 9f832e13fbf83919f5ef95f37d984ebbb53de910 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Wed, 16 Aug 2017 09:25:45 +0100 Subject: [PATCH] Set user_id when creating leases The user_id field in leases is set from ctx.user_id, which is always None because it is not defined in trusts.create_ctx_from_trust(). Nevertheless, we cannot use this value since we are in the trustee context, which is the blazar user. This patch modifies the API handler so that the real user_id is included in the lease_values dict passed to create_lease(). Ideally, the context would be extended to include a field referring to the trustor user. Change-Id: If0ee6efcd30dc56dfd78fbfe566517a8d8aa6ba7 Closes-Bug: #1709103 --- blazar/api/v1/service.py | 5 +++++ blazar/manager/service.py | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/blazar/api/v1/service.py b/blazar/api/v1/service.py index 1fbd6994..48fbd5f3 100644 --- a/blazar/api/v1/service.py +++ b/blazar/api/v1/service.py @@ -49,6 +49,11 @@ class API(object): :param data: New lease characteristics. :type data: dict """ + # TODO(priteau): If possible, extend the context object used in the + # manager to keep track of the trustor, instead of using the following + # two lines + ctx = context.current() + data['user_id'] = ctx.user_id return self.manager_rpcapi.create_lease(data) @policy.authorize('leases', 'get') diff --git a/blazar/manager/service.py b/blazar/manager/service.py index 1cefda71..4d560baf 100644 --- a/blazar/manager/service.py +++ b/blazar/manager/service.py @@ -208,7 +208,9 @@ class ManagerService(service_utils.RPCServer): 'Start date must later than current date') with trusts.create_ctx_from_trust(trust_id) as ctx: - lease_values['user_id'] = ctx.user_id + # NOTE(priteau): We should not get user_id from ctx, because we are + # in the context of the trustee (blazar user). + # lease_values['user_id'] is set in blazar/api/v1/service.py lease_values['project_id'] = ctx.project_id lease_values['start_date'] = start_date lease_values['end_date'] = end_date