Fixes scope menu issue in #884 (#888)

Adds proper inheritance of object to ScopeMenuOption and ScopeSelectionMenu which fixes the issue of property setters not being called.
Also initialize all private members during __init__
This commit is contained in:
ejochman
2019-04-15 12:17:47 -07:00
committed by Jay Lee
parent 9930209980
commit fe7c72beac

View File

@@ -12686,7 +12686,7 @@ def getScopesFromUser(menu_options=None):
return menu.get_selected_scopes() return menu.get_selected_scopes()
class ScopeMenuOption(): class ScopeMenuOption(object):
"""A single GAM API/feature with scopes that can be turned on/off.""" """A single GAM API/feature with scopes that can be turned on/off."""
def __init__(self, oauth_scopes, description, def __init__(self, oauth_scopes, description,
@@ -12717,6 +12717,9 @@ class ScopeMenuOption():
restriction: String, the currently enabled restriction on all scopes in restriction: String, the currently enabled restriction on all scopes in
this ScopeMenuOption. Default is no restrictions (highest permission). this ScopeMenuOption. Default is no restrictions (highest permission).
""" """
# Initialize private members
self._is_selected = False
self._restriction = None
self.scopes = oauth_scopes self.scopes = oauth_scopes
self.description = description self.description = description
@@ -12725,7 +12728,8 @@ class ScopeMenuOption():
self.is_selected = is_required or is_selected self.is_selected = is_required or is_selected
self.supported_restrictions = ( self.supported_restrictions = (
supported_restrictions if supported_restrictions is not None else []) supported_restrictions if supported_restrictions is not None else [])
self._restriction = restriction if restriction:
self.restrict_to(restriction)
def select(self, restriction=None): def select(self, restriction=None):
"""Selects/enables the ScopeMenuOption with an optional restriction.""" """Selects/enables the ScopeMenuOption with an optional restriction."""
@@ -12790,7 +12794,7 @@ class ScopeMenuOption():
error = 'Scope does not support a %s restriction.' % restriction error = 'Scope does not support a %s restriction.' % restriction
if self.supported_restrictions is not None: if self.supported_restrictions is not None:
restriction_list = ', '.join(self.supported_restrictions) restriction_list = ', '.join(self.supported_restrictions)
error.append(' Supported restrictions are: %s' % restriction_list) error = error + (' Supported restrictions are: %s' % restriction_list)
raise ValueError(error) raise ValueError(error)
def unrestrict(self): def unrestrict(self):
@@ -12850,7 +12854,7 @@ class ScopeMenuOption():
supported_restrictions=scope_definition.get('subscopes', []), supported_restrictions=scope_definition.get('subscopes', []),
is_required=scope_definition.get('required', False)) is_required=scope_definition.get('required', False))
class ScopeSelectionMenu(): class ScopeSelectionMenu(object):
"""A text menu which prompts the user to select the scopes to authorize.""" """A text menu which prompts the user to select the scopes to authorize."""
class MenuChoiceError(Exception): class MenuChoiceError(Exception):
@@ -13122,7 +13126,6 @@ Append an 'r' to grant read-only access or an 'a' to grant action-only access.
if selected is None: if selected is None:
# Toggle the option on/off # Toggle the option on/off
option.is_selected = not option.is_selected option.is_selected = not option.is_selected
option.unrestrict()
else: else:
option.is_selected = selected option.is_selected = selected
else: else: