cards: add user support (#48392)

This commit is contained in:
Lauréline Guérin 2020-11-16 15:21:23 +01:00
parent b284cca5d3
commit ab5226d12b
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
6 changed files with 73 additions and 3 deletions

View File

@ -278,6 +278,27 @@ def test_card_category(pub, studio):
assert '<span class="label">Category</span> <span class="value">Bar</span>' in resp.text
def test_card_user_support(pub, studio):
create_superuser(pub)
CardDef.wipe()
carddef = CardDef()
carddef.name = 'card title'
carddef.fields = []
carddef.store()
app = login(get_app(pub))
resp = app.get('/backoffice/cards/1/')
assert '<span class="label">User support</span> <span class="value">No</span>' in resp.text
resp = resp.click(href='user_support')
resp.forms[0]['user_support'] = 'optional'
resp.forms[0].submit('submit')
assert CardDef.get(carddef.id).user_support == 'optional'
resp = app.get('/backoffice/cards/1/')
assert '<span class="label">User support</span> <span class="value">Optional</span>' in resp.text
def test_card_custom_view_data_source(pub, studio):
user = create_superuser(pub)
Role.wipe()

View File

@ -169,6 +169,35 @@ def test_carddata_management_categories(pub, studio):
assert '<h3>Bar</h3>' in resp.text
def test_carddata_management_user_support(pub, studio):
user = create_user(pub)
CardDef.wipe()
carddef = CardDef()
carddef.name = 'foo'
carddef.fields = []
carddef.backoffice_submission_roles = user.roles
carddef.workflow_roles = {'_editor': user.roles[0]}
carddef.store()
app = login(get_app(pub))
resp = app.get('/backoffice/data/foo/add/')
assert 'Associated User' not in resp.text
assert 'user_id' not in resp.form.fields
carddef.user_support = 'foobar'
carddef.store()
resp = app.get('/backoffice/data/foo/add/')
assert 'Associated User' not in resp.text
assert 'user_id' not in resp.form.fields
carddef.user_support = 'optional'
carddef.store()
resp = app.get('/backoffice/data/foo/add/')
assert 'Associated User' in resp.text
assert 'user_id' in resp.form.fields
def test_studio_card_item_link(pub, studio):
user = create_user(pub)
CardDef.wipe()

View File

@ -171,7 +171,7 @@ class OptionsDirectory(Directory):
_q_exports = ['confirmation', 'only_allow_one',
'always_advertise', 'tracking_code', 'online_status', 'captcha',
'description', 'keywords', 'category', 'management',
'geolocations', 'appearance', 'templates']
'geolocations', 'appearance', 'templates', 'user_support']
def __init__(self, formdef):
self.formdef = formdef
@ -310,6 +310,15 @@ class OptionsDirectory(Directory):
_('Existing forms will be updated in the background.'))
return result
def user_support(self):
form = Form(enctype='multipart/form-data')
form.add(
SingleSelectWidget, 'user_support', title=_('User support'),
value=self.formdef.user_support,
options=[(None, C_('user_support|No'), ''), ('optional', C_('user_support|Optional'), 'optional')]
)
return self.handle(form, _('User support'))
def handle(self, form, title):
if not self.formdef.is_readonly():
form.add_submit('submit', _('Submit'))
@ -325,7 +334,7 @@ class OptionsDirectory(Directory):
'description', 'keywords', 'category_id',
'skip_from_360_view', 'geoloc_label', 'appearance_keywords',
'include_download_all_button',
'digest_template', 'drafts_lifespan']
'digest_template', 'drafts_lifespan', 'user_support']
for attr in attrs:
widget = form.get_widget(attr)
if widget:

View File

@ -171,6 +171,11 @@ class CardDefPage(FormDefPage):
digest_template_status = C_('template|None')
r += add_option_line('options/templates',
_('Digest Template'), digest_template_status)
if self.formdef.user_support == 'optional':
user_support_status = C_('user_support|Optional')
else:
user_support_status = C_('user_support|No')
r += add_option_line('options/user_support', _('User support'), user_support_status)
r += htmltext('</ul>')
r += htmltext('</div>')

View File

@ -316,6 +316,11 @@ class CardFillPage(FormFillPage):
has_channel_support = False
has_user_support = False
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.formdef.user_support == 'optional':
self.has_user_support = True
def submitted(self, form, *args):
super(CardFillPage, self).submitted(form, *args)
if get_response().get_header('location').endswith('/backoffice/submission/'):

View File

@ -118,6 +118,7 @@ class FormDef(StorableObject):
appearance_keywords = None
digest_template = None
drafts_lifespan = None
user_support = None
geolocations = None
@ -136,7 +137,7 @@ class FormDef(StorableObject):
TEXT_ATTRIBUTES = ['name', 'url_name', 'description', 'keywords',
'publication_date', 'expiration_date', 'internal_identifier',
'disabled_redirection', 'appearance_keywords',
'digest_template', 'drafts_lifespan']
'digest_template', 'drafts_lifespan', 'user_support']
BOOLEAN_ATTRIBUTES = ['discussion', 'detailed_emails', 'disabled',
'only_allow_one', 'enable_tracking_codes', 'confirmation',
'always_advertise', 'include_download_all_button',