wcs: use /api/users/<uuid>/* endpoints for user data (#28733)
This commit is contained in:
parent
51cb703350
commit
7c944f8382
|
@ -187,6 +187,10 @@ class WcsCategoryCell(WcsCommonCategoryCell):
|
|||
class WcsBlurpMixin(object):
|
||||
is_enabled = classmethod(is_wcs_enabled)
|
||||
cache_duration = 5
|
||||
api_url = None
|
||||
|
||||
def get_api_url(self, context):
|
||||
return self.api_url
|
||||
|
||||
def get_data(self, context):
|
||||
if context.get('placeholder_search_mode'):
|
||||
|
@ -211,9 +215,9 @@ class WcsBlurpMixin(object):
|
|||
wcs_site['slug'] = wcs_slug
|
||||
|
||||
response = requests.get(
|
||||
self.api_url,
|
||||
self.get_api_url(context),
|
||||
remote_service=wcs_site,
|
||||
user=self.get_concerned_user(context),
|
||||
user=getattr(context.get('request'), 'user', None),
|
||||
cache_duration=self.cache_duration,
|
||||
raise_if_not_cached=not(context.get('synchronous')),
|
||||
log_errors=False)
|
||||
|
@ -293,7 +297,6 @@ class WcsUserDataBaseCell(WcsDataBaseCell):
|
|||
|
||||
@register_cell_class
|
||||
class WcsCurrentFormsCell(WcsUserDataBaseCell):
|
||||
api_url = '/api/user/forms'
|
||||
variable_name = 'user_forms'
|
||||
|
||||
categories = JSONField(_('Categories'), blank=True)
|
||||
|
@ -307,6 +310,12 @@ class WcsCurrentFormsCell(WcsUserDataBaseCell):
|
|||
from .forms import WcsCurrentFormsCellForm
|
||||
return WcsCurrentFormsCellForm
|
||||
|
||||
def get_api_url(self, context):
|
||||
user = self.get_concerned_user(context)
|
||||
if hasattr(user, 'saml_identifiers') and user.saml_identifiers.exists():
|
||||
return '/api/users/%s/forms' % user.saml_identifiers.first().name_id
|
||||
return '/api/user/forms'
|
||||
|
||||
@property
|
||||
def template_name(self):
|
||||
if self.current_forms and self.done_forms:
|
||||
|
@ -368,13 +377,18 @@ class WcsCurrentFormsCell(WcsUserDataBaseCell):
|
|||
|
||||
@register_cell_class
|
||||
class WcsCurrentDraftsCell(WcsUserDataBaseCell):
|
||||
api_url = '/api/user/drafts'
|
||||
variable_name = 'current_drafts'
|
||||
template_name = 'combo/wcs/current_drafts.html'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Current Drafts')
|
||||
|
||||
def get_api_url(self, context):
|
||||
user = self.get_concerned_user(context)
|
||||
if hasattr(user, 'saml_identifiers') and user.saml_identifiers.exists():
|
||||
return '/api/users/%s/drafts' % user.saml_identifiers.first().name_id
|
||||
return '/api/user/drafts'
|
||||
|
||||
def get_cell_extra_context(self, context):
|
||||
context = super(WcsCurrentDraftsCell, self).get_cell_extra_context(context)
|
||||
|
||||
|
@ -417,8 +431,7 @@ class WcsFormsOfCategoryCell(WcsCommonCategoryCell, WcsBlurpMixin):
|
|||
def wcs_site(self):
|
||||
return self.category_reference.split(':')[0]
|
||||
|
||||
@property
|
||||
def api_url(self):
|
||||
def get_api_url(self, context):
|
||||
api_url = '/api/categories/%s/formdefs/' % self.category_reference.split(':')[1]
|
||||
if self.ordering == 'popularity':
|
||||
api_url += '?include-count=on'
|
||||
|
@ -528,11 +541,6 @@ class BackofficeSubmissionCell(WcsDataBaseCell):
|
|||
class Meta:
|
||||
verbose_name = _('Backoffice Submission')
|
||||
|
||||
def get_concerned_user(self, context):
|
||||
# always return connected user; the selected user will be used in the
|
||||
# query string when creating a new formdata.
|
||||
return getattr(context.get('request'), 'user', None)
|
||||
|
||||
def get_cell_extra_context(self, context):
|
||||
context = super(BackofficeSubmissionCell, self).get_cell_extra_context(context)
|
||||
# add a fake category where it's missing
|
||||
|
|
Loading…
Reference in New Issue