Distinguish between 'renew' and 'join' in messages & URL to open.

This commit is contained in:
Sybren A. Stüvel 2018-01-02 14:01:33 +01:00
parent 45cffc5365
commit 77664fb6d7
6 changed files with 55 additions and 31 deletions

View File

@ -1,5 +1,11 @@
# Blender Cloud changelog # Blender Cloud changelog
## Version 1.8 (in development)
- Distinguish between 'please subscribe' (to get a new subscription) and 'please renew' (to renew an
existing subscription).
## Version 1.7.5 (2017-10-06) ## Version 1.7.5 (2017-10-06)
- Sorting the project list alphabetically. - Sorting the project list alphabetically.

View File

@ -79,6 +79,7 @@ def register():
reload_mod('blendfile') reload_mod('blendfile')
reload_mod('home_project') reload_mod('home_project')
reload_mod('utils') reload_mod('utils')
reload_mod('pillar')
async_loop = reload_mod('async_loop') async_loop = reload_mod('async_loop')
flamenco = reload_mod('flamenco') flamenco = reload_mod('flamenco')

View File

@ -124,9 +124,8 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
db_user = 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.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 as ex:
self.log.exception('User not subscribed to cloud.') self._log_subscription_needed(can_renew=ex.can_renew)
self.report({'ERROR'}, 'Please subscribe to the Blender Cloud.')
self._state = 'QUIT' self._state = 'QUIT'
return return
except pillar.UserNotLoggedInError: except pillar.UserNotLoggedInError:

View File

@ -62,7 +62,16 @@ class CredentialsNotSyncedError(UserNotLoggedInError):
class NotSubscribedToCloudError(UserNotLoggedInError): class NotSubscribedToCloudError(UserNotLoggedInError):
"""Raised when the user may be logged in on Blender ID, but has no Blender Cloud token.""" """Raised when the user does not have an active Cloud subscription.
:ivar can_renew: True when the user has an inactive subscription that can be renewed,
or False when the user has no subscription at all.
"""
def __init__(self, can_renew: bool):
super().__init__()
self.can_renew = can_renew
log.warning('Not subscribed to cloud, can_renew=%s', can_renew)
class PillarError(RuntimeError): class PillarError(RuntimeError):
@ -273,14 +282,15 @@ async def check_pillar_credentials(required_roles: set):
except (pillarsdk.UnauthorizedAccess, pillarsdk.ResourceNotFound, pillarsdk.ForbiddenAccess): except (pillarsdk.UnauthorizedAccess, pillarsdk.ResourceNotFound, pillarsdk.ForbiddenAccess):
raise CredentialsNotSyncedError() raise CredentialsNotSyncedError()
roles = db_user.roles or set() roles = set(db_user.roles or set())
log.debug('User has roles %r', roles) log.getChild('check_pillar_credentials').debug('user has roles %r', roles)
if required_roles and not required_roles.intersection(set(roles)): if required_roles and not required_roles.intersection(roles):
# Delete the subclient info. This forces a re-check later, which can # Delete the subclient info. This forces a re-check later, which can
# then pick up on the user's new status. # then pick up on the user's new status.
del profile.subclients[SUBCLIENT_ID] del profile.subclients[SUBCLIENT_ID]
profile.save_json() profile.save_json()
raise NotSubscribedToCloudError()
raise NotSubscribedToCloudError(can_renew='has_subscription' in roles)
return db_user return db_user
@ -834,7 +844,6 @@ class PillarOperatorMixin:
try: try:
db_user = await check_pillar_credentials(required_roles) db_user = await check_pillar_credentials(required_roles)
except NotSubscribedToCloudError: except NotSubscribedToCloudError:
self._log_subscription_needed()
raise raise
except CredentialsNotSyncedError: except CredentialsNotSyncedError:
self.log.info('Credentials not synced, re-syncing automatically.') self.log.info('Credentials not synced, re-syncing automatically.')
@ -845,7 +854,6 @@ class PillarOperatorMixin:
try: try:
db_user = await refresh_pillar_credentials(required_roles) db_user = await refresh_pillar_credentials(required_roles)
except NotSubscribedToCloudError: except NotSubscribedToCloudError:
self._log_subscription_needed()
raise raise
except CredentialsNotSyncedError: except CredentialsNotSyncedError:
self.log.info('Credentials not synced after refreshing, handling as not logged in.') self.log.info('Credentials not synced after refreshing, handling as not logged in.')
@ -857,11 +865,13 @@ class PillarOperatorMixin:
self.log.info('Credentials refreshed and ok.') self.log.info('Credentials refreshed and ok.')
return db_user return db_user
def _log_subscription_needed(self): def _log_subscription_needed(self, *, can_renew: bool, level='ERROR'):
self.log.warning( if can_renew:
'Please subscribe to the blender cloud at https://cloud.blender.org/join') msg = 'Please renew your Blender Cloud subscription at https://cloud.blender.org/renew'
self.report({'INFO'}, else:
'Please subscribe to the blender cloud at https://cloud.blender.org/join') msg = 'Please subscribe to the blender cloud at https://cloud.blender.org/join'
self.log.warning(msg)
self.report({level}, msg)
class AuthenticatedPillarOperatorMixin(PillarOperatorMixin): class AuthenticatedPillarOperatorMixin(PillarOperatorMixin):

View File

@ -284,9 +284,8 @@ class PILLAR_OT_sync(pillar.PillarOperatorMixin,
db_user = 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'] 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 as ex:
self.log.exception('User not subscribed to cloud.') self._log_subscription_needed(can_renew=ex.can_renew)
self.bss_report({'SUBSCRIBE'}, 'Please subscribe to the Blender Cloud.')
self._state = 'QUIT' self._state = 'QUIT'
return return
except pillar.UserNotLoggedInError: except pillar.UserNotLoggedInError:

View File

@ -311,8 +311,8 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
self.mouse_y = event.mouse_y self.mouse_y = event.mouse_y
left_mouse_release = event.type == 'LEFTMOUSE' and event.value == 'RELEASE' left_mouse_release = event.type == 'LEFTMOUSE' and event.value == 'RELEASE'
if self._state == 'PLEASE_SUBSCRIBE' and left_mouse_release: if left_mouse_release and self._state in {'PLEASE_SUBSCRIBE', 'PLEASE_RENEW'}:
self.open_browser_subscribe() self.open_browser_subscribe(renew=self._state == 'PLEASE_RENEW')
self._finish(context) self._finish(context)
return {'FINISHED'} return {'FINISHED'}
@ -365,9 +365,9 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
try: try:
db_user = 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 as ex:
self.log.info('User not subscribed to Blender Cloud.') self._log_subscription_needed(can_renew=ex.can_renew, level='INFO')
self._show_subscribe_screen() self._show_subscribe_screen(can_renew=ex.can_renew)
return None return None
if db_user is None: if db_user is None:
@ -375,10 +375,14 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
await self.async_download_previews() await self.async_download_previews()
def _show_subscribe_screen(self): def _show_subscribe_screen(self, *, can_renew: bool):
"""Shows the "You need to subscribe" screen.""" """Shows the "You need to subscribe" screen."""
if can_renew:
self._state = 'PLEASE_RENEW'
else:
self._state = 'PLEASE_SUBSCRIBE' self._state = 'PLEASE_SUBSCRIBE'
bpy.context.window.cursor_set('HAND') bpy.context.window.cursor_set('HAND')
def descend_node(self, menu_item: MenuItem): def descend_node(self, menu_item: MenuItem):
@ -560,6 +564,7 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
'DOWNLOADING_TEXTURE': self._draw_downloading, 'DOWNLOADING_TEXTURE': self._draw_downloading,
'EXCEPTION': self._draw_exception, 'EXCEPTION': self._draw_exception,
'PLEASE_SUBSCRIBE': self._draw_subscribe, 'PLEASE_SUBSCRIBE': self._draw_subscribe,
'PLEASE_RENEW': self._draw_renew,
} }
if self._state in drawers: if self._state in drawers:
@ -727,6 +732,11 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
'Click to subscribe to the Blender Cloud', 'Click to subscribe to the Blender Cloud',
(0.0, 0.0, 0.2, 0.6)) (0.0, 0.0, 0.2, 0.6))
def _draw_renew(self, context):
self._draw_text_on_colour(context,
'Click to renew your Blender Cloud subscription',
(0.0, 0.0, 0.2, 0.6))
def get_clicked(self) -> MenuItem: def get_clicked(self) -> MenuItem:
for item in self.current_display_content: for item in self.current_display_content:
@ -807,11 +817,11 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
future=signalling_future)) future=signalling_future))
self.async_task.add_done_callback(texture_download_completed) self.async_task.add_done_callback(texture_download_completed)
def open_browser_subscribe(self): def open_browser_subscribe(self, *, renew: bool):
import webbrowser import webbrowser
webbrowser.open_new_tab('https://cloud.blender.org/join') url = 'renew' if renew else 'join'
webbrowser.open_new_tab('https://cloud.blender.org/%s' % url)
self.report({'INFO'}, 'We just started a browser for you.') self.report({'INFO'}, 'We just started a browser for you.')
def _scroll_smooth(self): def _scroll_smooth(self):
@ -866,9 +876,8 @@ class PILLAR_OT_switch_hdri(pillar.PillarOperatorMixin,
try: try:
db_user = 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'] user_id = db_user['_id']
except pillar.NotSubscribedToCloudError: except pillar.NotSubscribedToCloudError as ex:
self.log.exception('User not subscribed to cloud.') self._log_subscription_needed(can_renew=ex.can_renew)
self.report({'ERROR'}, 'Please subscribe to the Blender Cloud.')
self._state = 'QUIT' self._state = 'QUIT'
return return
except pillar.UserNotLoggedInError: except pillar.UserNotLoggedInError: