Projet

Général

Profil

0001-wcs-use-api-users-uuid-endpoints-for-user-data-28733.patch

Frédéric Péters, 07 décembre 2018 14:34

Télécharger (3,92 ko)

Voir les différences:

Subject: [PATCH] wcs: use /api/users/<uuid>/* endpoints for user data (#28733)

 combo/apps/wcs/models.py | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)
combo/apps/wcs/models.py
187 187
class WcsBlurpMixin(object):
188 188
    is_enabled = classmethod(is_wcs_enabled)
189 189
    cache_duration = 5
190
    api_url = None
191

  
192
    def get_api_url(self, context):
193
        return self.api_url
190 194

  
191 195
    def get_data(self, context):
192 196
        if context.get('placeholder_search_mode'):
......
211 215
            wcs_site['slug'] = wcs_slug
212 216

  
213 217
            response = requests.get(
214
                    self.api_url,
218
                    self.get_api_url(context),
215 219
                    remote_service=wcs_site,
216
                    user=self.get_concerned_user(context),
220
                    user=getattr(context.get('request'), 'user', None),
217 221
                    cache_duration=self.cache_duration,
218 222
                    raise_if_not_cached=not(context.get('synchronous')),
219 223
                    log_errors=False)
......
293 297

  
294 298
@register_cell_class
295 299
class WcsCurrentFormsCell(WcsUserDataBaseCell):
296
    api_url = '/api/user/forms'
297 300
    variable_name = 'user_forms'
298 301

  
299 302
    categories = JSONField(_('Categories'), blank=True)
......
307 310
        from .forms import WcsCurrentFormsCellForm
308 311
        return WcsCurrentFormsCellForm
309 312

  
313
    def get_api_url(self, context):
314
        user = self.get_concerned_user(context)
315
        if hasattr(user, 'saml_identifiers') and user.saml_identifiers.exists():
316
            return '/api/users/%s/forms' % user.saml_identifiers.first().name_id
317
        return '/api/user/forms'
318

  
310 319
    @property
311 320
    def template_name(self):
312 321
        if self.current_forms and self.done_forms:
......
368 377

  
369 378
@register_cell_class
370 379
class WcsCurrentDraftsCell(WcsUserDataBaseCell):
371
    api_url = '/api/user/drafts'
372 380
    variable_name = 'current_drafts'
373 381
    template_name = 'combo/wcs/current_drafts.html'
374 382

  
375 383
    class Meta:
376 384
        verbose_name = _('Current Drafts')
377 385

  
386
    def get_api_url(self, context):
387
        user = self.get_concerned_user(context)
388
        if hasattr(user, 'saml_identifiers') and user.saml_identifiers.exists():
389
            return '/api/users/%s/drafts' % user.saml_identifiers.first().name_id
390
        return '/api/user/drafts'
391

  
378 392
    def get_cell_extra_context(self, context):
379 393
        context = super(WcsCurrentDraftsCell, self).get_cell_extra_context(context)
380 394

  
......
417 431
    def wcs_site(self):
418 432
        return self.category_reference.split(':')[0]
419 433

  
420
    @property
421
    def api_url(self):
434
    def get_api_url(self, context):
422 435
        api_url = '/api/categories/%s/formdefs/' % self.category_reference.split(':')[1]
423 436
        if self.ordering == 'popularity':
424 437
            api_url += '?include-count=on'
......
528 541
    class Meta:
529 542
        verbose_name = _('Backoffice Submission')
530 543

  
531
    def get_concerned_user(self, context):
532
        # always return connected user; the selected user will be used in the
533
        # query string when creating a new formdata.
534
        return getattr(context.get('request'), 'user', None)
535

  
536 544
    def get_cell_extra_context(self, context):
537 545
        context = super(BackofficeSubmissionCell, self).get_cell_extra_context(context)
538 546
        # add a fake category where it's missing
539
-