Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
296602ea52fc
Commit
35342ebf
authored
Feb 09, 2021
by
Élodie Thiéblin
Browse files
feat(urlpublish): add empty_rset_raises_404 flag on rql rewrite urls
parent
f104b7b55d13
Changes
2
Hide whitespace changes
Inline
Side-by-side
cubicweb/web/test/unittest_application.py
View file @
296602ea
...
...
@@ -30,6 +30,7 @@ from cubicweb.devtools.fake import FakeRequest
from
cubicweb.web
import
LogOut
,
Redirect
,
INTERNAL_FIELD_VALUE
from
cubicweb.web.views.basecontrollers
import
ViewController
from
cubicweb.web.application
import
anonymized_request
from
cubicweb.web.views.urlrewrite
import
SimpleReqRewriter
,
rgx
class
FakeMapping
:
...
...
@@ -760,18 +761,37 @@ class ApplicationTC(CubicWebTC):
def
test_notfound_raised_on_empty_underlying_rset
(
self
):
"""tests URLs that are rewritten with an underlying rqlquery.
If the rql query is empty, a NotFound error should be raised."""
If the rql query is empty and the flag empty_rset_raises_404 is True,
a NotFound error should be raised."""
oldrules
=
SimpleReqRewriter
.
rules
with
self
.
new_access
(
'anon'
).
web_request
(
'schema/CWUser'
)
as
req
:
SimpleReqRewriter
.
rules
=
[(
rgx
(
r
'/mycwetypeurl/([^/]+)'
),
dict
(
vid
=
'primary'
,
rql
=
r
'Any T WHERE T is CWEType, T name "\1"'
,
empty_rset_raises_404
=
True
),)]
with
self
.
new_access
(
'anon'
).
web_request
(
'mycwetypeurl/CWUser'
)
as
req
:
self
.
app_handle_request
(
req
)
self
.
assertEqual
(
req
.
status_out
,
200
)
# There is an underlying rql to fetch the schema of cwetype.
# As there is no entity «pouet», it should raise NotFound.
with
self
.
new_access
(
'anon'
).
web_request
(
'schema/pouet'
)
as
req
:
with
self
.
new_access
(
'anon'
).
web_request
(
'mycwetypeurl/pouet'
)
as
req
:
self
.
app_handle_request
(
req
)
self
.
assertEqual
(
req
.
status_out
,
404
)
SimpleReqRewriter
.
rules
=
[(
rgx
(
r
'/mycwetypeurl/([^/]+)'
),
dict
(
vid
=
'primary'
,
rql
=
r
'Any T WHERE T is CWEType, T name "\1"'
),)]
with
self
.
new_access
(
'anon'
).
web_request
(
'mycwetypeurl/CWUser'
)
as
req
:
self
.
app_handle_request
(
req
)
self
.
assertEqual
(
req
.
status_out
,
200
)
with
self
.
new_access
(
'anon'
).
web_request
(
'mycwetypeurl/pouet'
)
as
req
:
self
.
app_handle_request
(
req
)
self
.
assertEqual
(
req
.
status_out
,
200
)
SimpleReqRewriter
.
rules
=
oldrules
if
__name__
==
'__main__'
:
unittest_main
()
cubicweb/web/views/basecontrollers.py
View file @
296602ea
...
...
@@ -89,7 +89,11 @@ class ViewController(Controller):
:raise NotFound: if the rql has been rewritten (rewrite rules) and the
resulting rset is empty"""
view
,
rset
=
self
.
_select_view_and_rset
(
rset
)
if
not
rset
and
getattr
(
self
.
_cw
,
'_rql_rewritten'
,
False
):
if
(
not
rset
and
getattr
(
self
.
_cw
,
'_rql_rewritten'
,
False
)
and
self
.
_cw
.
form
.
get
(
"empty_rset_raises_404"
,
False
)
):
raise
NotFound
view
.
set_http_cache_headers
()
if
self
.
_cw
.
is_client_cache_valid
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment