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
This commit is contained in:
Pierre Riteau 2017-08-16 09:25:45 +01:00
parent cb187056f8
commit 9f832e13fb
2 changed files with 8 additions and 1 deletions

View File

@ -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')

View File

@ -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