From 1df113ca018682aa85faf27cea9098748bd46be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 26 Aug 2016 17:43:07 +0200 Subject: [PATCH] check_credentials() now returns the entire user, not just the ID. --- blender_cloud/image_sharing.py | 4 ++-- blender_cloud/pillar.py | 12 ++++++------ blender_cloud/settings_sync.py | 3 ++- blender_cloud/texture_browser.py | 7 ++++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/blender_cloud/image_sharing.py b/blender_cloud/image_sharing.py index cee5e02..b8d21b3 100644 --- a/blender_cloud/image_sharing.py +++ b/blender_cloud/image_sharing.py @@ -117,8 +117,8 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin, try: # Refresh credentials try: - self.user_id = await self.check_credentials(context, - REQUIRES_ROLES_FOR_IMAGE_SHARING) + db_user = await self.check_credentials(context, REQUIRES_ROLES_FOR_IMAGE_SHARING) + self.user_id = db_user['_id'] self.log.debug('Found user ID: %s', self.user_id) except pillar.NotSubscribedToCloudError: self.log.exception('User not subscribed to cloud.') diff --git a/blender_cloud/pillar.py b/blender_cloud/pillar.py index 5f66e1d..17da5b7 100644 --- a/blender_cloud/pillar.py +++ b/blender_cloud/pillar.py @@ -241,7 +241,7 @@ async def check_pillar_credentials(required_roles: set): profile.save_json() raise NotSubscribedToCloudError() - return pillar_user_id + return db_user async def refresh_pillar_credentials(required_roles: set): @@ -780,7 +780,7 @@ def is_cancelled(future: asyncio.Future) -> bool: class PillarOperatorMixin: 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. """ @@ -788,7 +788,7 @@ class PillarOperatorMixin: # self.report({'INFO'}, 'Checking Blender Cloud credentials') try: - user_id = await check_pillar_credentials(required_roles) + db_user = await check_pillar_credentials(required_roles) except NotSubscribedToCloudError: self._log_subscription_needed() raise @@ -796,10 +796,10 @@ class PillarOperatorMixin: self.log.info('Credentials not synced, re-syncing automatically.') else: self.log.info('Credentials okay.') - return user_id + return db_user try: - user_id = await refresh_pillar_credentials(required_roles) + db_user = await refresh_pillar_credentials(required_roles) except NotSubscribedToCloudError: self._log_subscription_needed() raise @@ -807,7 +807,7 @@ class PillarOperatorMixin: self.log.error('User not logged in on Blender ID.') else: self.log.info('Credentials refreshed and ok.') - return user_id + return db_user return None diff --git a/blender_cloud/settings_sync.py b/blender_cloud/settings_sync.py index 69c43b9..98fb365 100644 --- a/blender_cloud/settings_sync.py +++ b/blender_cloud/settings_sync.py @@ -281,7 +281,8 @@ class PILLAR_OT_sync(pillar.PillarOperatorMixin, try: # Refresh credentials 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) except pillar.NotSubscribedToCloudError: self.log.exception('User not subscribed to cloud.') diff --git a/blender_cloud/texture_browser.py b/blender_cloud/texture_browser.py index cfbe99f..6e02309 100644 --- a/blender_cloud/texture_browser.py +++ b/blender_cloud/texture_browser.py @@ -363,13 +363,13 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin, self.log.debug('Checking credentials') 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: self.log.info('User not subscribed to Blender Cloud.') self._show_subscribe_screen() return None - if user_id is None: + if db_user is None: raise pillar.UserNotLoggedInError() await self.async_download_previews() @@ -854,7 +854,8 @@ class PILLAR_OT_switch_hdri(pillar.PillarOperatorMixin, 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: self.log.exception('User not subscribed to cloud.') self.report({'ERROR'}, 'Please subscribe to the Blender Cloud.')