def has_action_permission(self, action, user, model_cls): try: if get_tenant_properties('CLOSED_SITE'): return user and user.is_authenticated() except AttributeError: pass return True
def get_currencies(): properties = get_tenant_properties() currencies = set( itertools.chain(*[ list(method['currencies'].keys()) for method in properties.PAYMENT_METHODS ])) min_amounts = get_min_amounts(properties.PAYMENT_METHODS) currencies = [{ 'code': code, 'name': get_currency_name(code), 'symbol': get_currency_symbol(code).replace('US$', '$') } for code in currencies] for currency in currencies: if currency['code'] in min_amounts: currency['minAmount'] = min_amounts[currency['code']] try: currency['rate'] = get_rate(properties.DEFAULT_CURRENCY, currency['code']) except (MissingRate, ProgrammingError): currency['rate'] = 1 return currencies
def get_currencies(): properties = get_tenant_properties() currencies = set(itertools.chain(*[ method['currencies'].keys() for method in properties.PAYMENT_METHODS ])) min_amounts = get_min_amounts(properties.PAYMENT_METHODS) currencies = [{ 'code': code, 'name': get_currency_name(code), 'symbol': get_currency_symbol(code) } for code in currencies] for currency in currencies: if currency['code'] in min_amounts: currency['minAmount'] = min_amounts[currency['code']] try: currency['rate'] = get_rate(currency['code']) except (CurrencyConversionException, ProgrammingError): currency['rate'] = 1 return currencies
def get_public_properties(request): """ Dynamically populate a tenant context with exposed tenant specific properties from reef/clients/client_name/properties.py. The context processor looks in tenant settings for the uppercased variable names that are defined in "EXPOSED_TENANT_PROPERTIES" to generate the context. Example: EXPOSED_TENANT_PROPERTIES = ['mixpanel', 'analytics'] This adds the value of the keys MIXPANEL and ANALYTICS from the settings file. """ config = {} properties = get_tenant_properties() props = None try: props = getattr(properties, 'EXPOSED_TENANT_PROPERTIES') except AttributeError: pass if not props: try: props = getattr(settings, 'EXPOSED_TENANT_PROPERTIES') except AttributeError: return config # First load tenant settings that should always be exposed if connection.tenant: current_tenant = connection.tenant properties = get_tenant_properties() config = { 'mediaUrl': getattr(properties, 'MEDIA_URL'), 'defaultAvatarUrl': "/images/default-avatar.png", 'currencies': get_currencies(), 'logoUrl': "/images/logo.svg", 'mapsApiKey': getattr(properties, 'MAPS_API_KEY', ''), 'donationsEnabled': getattr(properties, 'DONATIONS_ENABLED', True), 'recurringDonationsEnabled': getattr(properties, 'RECURRING_DONATIONS_ENABLED', False), 'siteName': current_tenant.name, 'languages': [{'code': lang[0], 'name': lang[1]} for lang in getattr(properties, 'LANGUAGES')], 'languageCode': get_language(), 'siteLinks': get_user_site_links(request.user), 'platform': { 'content': get_platform_settings('cms.SitePlatformSettings'), 'projects': get_platform_settings('projects.ProjectPlatformSettings'), 'analytics': get_platform_settings('analytics.AnalyticsPlatformSettings'), 'members': get_platform_settings('members.MemberPlatformSettings'), } } try: config['readOnlyFields'] = { 'user': properties.TOKEN_AUTH.get('assertion_mapping', {}).keys() } except AttributeError: pass else: config = {} # snake_case to CamelCase def _camelize(s): return re.sub('_.', lambda x: x.group()[1].upper(), s) # Now load the tenant specific properties for item in props: try: parts = item.split('.') if len(parts) == 2: # get parent and child details parent = getattr(properties, parts[0].upper()) parent_key = _camelize(parts[0]) child_key = _camelize(parts[1]) # skip if the child property does not exist try: value = parent[parts[1]] except KeyError: continue if parent_key not in config: config[parent_key] = {} config[parent_key][child_key] = value elif len(parts) > 2: logger.info("Depth is too great for exposed property: {}".format(item)) else: # Use camelcase for setting keys (convert from snakecase) key = _camelize(item) config[key] = getattr(properties, item.upper()) except AttributeError: pass return config
def get_public_properties(request): """ Dynamically populate a tenant context with exposed tenant specific properties from reef/clients/client_name/properties.py. The context processor looks in tenant settings for the uppercased variable names that are defined in "EXPOSED_TENANT_PROPERTIES" to generate the context. Example: EXPOSED_TENANT_PROPERTIES = ['mixpanel', 'analytics'] This adds the value of the keys MIXPANEL and ANALYTICS from the settings file. """ config = {} properties = get_tenant_properties() props = None try: props = getattr(properties, 'EXPOSED_TENANT_PROPERTIES') except AttributeError: pass if not props: try: props = getattr(settings, 'EXPOSED_TENANT_PROPERTIES') except AttributeError: return config # First load tenant settings that should always be exposed if connection.tenant: current_tenant = connection.tenant properties = get_tenant_properties() config = { 'mediaUrl': getattr(properties, 'MEDIA_URL'), 'defaultAvatarUrl': "/images/default-avatar.png", 'currencies': get_currencies(), 'logoUrl': "/images/logo.svg", 'mapsApiKey': getattr(properties, 'MAPS_API_KEY', ''), 'donationsEnabled': getattr(properties, 'DONATIONS_ENABLED', True), 'recurringDonationsEnabled': getattr(properties, 'RECURRING_DONATIONS_ENABLED', False), 'siteName': current_tenant.name, 'languages': [{'code': lang[0], 'name': lang[1]} for lang in getattr(properties, 'LANGUAGES')], 'languageCode': get_language() } try: config['readOnlyFields'] = { 'user': properties.TOKEN_AUTH.get('assertion_mapping', {}).keys() } except AttributeError: pass else: config = {} # Now load the tenant specific properties for item in props: try: key = re.sub('_.',lambda x: x.group()[1].upper(), item) # Use camelcase for setting keys (convert from snakecase) config[key] = getattr(properties, item.upper()) except AttributeError: pass return config