combo/combo/apps/family/utils.py

62 lines
2.0 KiB
Python

# combo - content management system
# Copyright (C) 2015-2016 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf import settings
from django.utils.http import urlencode
from combo.utils import requests
def get_passerelle_service():
if hasattr(settings, 'KNOWN_SERVICES') and settings.KNOWN_SERVICES.get('passerelle'):
return list(settings.KNOWN_SERVICES['passerelle'].values())[0]
def is_family_enabled():
return get_passerelle_service() and hasattr(settings, 'FAMILY_SERVICE')
def remote_service(endpoint, **kwargs):
path = settings.FAMILY_SERVICE.get('root') + endpoint
return requests.get(path,
remote_service=get_passerelle_service(),
headers={'accept': 'application/json'},
**kwargs)
def get_family(**kwargs):
endpoint = 'family/'
return remote_service(endpoint, **kwargs)
def link_family(user, family_id, family_code):
endpoint = 'family/link/'
kwargs = {
'user': user,
'invalidate_cache': True,
'params': {
'login': family_id,
'password': family_code,
}
}
return remote_service(endpoint, **kwargs)
def unlink_family(user):
endpoint = 'family/unlink/'
kwargs = {
'user': user,
'invalidate_cache': True
}
return remote_service(endpoint, **kwargs)