Skip to content

Commit

Permalink
refactor: [AXM-475] refactor firebase settings
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedielnitsevIvan committed May 22, 2024
1 parent 90e54b6 commit fa1d91a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
3 changes: 1 addition & 2 deletions openedx/core/djangoapps/ace_common/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def plugin_settings(settings): # lint-amnesty, pylint: disable=missing-function
settings.FCM_APP_NAME = 'fcm-edx-platform'
settings.FIREBASE_CREDENTIALS = None

if not getattr(settings, 'FIREBASE_APP', None) and settings.FIREBASE_CREDENTIALS:
settings.FIREBASE_APP = setup_firebase_app(settings.FIREBASE_CREDENTIALS, settings.FCM_APP_NAME)
settings.FIREBASE_APP = setup_firebase_app(settings.FIREBASE_CREDENTIALS, settings.FCM_APP_NAME)

if getattr(settings, 'FIREBASE_APP', None):
settings.ACE_ENABLED_CHANNELS.append(settings.ACE_CHANNEL_DEFAULT_PUSH)
Expand Down
31 changes: 15 additions & 16 deletions openedx/core/djangoapps/ace_common/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,21 @@ def plugin_settings(settings):
settings.ACE_CHANNEL_TRANSACTIONAL_EMAIL = settings.ENV_TOKENS.get(
'ACE_CHANNEL_TRANSACTIONAL_EMAIL', settings.ACE_CHANNEL_TRANSACTIONAL_EMAIL
)
settings.FCM_APP_NAME = settings.ENV_TOKENS.get('FCM_APP_NAME', 'fcm-edx-platform')
settings.FIREBASE_CREDENTIALS = settings.ENV_TOKENS.get('FIREBASE_CREDENTIALS', {})
settings.FCM_APP_NAME = settings.ENV_TOKENS.get('FCM_APP_NAME', settings.FCM_APP_NAME)
settings.FIREBASE_CREDENTIALS = settings.ENV_TOKENS.get('FIREBASE_CREDENTIALS', settings.FIREBASE_CREDENTIALS)

if not getattr(settings, 'FIREBASE_APP', None) and settings.FIREBASE_CREDENTIALS:
settings.FIREBASE_APP = setup_firebase_app(settings.FIREBASE_CREDENTIALS, settings.FCM_APP_NAME)
if settings.FIREBASE_APP:
settings.ACE_ENABLED_CHANNELS.append(settings.ACE_CHANNEL_DEFAULT_PUSH)
settings.ACE_ENABLED_POLICIES.append(settings.ACE_CHANNEL_DEFAULT_PUSH)
settings.FIREBASE_APP = setup_firebase_app(settings.FIREBASE_CREDENTIALS, settings.FCM_APP_NAME)
if settings.FIREBASE_APP:
settings.ACE_ENABLED_CHANNELS.append(settings.ACE_CHANNEL_DEFAULT_PUSH)
settings.ACE_ENABLED_POLICIES.append(settings.ACE_CHANNEL_DEFAULT_PUSH)

settings.PUSH_NOTIFICATIONS_SETTINGS = {
'CONFIG': 'push_notifications.conf.AppConfig',
'APPLICATIONS': {
settings.FCM_APP_NAME: {
'PLATFORM': 'FCM',
'FIREBASE_APP': settings.FIREBASE_APP,
},
settings.PUSH_NOTIFICATIONS_SETTINGS = {
'CONFIG': 'push_notifications.conf.AppConfig',
'APPLICATIONS': {
settings.FCM_APP_NAME: {
'PLATFORM': 'FCM',
'FIREBASE_APP': settings.FIREBASE_APP,
},
'UPDATE_ON_DUPLICATE_REG_ID': True,
}
},
'UPDATE_ON_DUPLICATE_REG_ID': True,
}
9 changes: 7 additions & 2 deletions openedx/core/djangoapps/ace_common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def setup_firebase_app(firebase_credentials, app_name='fcm-app'):
except ImportError:
log.error('Could not import firebase_admin package.')
return

if firebase_credentials:
certificate = firebase_admin.credentials.Certificate(firebase_credentials)
return firebase_admin.initialize_app(certificate, name=app_name)
try:
app = firebase_admin.get_app(app_name)
except ValueError:
certificate = firebase_admin.credentials.Certificate(firebase_credentials)
app = firebase_admin.initialize_app(certificate, name=app_name)
return app

0 comments on commit fa1d91a

Please sign in to comment.