Projet

Général

Profil

0001-misc-look-for-portal-agent-associated-to-user-OU-whe.patch

Frédéric Péters, 11 janvier 2019 11:35

Télécharger (5,16 ko)

Voir les différences:

Subject: [PATCH] misc: look for portal agent associated to user OU when in
 Authentic (#29658)

 debian/debian_config_common.py                |  2 ++
 .../hobo/management/commands/hobo_deploy.py   |  1 +
 hobo/context_processors.py                    | 19 +++++++++++++++++++
 hobo/multitenant/settings_loaders.py          |  6 ++----
 4 files changed, 24 insertions(+), 4 deletions(-)
debian/debian_config_common.py
207 207
    TEMPLATE_CONTEXT_PROCESSORS = (
208 208
            'hobo.context_processors.template_vars',
209 209
            'hobo.context_processors.theme_base',
210
            'hobo.context_processors.portal_agent_url',
210 211
            ) + TEMPLATE_CONTEXT_PROCESSORS
211 212
else:
212 213
    assert len(TEMPLATES)
......
228 229
    TEMPLATES[0]['OPTIONS']['context_processors'] = [
229 230
            'hobo.context_processors.template_vars',
230 231
            'hobo.context_processors.theme_base',
232
            'hobo.context_processors.portal_agent_url',
231 233
            ] + TEMPLATES[0]['OPTIONS']['context_processors']
232 234

  
233 235
# needed by hobo.context_processors.theme_base:
hobo/agent/hobo/management/commands/hobo_deploy.py
61 61
                                  'secret_key': service_dict.get('secret_key')})
62 62
                service.title = service_dict['title']
63 63
                service.secret_key = service_dict.get('secret_key')
64
                service.template_name = service_dict.get('template_name') or ''
64 65
                service.slug = service_slug
65 66
                service.use_as_idp_for_self = True
66 67
                service.last_operational_check_timestamp = now()
hobo/context_processors.py
143 143
            'theme_base_filename': template_vars(request).get('theme_base_filename') or 'theme.html'
144 144
           }
145 145

  
146

  
147
def portal_agent_url(request):
148
    def get_portal_agent_url():
149
        portal_agents = []
150
        if 'authentic2' in settings.INSTALLED_APPS:
151
            portal_agents = [x for x in settings.KNOWN_SERVICES.get('combo', {}).values()
152
                             if x.get('is-portal-agent')]
153
        if len(portal_agents) > 1 and request.user and request.user.is_authenticated() and request.user.ou_id:
154
            ou_slug = request.user.ou.slug
155
            for portal_agent in portal_agents:
156
                variables = portal_agent.get('variables') or {}
157
                if variables.get('ou-slug') == ou_slug:
158
                    return portal_agent['url']
159
        variables = getattr(settings, 'TEMPLATE_VARS', {})
160
        return variables.get(settings.HOBO_MANAGER_HOMEPAGE_URL_VAR)
161

  
162
    return {'manager_homepage_url': get_portal_agent_url}
163

  
164

  
146 165
def hobo_json(request):
147 166
    from hobo.multitenant.settings_loaders import TemplateVars
148 167
    from hobo.deploy.utils import get_hobo_json
hobo/multitenant/settings_loaders.py
89 89
                'verif_orig': verif_orig,
90 90
                'variables': service.get('variables'),
91 91
                'secondary': service.get('secondary'),
92
                'template_name': service.get('template_name'),
92 93
            }
93 94

  
94 95
            if service.get('secondary') and (service.get('variables') and
......
129 130
                continue
130 131
            variables['%s_url' % service.get('slug').replace('-','_')] = service.get('base_url')
131 132

  
132
            if service.get('service-id') == 'combo':
133
            if service.get('service-id') == 'combo' and not service.get('secondary'):
133 134
                if service.get('template_name') == 'portal-agent':
134 135
                    variables['portal_agent_url'] = service.get('base_url')
135 136
                    variables['portal_agent_title'] = service.get('title')
......
149 150
            variables.update(service.get('variables') or {})
150 151
            variables['site_title'] = service.get('title')
151 152

  
152
        if getattr(settings, 'HOBO_MANAGER_HOMEPAGE_URL_VAR', None):
153
            variables['manager_homepage_url'] = \
154
                        variables.get(settings.HOBO_MANAGER_HOMEPAGE_URL_VAR)
155 153
        if getattr(settings, 'HOBO_MANAGER_HOMEPAGE_TITLE_VAR', None):
156 154
            variables['manager_homepage_title'] = \
157 155
                        variables.get(settings.HOBO_MANAGER_HOMEPAGE_TITLE_VAR)
158
-