check_credentials() now returns the entire user, not just the ID.
This commit is contained in:
parent
887a9cc697
commit
1df113ca01
@ -117,8 +117,8 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|||||||
try:
|
try:
|
||||||
# Refresh credentials
|
# Refresh credentials
|
||||||
try:
|
try:
|
||||||
self.user_id = await self.check_credentials(context,
|
db_user = await self.check_credentials(context, REQUIRES_ROLES_FOR_IMAGE_SHARING)
|
||||||
REQUIRES_ROLES_FOR_IMAGE_SHARING)
|
self.user_id = db_user['_id']
|
||||||
self.log.debug('Found user ID: %s', self.user_id)
|
self.log.debug('Found user ID: %s', self.user_id)
|
||||||
except pillar.NotSubscribedToCloudError:
|
except pillar.NotSubscribedToCloudError:
|
||||||
self.log.exception('User not subscribed to cloud.')
|
self.log.exception('User not subscribed to cloud.')
|
||||||
|
@ -241,7 +241,7 @@ async def check_pillar_credentials(required_roles: set):
|
|||||||
profile.save_json()
|
profile.save_json()
|
||||||
raise NotSubscribedToCloudError()
|
raise NotSubscribedToCloudError()
|
||||||
|
|
||||||
return pillar_user_id
|
return db_user
|
||||||
|
|
||||||
|
|
||||||
async def refresh_pillar_credentials(required_roles: set):
|
async def refresh_pillar_credentials(required_roles: set):
|
||||||
@ -780,7 +780,7 @@ def is_cancelled(future: asyncio.Future) -> bool:
|
|||||||
|
|
||||||
class PillarOperatorMixin:
|
class PillarOperatorMixin:
|
||||||
async def check_credentials(self, context, required_roles) -> bool:
|
async def check_credentials(self, context, required_roles) -> bool:
|
||||||
"""Checks credentials with Pillar, and if ok returns the user ID.
|
"""Checks credentials with Pillar, and if ok returns the user document from Pillar/MongoDB.
|
||||||
|
|
||||||
Returns None if the user cannot be found, or if the user is not a Cloud subscriber.
|
Returns None if the user cannot be found, or if the user is not a Cloud subscriber.
|
||||||
"""
|
"""
|
||||||
@ -788,7 +788,7 @@ class PillarOperatorMixin:
|
|||||||
# self.report({'INFO'}, 'Checking Blender Cloud credentials')
|
# self.report({'INFO'}, 'Checking Blender Cloud credentials')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_id = await check_pillar_credentials(required_roles)
|
db_user = await check_pillar_credentials(required_roles)
|
||||||
except NotSubscribedToCloudError:
|
except NotSubscribedToCloudError:
|
||||||
self._log_subscription_needed()
|
self._log_subscription_needed()
|
||||||
raise
|
raise
|
||||||
@ -796,10 +796,10 @@ class PillarOperatorMixin:
|
|||||||
self.log.info('Credentials not synced, re-syncing automatically.')
|
self.log.info('Credentials not synced, re-syncing automatically.')
|
||||||
else:
|
else:
|
||||||
self.log.info('Credentials okay.')
|
self.log.info('Credentials okay.')
|
||||||
return user_id
|
return db_user
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_id = await refresh_pillar_credentials(required_roles)
|
db_user = await refresh_pillar_credentials(required_roles)
|
||||||
except NotSubscribedToCloudError:
|
except NotSubscribedToCloudError:
|
||||||
self._log_subscription_needed()
|
self._log_subscription_needed()
|
||||||
raise
|
raise
|
||||||
@ -807,7 +807,7 @@ class PillarOperatorMixin:
|
|||||||
self.log.error('User not logged in on Blender ID.')
|
self.log.error('User not logged in on Blender ID.')
|
||||||
else:
|
else:
|
||||||
self.log.info('Credentials refreshed and ok.')
|
self.log.info('Credentials refreshed and ok.')
|
||||||
return user_id
|
return db_user
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -281,7 +281,8 @@ class PILLAR_OT_sync(pillar.PillarOperatorMixin,
|
|||||||
try:
|
try:
|
||||||
# Refresh credentials
|
# Refresh credentials
|
||||||
try:
|
try:
|
||||||
self.user_id = await self.check_credentials(context, REQUIRES_ROLES_FOR_SYNC)
|
db_user = await self.check_credentials(context, REQUIRES_ROLES_FOR_SYNC)
|
||||||
|
self.user_id = db_user['_id']
|
||||||
log.debug('Found user ID: %s', self.user_id)
|
log.debug('Found user ID: %s', self.user_id)
|
||||||
except pillar.NotSubscribedToCloudError:
|
except pillar.NotSubscribedToCloudError:
|
||||||
self.log.exception('User not subscribed to cloud.')
|
self.log.exception('User not subscribed to cloud.')
|
||||||
|
@ -363,13 +363,13 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
self.log.debug('Checking credentials')
|
self.log.debug('Checking credentials')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_id = await self.check_credentials(context, REQUIRED_ROLES_FOR_TEXTURE_BROWSER)
|
db_user = await self.check_credentials(context, REQUIRED_ROLES_FOR_TEXTURE_BROWSER)
|
||||||
except pillar.NotSubscribedToCloudError:
|
except pillar.NotSubscribedToCloudError:
|
||||||
self.log.info('User not subscribed to Blender Cloud.')
|
self.log.info('User not subscribed to Blender Cloud.')
|
||||||
self._show_subscribe_screen()
|
self._show_subscribe_screen()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if user_id is None:
|
if db_user is None:
|
||||||
raise pillar.UserNotLoggedInError()
|
raise pillar.UserNotLoggedInError()
|
||||||
|
|
||||||
await self.async_download_previews()
|
await self.async_download_previews()
|
||||||
@ -854,7 +854,8 @@ class PILLAR_OT_switch_hdri(pillar.PillarOperatorMixin,
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
user_id = await self.check_credentials(context, REQUIRED_ROLES_FOR_TEXTURE_BROWSER)
|
db_user = await self.check_credentials(context, REQUIRED_ROLES_FOR_TEXTURE_BROWSER)
|
||||||
|
user_id = db_user['_id']
|
||||||
except pillar.NotSubscribedToCloudError:
|
except pillar.NotSubscribedToCloudError:
|
||||||
self.log.exception('User not subscribed to cloud.')
|
self.log.exception('User not subscribed to cloud.')
|
||||||
self.report({'ERROR'}, 'Please subscribe to the Blender Cloud.')
|
self.report({'ERROR'}, 'Please subscribe to the Blender Cloud.')
|
||||||
|
Reference in New Issue
Block a user