Skip to content

Commit 74a34e2

Browse files
committed
Added preview for node editing.
Fixed redirection to previous page during authentication workflow. SEO: fixed issue with page having unicode keywords (tags). Fixed caller of {CMS_ENCODERS}.secured_url_content to avoid obsolete implicate conversions to STRING_8. Cosmetic and unused local variables removal.
1 parent e931964 commit 74a34e2

23 files changed

+188
-93
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ EIFGENs
77
.*.swo
88
Thumbs.db
99
*.dll
10+
examples/demo/docker-inc/site/mysql/*

examples/demo/src/demo_cms_server.e

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
note
2-
description: "[
3-
DEMO application server.
4-
]"
1+
note
2+
description: "DEMO application server."
53
date: "$Date$"
64
revision: "$Revision$"
75

modules/admin/handler/cms_admin_info_handler.e

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
note
1+
note
22
description: "Display information about ROC CMS installation."
33
date: "$Date$"
44
revision: "$Revision$"
@@ -8,7 +8,6 @@ class
88

99
inherit
1010
CMS_HANDLER
11-
1211
WSF_URI_HANDLER
1312

1413
create
@@ -40,8 +39,6 @@ feature -- Execution
4039
end
4140

4241
append_system_info_to (s: STRING)
43-
local
44-
n: INTEGER
4542
do
4643
s.append ("<ul>")
4744
across

modules/auth/cms_auth_module_i.e

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ feature {NONE} -- Template
103103

104104
smarty_template_login_block (a_request: WSF_REQUEST; a_module: CMS_MODULE; a_block_id: READABLE_STRING_8; a_cms_api: CMS_API): like smarty_template_block
105105
local
106-
l_destination: detachable READABLE_STRING_32
106+
l_destination: detachable READABLE_STRING_GENERAL
107107
do
108108
Result := smarty_template_block (a_module, a_block_id, a_cms_api)
109109
if Result /= Void then
@@ -112,8 +112,12 @@ feature {NONE} -- Template
112112
elseif attached {WSF_STRING} a_request.form_parameter ("destination") as p_destination then
113113
l_destination := p_destination.value
114114
end
115-
if l_destination /= Void then
116-
Result.set_value (secured_url_content (l_destination), "site_destination")
115+
if
116+
l_destination /= Void and then
117+
not l_destination.is_whitespace and then
118+
l_destination.is_valid_as_string_8
119+
then
120+
Result.set_value (secured_url_content (l_destination.to_string_8), "site_destination")
117121
end
118122
end
119123
end

modules/auth/cms_authentication_module.e

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ feature -- Hooks configuration
167167
l_url_name: READABLE_STRING_GENERAL
168168
do
169169
if attached {WSF_STRING} a_response.request.item ("destination") as p_destination then
170-
l_destination := secured_url_content (p_destination.value)
170+
l_destination := secured_url_content (p_destination.url_encoded_value)
171171
else
172172
l_destination := a_response.location
173173
end
@@ -391,8 +391,12 @@ feature -- Handler
391391
elseif attached a_auth_api.cms_api.module_by_name ("session_auth") then
392392
-- FIXME: find better solution to support a default login system.
393393
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, a_auth_api.cms_api)
394-
if attached {WSF_STRING} req.item ("destination") as l_destination then
395-
r.set_redirection ("account/auth/roc-session-login?destination=" + secured_url_content (l_destination.url_encoded_value))
394+
if
395+
attached {WSF_STRING} req.item ("destination") as l_destination and then
396+
attached l_destination.value as v and then
397+
v.is_valid_as_string_8
398+
then
399+
r.set_redirection ("account/auth/roc-session-login?destination=" + secured_url_content (v.to_string_8))
396400
else
397401
r.set_redirection ("account/auth/roc-session-login")
398402
end
@@ -402,8 +406,13 @@ feature -- Handler
402406
elseif attached a_auth_api.cms_api.module_by_name ("basic_auth") then
403407
-- FIXME: find better solution to support a default login system.
404408
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, a_auth_api.cms_api)
405-
if attached {WSF_STRING} req.item ("destination") as l_destination then
406-
r.set_redirection ("account/auth/roc-basic-login?destination=" + secured_url_content (l_destination.url_encoded_value))
409+
410+
if
411+
attached {WSF_STRING} req.item ("destination") as l_destination and then
412+
attached l_destination.value as v and then
413+
v.is_valid_as_string_8
414+
then
415+
r.set_redirection ("account/auth/roc-basic-login?destination=" + secured_url_content (v.to_string_8))
407416
else
408417
r.set_redirection ("account/auth/roc-basic-login")
409418
end
@@ -441,10 +450,6 @@ feature -- Handler
441450
l_user_api: CMS_USER_API
442451
u: CMS_TEMP_USER
443452
l_exist: BOOLEAN
444-
es: CMS_AUTHENTICATION_EMAIL_SERVICE
445-
l_url_activate: STRING
446-
l_url_reject: STRING
447-
l_token: STRING
448453
l_captcha_passed: BOOLEAN
449454
l_email: READABLE_STRING_8
450455
do

modules/auth/cms_user_register_webapi_handler.e

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ feature -- Execution
4343
l_user_api: CMS_USER_API
4444
u: CMS_TEMP_USER
4545
l_exist: BOOLEAN
46-
47-
l_url_activate: STRING
48-
l_url_reject: STRING
49-
l_token: STRING
50-
l_captcha_passed: BOOLEAN
5146
l_email: READABLE_STRING_8
5247
do
5348
if

modules/feed_aggregator/feed_aggregator_module.e

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
note
1+
note
22
description: "CMS module bringing support for feed aggregation."
33
date: "$Date$"
44
revision: "$Revision$"
@@ -352,10 +352,7 @@ feature -- Hook
352352
feed_to_html (a_feed_id: READABLE_STRING_GENERAL; a_count: INTEGER; with_feed_info: BOOLEAN; a_response: CMS_RESPONSE): detachable STRING
353353
local
354354
nb: INTEGER
355-
i: INTEGER
356-
e: FEED_ITEM
357355
l_cache: CMS_FILE_STRING_8_CACHE
358-
lnk: detachable FEED_LINK
359356
vis: FEED_TO_XHTML_VISITOR
360357
s: STRING
361358
do
@@ -410,11 +407,7 @@ feature -- Hook
410407

411408
feed_to_atom (a_feed_id: READABLE_STRING_GENERAL; a_count: INTEGER): detachable STRING
412409
local
413-
nb: INTEGER
414-
i: INTEGER
415-
e: FEED_ITEM
416410
vis: ATOM_FEED_GENERATOR
417-
s: STRING
418411
l_cache: CMS_FILE_STRING_8_CACHE
419412
do
420413
if

modules/messaging/src/cms_messaging_module.e

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
note
2-
description: "[
3-
Module that provides messenger functionality.
4-
]"
5-
author: "$Author: jfiat $"
1+
note
2+
description: "Module that provides messenger functionality."
3+
author: "$Author$"
64
date: "$Date$"
75
revision: "$Revision$"
86

@@ -238,8 +236,6 @@ $(document).ready(function() {
238236
r: CMS_RESPONSE
239237
e: CMS_EMAIL
240238
l_emails: ARRAYED_LIST [CMS_EMAIL]
241-
vars: STRING_TABLE [READABLE_STRING_8]
242-
l_messaging_email_address: READABLE_STRING_8
243239
s: STRING
244240
l_uid: READABLE_STRING_32
245241
f: like new_messaging_form

modules/node/cms_node_api.e

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
note
2-
description: "[
3-
API to manage CMS Nodes
4-
]"
1+
note
2+
description: "API to manage CMS Nodes."
53
date: "$Date$"
64
revision: "$Revision$"
75

@@ -315,8 +313,6 @@ feature -- Access: feeds
315313
l_size: NATURAL_64
316314
l_exhausted: BOOLEAN
317315
lnk: FEED_LINK
318-
mesg: CMS_CUSTOM_RESPONSE_MESSAGE
319-
l_payload: STRING
320316
l_feed_name: STRING_32
321317
do
322318
create l_feed_name.make_from_string (cms_api.setup.site_name)

modules/node/cms_node_module.e

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ feature -- Access: router
188188
a_router.map (l_uri_mapping, a_router.methods_get_post)
189189

190190
a_router.handle ("/node/add/{type}", l_node_handler, a_router.methods_get_post)
191+
a_router.handle ("/node/preview/{type}", l_node_handler, a_router.methods_post)
191192
a_router.handle ("/node/{id}/revision", l_node_handler, a_router.methods_get)
192193
a_router.handle ("/node/{id}/edit", l_node_handler, a_router.methods_get_post)
194+
a_router.handle ("/node/{id}/preview", l_node_handler, a_router.methods_post)
193195
a_router.handle ("/node/{id}/delete", l_node_handler, a_router.methods_get_post)
194196
a_router.handle ("/node/{id}/trash", l_node_handler, a_router.methods_get_post)
195197

@@ -231,6 +233,9 @@ feature -- Hooks
231233
-- <Precursor>
232234
do
233235
a_response.add_style (a_response.module_resource_url (Current, "/files/css/node.css", Void), Void)
236+
if attached {NODE_FORM_RESPONSE} a_response then
237+
a_response.add_javascript_url (a_response.module_resource_url (Current, "/files/js/node_form.js", Void))
238+
end
234239
end
235240

236241
block_list: ITERABLE [like {CMS_BLOCK}.name]

modules/node/handler/node_handler.e

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,18 @@ feature -- HTTP Methods
180180
-- <Precursor>
181181
local
182182
edit_response: NODE_FORM_RESPONSE
183+
preview_response: NODE_PREVIEW_RESPONSE
183184
do
184185
fixme ("Refactor code: extract methods: edit_node and add_node")
185186
if req.percent_encoded_path_info.ends_with ("/edit") then
186187
create edit_response.make (req, res, api, node_api)
187188
edit_response.execute
189+
elseif
190+
req.percent_encoded_path_info.ends_with ("/preview")
191+
or else req.percent_encoded_path_info.starts_with ("/node/preview")
192+
then
193+
create preview_response.make (req, res, api, node_api)
194+
preview_response.execute
188195
elseif req.percent_encoded_path_info.ends_with ("/delete") then
189196
if
190197
attached {WSF_STRING} req.form_parameter ("op") as l_op and then
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
note
2+
description: "Preview response handling node."
3+
revision: "$Revision$"
4+
5+
class
6+
NODE_PREVIEW_RESPONSE
7+
8+
inherit
9+
CMS_RESPONSE_I
10+
rename
11+
make as make_response
12+
end
13+
14+
create
15+
make
16+
17+
feature {NONE} -- Initialization
18+
19+
make (req: WSF_REQUEST; res: WSF_RESPONSE; a_api: like api; a_node_api: like node_api)
20+
do
21+
node_api := a_node_api
22+
make_response (req, res, a_api)
23+
end
24+
25+
feature -- Access
26+
27+
node_api: CMS_NODE_API
28+
-- Associated node API.
29+
30+
feature -- Helpers
31+
32+
node_id_path_parameter: INTEGER_64
33+
-- Node id passed as path parameter for request `request'.
34+
local
35+
s: STRING
36+
do
37+
if attached {WSF_STRING} request.path_parameter ("id") as p_nid then
38+
s := p_nid.value
39+
if s.is_integer_64 then
40+
Result := s.to_integer_64
41+
end
42+
end
43+
end
44+
45+
feature -- Execution
46+
47+
execute
48+
-- Computed response message.
49+
local
50+
html: CMS_HTML_PAGE_RESPONSE
51+
nid: INTEGER_64
52+
fd: detachable WSF_FORM_DATA
53+
l_ct_name: READABLE_STRING_GENERAL
54+
do
55+
if
56+
location.ends_with_general ("/preview")
57+
or else location.starts_with_general ("node/preview/")
58+
then
59+
if attached {WSF_STRING} request.path_parameter ("type") as p_type then
60+
l_ct_name := p_type.value
61+
else
62+
nid := node_id_path_parameter
63+
if
64+
nid > 0 and then
65+
attached node_api.node (nid) as l_node
66+
then
67+
l_ct_name := l_node.content_type
68+
end
69+
end
70+
if l_ct_name /= Void and then attached node_api.node_type (l_ct_name) as l_type then
71+
if
72+
attached new_edit_form (Void, request.request_uri, "preview_form", l_type) as f
73+
then
74+
f.process (Current)
75+
fd := f.last_data
76+
end
77+
if
78+
fd /= Void and then
79+
fd.is_valid and then
80+
attached fd.string_item ("content") as l_content and then
81+
attached fd.string_item ("format") as l_format and then
82+
attached previewed_content (l_format, l_content) as l_preview
83+
then
84+
create html.make (l_preview)
85+
response.send (html)
86+
else
87+
api.response_api.send_bad_request ("Invalid preview request!", request, response)
88+
end
89+
else
90+
api.response_api.send_bad_request ("Invalid preview request!", request, response)
91+
end
92+
else
93+
api.response_api.send_bad_request ("Invalid preview request!", request, response)
94+
end
95+
end
96+
97+
feature {NONE} -- Preview
98+
99+
previewed_content (a_format: READABLE_STRING_GENERAL; a_content: READABLE_STRING_GENERAL): detachable STRING
100+
local
101+
l_format: detachable CONTENT_FORMAT
102+
do
103+
if attached api.format (a_format) as f_format then
104+
l_format := f_format
105+
if
106+
l_format /= Void and then
107+
not api.has_permission_to_use_format (l_format)
108+
then
109+
l_format := Void
110+
end
111+
end
112+
if l_format /= Void then
113+
if a_content.is_valid_as_string_8 then
114+
Result := l_format.formatted_output (a_content.to_string_8)
115+
else
116+
Result := l_format.formatted_output (api.utf_8_encoded (a_content))
117+
end
118+
else
119+
Result := html_encoded (a_content)
120+
end
121+
end
122+
123+
new_edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_node_type: CMS_NODE_TYPE [CMS_NODE]): CMS_FORM
124+
-- Create a web form named `a_name' for node `a_node' (if set), using form action url `a_url', and for type of node `a_node_type'.
125+
local
126+
n: NODE_FORM_RESPONSE
127+
do
128+
create n.make (request, response, api, node_api)
129+
Result := n.new_edit_form (a_node, a_url, a_name, a_node_type)
130+
end
131+
132+
end

modules/node/handler/nodes_handler.e

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
note
1+
note
22
description: "Request handler related to /nodes."
33
date: "$Date$"
44
revision: "$Revision$"
@@ -71,16 +71,9 @@ feature -- HTTP Methods
7171
do_nodes_feed (a_content_type: CMS_CONTENT_TYPE; req: WSF_REQUEST; res: WSF_RESPONSE)
7272
local
7373
l_feed: FEED
74-
l_feed_item: FEED_ITEM
75-
l_params: CMS_DATA_QUERY_PARAMETERS
76-
n: CMS_NODE
77-
pg, nb: NATURAL_64
7874
l_size: NATURAL_64
79-
l_exhausted: BOOLEAN
80-
lnk: FEED_LINK
8175
mesg: CMS_CUSTOM_RESPONSE_MESSAGE
8276
l_payload: STRING
83-
l_feed_name: STRING_32
8477
do
8578
if attached {WSF_STRING} req.query_parameter ("size") as p_size and then p_size.is_integer then
8679
l_size := p_size.integer_value.to_natural_64

0 commit comments

Comments
 (0)