0001-general-make-formdatas-visible-even-if-related-formd.patch
tests/test_api.py | ||
---|---|---|
965 | 965 |
assert resp.json[0]['fields']['foobar'] == 'foo@localhost' |
966 | 966 |
assert resp.json[0]['keywords'] == ['hello', 'world'] |
967 | 967 | |
968 |
formdef.disabled = True |
|
969 |
formdef.store() |
|
970 |
resp = get_app(pub).get(sign_uri('/api/user/forms', user=local_user)) |
|
971 |
assert len(resp.json) == 1 |
|
972 | ||
968 | 973 |
def test_user_drafts(pub, local_user): |
969 | 974 |
FormDef.wipe() |
970 | 975 |
formdef = FormDef() |
... | ... | |
1002 | 1007 |
assert 'file' not in resp.json[0]['fields'] # no file export in full lists |
1003 | 1008 |
assert resp.json[0]['keywords'] == ['hello', 'world'] |
1004 | 1009 | |
1010 |
formdef.disabled = True |
|
1011 |
formdef.store() |
|
1012 |
resp = get_app(pub).get(sign_uri('/api/user/drafts', user=local_user)) |
|
1013 |
assert len(resp.json) == 0 |
|
1014 | ||
1005 | 1015 |
def test_api_list_formdata(pub, local_user): |
1006 | 1016 |
Role.wipe() |
1007 | 1017 |
role = Role(name='test') |
tests/test_form_pages.py | ||
---|---|---|
114 | 114 |
assert 'category-misc' in home.body |
115 | 115 |
assert '<a class="" href="test/">test</a>' in home.body |
116 | 116 | |
117 |
def test_home_with_user_forms(pub): |
|
118 |
user = create_user(pub) |
|
119 |
formdef = create_formdef() |
|
120 |
formdef.category_id = '1' |
|
121 |
wf = Workflow(name='status') |
|
122 |
st1 = wf.add_status('Status1', 'st1') |
|
123 |
wf.store() |
|
124 |
formdef.workflow_id = wf.id |
|
125 |
formdef.store() |
|
126 | ||
127 |
formdef.data_class().wipe() |
|
128 |
formdata = formdef.data_class()() |
|
129 |
formdata.user_id = user.id |
|
130 |
formdata.status = 'wf-st1' |
|
131 |
formdata.data = {} |
|
132 |
formdata.store() |
|
133 |
draft = formdef.data_class()() |
|
134 |
draft.user_id = user.id |
|
135 |
draft.status = 'draft' |
|
136 |
draft.data = {} |
|
137 |
draft.store() |
|
138 | ||
139 |
app = login(get_app(pub), username='foo', password='foo') |
|
140 |
resp = app.get('/') |
|
141 |
assert 'Status1' in resp |
|
142 |
assert '<a href="test/%s/"' % formdata.id in resp |
|
143 |
assert 'Draft' in resp |
|
144 |
assert '<a href="test/%s"' % draft.id in resp |
|
145 |
resp = app.get('/test/%s' % formdata.id) |
|
146 |
resp.status_int = 200 |
|
147 |
resp = app.get('/test/%s' % draft.id, status=302) |
|
148 |
resp = resp.follow(status=200) |
|
149 | ||
150 |
# disable formdef: formdatas are still visible and accessible, drafts are not |
|
151 |
formdef.disabled = True |
|
152 |
formdef.store() |
|
153 |
resp = app.get('/') |
|
154 |
assert 'Status1' in resp |
|
155 |
assert '<a href="test/%s/"' % formdata.id in resp |
|
156 |
assert not 'Draft' in resp |
|
157 |
assert not '<a href="test/%s"' % draft.id in resp |
|
158 |
resp = app.get('/test/%s' % formdata.id) |
|
159 |
resp.status_int = 200 |
|
160 |
resp = app.get('/test/%s' % draft.id, status=302) |
|
161 |
resp = resp.follow(status=403) |
|
162 | ||
117 | 163 |
def test_home_category(pub): |
118 | 164 |
formdef = create_formdef() |
119 | 165 |
formdef.category_id = '1' |
wcs/api.py | ||
---|---|---|
417 | 417 |
return json.dumps(user_info) |
418 | 418 | |
419 | 419 |
def get_user_forms(self, user): |
420 |
formdefs = FormDef.select(lambda x: not x.is_disabled())
|
|
420 |
formdefs = FormDef.select() |
|
421 | 421 |
user_forms = [] |
422 | 422 |
for formdef in formdefs: |
423 | 423 |
user_forms.extend(formdef.data_class().get_with_indexed_value( |
... | ... | |
439 | 439 |
for form in self.get_user_forms(user): |
440 | 440 |
if not form.is_draft(): |
441 | 441 |
continue |
442 |
if form.formdef.is_disabled(): |
|
443 |
continue |
|
442 | 444 |
title = _('%(name)s, draft saved on %(datetime)s') % { |
443 | 445 |
'name': form.formdef.name, |
444 | 446 |
'datetime': misc.localstrftime(form.receipt_time) |
wcs/forms/root.py | ||
---|---|---|
1218 | 1218 |
r += htmltext('</div>') |
1219 | 1219 | |
1220 | 1220 |
if self.category: |
1221 |
formdefs = FormDef.select( |
|
1221 |
all_formdefs = FormDef.select(
|
|
1222 | 1222 |
lambda x: str(x.category_id) == str(self.category.id), |
1223 | 1223 |
order_by='name', ignore_errors=True) |
1224 | 1224 |
else: |
1225 |
formdefs = FormDef.select(order_by='name', ignore_errors=True) |
|
1225 |
all_formdefs = FormDef.select(order_by='name', ignore_errors=True)
|
|
1226 | 1226 | |
1227 |
formdefs = [x for x in formdefs if (not x.is_disabled() or x.disabled_redirection)] |
|
1227 |
formdefs = [x for x in all_formdefs if (not x.is_disabled() or x.disabled_redirection)]
|
|
1228 | 1228 | |
1229 | 1229 |
if not self.category and any((x for x in formdefs if x.enable_tracking_codes)): |
1230 | 1230 |
r += htmltext('<div id="side">') |
... | ... | |
1245 | 1245 | |
1246 | 1246 |
user_forms = [] |
1247 | 1247 |
if user: |
1248 |
for formdef in list_forms: |
|
1249 |
if not formdef.is_disabled(): |
|
1250 |
user_forms.extend(get_user_forms(formdef)) |
|
1251 |
user_forms = [x for x in user_forms if x.formdef.is_user_allowed_read(user, x)] |
|
1248 |
for formdef in all_formdefs: |
|
1249 |
user_forms.extend(get_user_forms(formdef)) |
|
1250 |
user_forms = [x for x in user_forms if x.formdef.is_user_allowed_read(user, x)] |
|
1252 | 1251 |
user_forms.sort(lambda x,y: cmp(x.receipt_time, y.receipt_time)) |
1253 | 1252 | |
1254 | 1253 |
if self.category: |
... | ... | |
1305 | 1304 | |
1306 | 1305 |
def user_forms(self, user_forms): |
1307 | 1306 |
r = TemplateIO(html=True) |
1308 |
draft = [x for x in user_forms if x.is_draft()] |
|
1307 |
draft = [x for x in user_forms if x.is_draft() and not x.formdef.is_disabled()]
|
|
1309 | 1308 |
if draft: |
1310 | 1309 |
r += htmltext('<h2 id="drafts">%s</h2>') % _('Your Current Drafts') |
1311 | 1310 |
r += htmltext('<ul>') |
1312 |
- |