Improved node management.

- List node by node types
- fixed the trash/restore/delete workflow
Added messaging module to send message to cms users (by email for now).
Added early protection for cache, export and import functionalities.
This commit is contained in:
2017-02-28 11:24:48 +01:00
parent dc84e79952
commit a341bd98eb
35 changed files with 1055 additions and 212 deletions

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="messaging" uuid="939C9362-FD46-4B4F-BB36-A593089430AB" library_target="messaging">
<target name="messaging">
<root all_classes="true"/>
<option>
</option>
<setting name="concurrency" value="scoop"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="..\..\cms-safe.ecf" readonly="false"/>
<library name="cms_app_env" location="..\..\library\app_env\app_env-safe.ecf" readonly="false"/>
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/>
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
<library name="wsf_encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
<library name="wsf_html" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf_html\wsf_html-safe.ecf"/>
<cluster name="src" location="src\" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,4 @@
.messaging-box fieldset {
overflow: scroll;
height: 250px;
}

View File

@@ -0,0 +1,6 @@
.messaging-box {
fieldset {
overflow:scroll;
height:250px;
}
}

View File

@@ -0,0 +1,17 @@
note
description: "API for the contact module."
date: "$Date$"
revision: "$Revision$"
class
CMS_MESSAGING_API
inherit
CMS_MODULE_API
REFACTORING_HELPER
create
make
end

View File

@@ -0,0 +1,381 @@
note
description: "[
Module that provides messenger functionality.
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
class
CMS_MESSAGING_MODULE
inherit
CMS_MODULE
rename
module_api as messaging_api
redefine
setup_hooks,
-- install,
initialize,
permissions,
messaging_api
end
CMS_HOOK_AUTO_REGISTER
CMS_HOOK_MENU_SYSTEM_ALTER
REFACTORING_HELPER
SHARED_LOGGER
create
make
feature {NONE} -- Initialization
make
-- Create current module
do
version := "1.0"
description := "Messaging module"
package := "messaging"
end
feature -- Access
name: STRING = "messaging"
-- <Precursor>
feature {CMS_API} -- Module Initialization
initialize (api: CMS_API)
-- <Precursor>
local
l_messaging_api: like messaging_api
do
Precursor (api)
create l_messaging_api.make (api)
messaging_api := l_messaging_api
end
feature {CMS_API} -- Access: API
messaging_api: detachable CMS_MESSAGING_API
feature -- Router
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
-- Router configuration.
local
m: WSF_URI_MAPPING
do
create m.make_trailing_slash_ignored ("/messaging", create {WSF_URI_AGENT_HANDLER}.make (agent handle_get_messaging (a_api, ?, ?)))
a_router.map (m, a_router.methods_head_get)
a_router.handle ("/messaging", create {WSF_URI_AGENT_HANDLER}.make (agent handle_post_messaging (a_api, ?, ?)), a_router.methods_put_post)
end
feature -- Security
permissions: LIST [READABLE_STRING_8]
-- List of permission ids, used by this module, and declared.
do
Result := Precursor
Result.force ("admin messaging")
Result.force ("message any user")
Result.force ("use messaging")
end
feature -- Hooks configuration
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
-- Module hooks configuration.
do
auto_subscribe_to_hooks (a_hooks)
end
feature -- Hooks
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
-- Hook execution on collection of menu contained by `a_menu_system'
-- for related response `a_response'.
do
debug ("refactor_fixme")
fixme ("add messaging to menu")
end
end
new_html_messaging_form (a_response: CMS_RESPONSE; api: CMS_API): STRING
local
f: CMS_FORM
do
a_response.add_style (a_response.url ("/module/" + name + "/files/css/messaging.css", Void), Void)
-- TODO: use template to overwrite/customize
-- if attached smarty_template_block (Current, "messaging", api) as l_tpl_block then
-- across
-- a_response.values as tb
-- loop
-- l_tpl_block.set_value (tb.item, tb.key)
-- end
-- Result := l_tpl_block.to_html (a_response.theme)
-- else
f := new_messaging_form (a_response, api)
api.hooks.invoke_form_alter (f, f.last_data, a_response)
Result := "<div class=%"messaging-box%"><h1>Send message to ...</h1>" + f.to_html (a_response.wsf_theme) + "<br/></div>"
-- end
end
new_messaging_form (a_response: CMS_RESPONSE; api: CMS_API): CMS_FORM
local
f: CMS_FORM
f_name: WSF_FORM_TEXT_INPUT
f_msg: WSF_FORM_TEXTAREA
f_submit: WSF_FORM_SUBMIT_INPUT
f_user: WSF_FORM_CHECKBOX_INPUT
f_set: WSF_FORM_FIELD_SET
l_params: CMS_DATA_QUERY_PARAMETERS
nb: INTEGER
i: INTEGER
do
create f.make (a_response.url ("messaging", Void), "messaging-form")
if attached api.user as l_current_user then
nb := api.user_api.users_count
from
create f_set.make
f_set.set_legend ("Select users")
f.extend (f_set)
i := 0
until
i > nb
loop
create l_params.make (i.to_natural_64, 25)
if attached api.user_api.recent_users (l_params) as l_users then
across
l_users as ic
loop
if l_current_user.id = ic.item.id then
else
create f_user.make_with_value ("users[]", ic.item.id.out)
f_user.set_title (api.user_api.user_display_name (ic.item))
f_set.extend (f_user)
end
end
end
i := i + 25
end
create f_name.make ("title")
f_name.set_size (80)
f_name.set_label ("Title")
f_name.set_is_required (True)
f.extend (f_name)
create f_msg.make ("message")
f_msg.set_cols (80)
f_msg.set_rows (75)
f_msg.set_label ("Message")
f_msg.set_rows (5)
f_msg.set_is_required (True)
f.extend (f_msg)
create f_submit.make_with_text ("submit-op", "Send")
f.extend (f_submit)
end
Result := f
end
handle_get_messaging (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local
r: CMS_RESPONSE
do
if api.has_permission ("use messaging") or api.has_permission ("message any user") then
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
r.values.force ("messaging", "messaging")
r.set_main_content (new_html_messaging_form (r, api))
else
create {FORBIDDEN_ERROR_CMS_RESPONSE} r.make (req, res, api)
end
r.execute
end
handle_post_messaging (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local
r: CMS_RESPONSE
e: CMS_EMAIL
l_emails: ARRAYED_LIST [CMS_EMAIL]
vars: STRING_TABLE [READABLE_STRING_8]
l_messaging_email_address: READABLE_STRING_8
s: STRING
l_uid: READABLE_STRING_32
f: like new_messaging_form
l_user: detachable CMS_USER
l_email_title: READABLE_STRING_8
l_email_messg: READABLE_STRING_8
do
if api.has_permission ("message any user") then
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
r.add_style (r.url ("/module/" + name + "/files/css/messaging.css", Void), Void)
create s.make_empty
f := new_messaging_form (r, api)
f.process (r)
if attached f.last_data as fd then
if
not fd.has_error and then
attached fd.string_item ("title") as l_title and then
attached fd.string_item ("message") as l_message and then
attached fd.table_item ("users") as l_users
then
create l_emails.make (l_users.count)
s.append ("Send message %"")
s.append (r.html_encoded (l_title))
s.append ("%"")
s.append (" to users: <ul>")
across
l_users as ic
loop
if attached {WSF_STRING} ic.item as p_uid then
l_uid := p_uid.value
if l_uid.is_integer_64 then
l_user := api.user_api.user_by_id (l_uid.to_integer_64)
else
l_user := api.user_api.user_by_name (l_uid)
end
s.append ("<li>")
if l_user /= Void and then attached l_user.email as l_user_email then
s.append (r.html_encoded (api.user_api.user_display_name (l_user)))
s.append (" &lt;")
s.append (r.html_encoded (l_user_email))
s.append ("&gt;")
l_email_title := resolved_template_text (api, l_title, l_user)
l_email_messg := resolved_template_text (api, l_message, l_user)
e := api.new_email (l_user_email, l_email_title, l_email_messg)
s.append (" <pre>")
s.append (e.message)
s.append ("</pre>")
l_emails.force (e)
api.process_email (e)
if e.is_sent then
s.append (" successfully sent.")
else
s.append (" failure, not sent!")
end
else
s.append (r.html_encoded (p_uid.value))
s.append (" skipped!")
end
s.append ("</li>%N")
end
end
else
f.append_to_html (r.wsf_theme, s)
end
end
r.set_main_content (s)
else
create {FORBIDDEN_ERROR_CMS_RESPONSE} r.make (req, res, api)
end
r.execute
end
feature {NONE} -- Helpers
form_parameters_as_string (req: WSF_REQUEST): STRING
do
create Result.make_empty
across req.form_parameters as ic loop
Result.append (ic.item.key)
Result.append_character ('=')
Result.append_string (ic.item.string_representation)
Result.append_character ('%N')
end
end
feature {NONE} -- Contact Message
resolved_template_text (api: CMS_API; a_text: READABLE_STRING_GENERAL; a_target_user: detachable CMS_USER): STRING_8
local
smt: CMS_SMARTY_TEMPLATE_TEXT
utf: UTF_CONVERTER
do
create smt.make (utf.utf_32_string_to_utf_8_string_8 (a_text))
across
api.builtin_variables as vars_ic
loop
smt.set_value (vars_ic.item, vars_ic.key)
end
if a_target_user /= Void then
smt.set_value (a_target_user.name, "target_user_name")
smt.set_value (api.user_api.user_display_name (a_target_user), "target_user_profile_name")
smt.set_value (a_target_user.id.out, "target_user_id")
if attached a_target_user.email as l_email then
smt.set_value (l_email, "target_user_email")
end
end
Result := smt.string
end
-- email_html_message (a_message_id: READABLE_STRING_8; a_response: CMS_RESPONSE; a_html_encoded_values: STRING_TABLE [READABLE_STRING_8]): STRING
-- -- html message related to `a_message_id'.
-- local
-- res: PATH
-- p: detachable PATH
-- tpl: CMS_SMARTY_TEMPLATE_BLOCK
-- exp: CMS_STRING_EXPANDER [STRING_8]
-- do
-- write_debug_log (generator + ".email_html_message for [" + a_message_id + " ]")
-- create res.make_from_string ("templates")
-- res := res.extended ("email_").appended (a_message_id).appended_with_extension ("tpl")
-- p := a_response.api.module_theme_resource_location (Current, res)
-- if p /= Void then
-- if attached p.entry as e then
-- create tpl.make (a_message_id, Void, p.parent, e)
-- write_debug_log (generator + ".email_html_message from smarty template:" + tpl.out)
-- else
-- create tpl.make (a_message_id, Void, p.parent, p)
-- write_debug_log (generator + ".email_html_message from smarty template:" + tpl.out)
-- end
-- across
-- a_html_encoded_values as ic
-- loop
-- tpl.set_value (ic.item, ic.key)
-- end
-- Result := tpl.to_html (a_response.theme)
-- else
-- if a_message_id.is_case_insensitive_equal_general ("message") then
-- create Result.make_from_string (messaging_message_template)
-- elseif a_message_id.is_case_insensitive_equal_general ("notification") then
-- create Result.make_from_string (messaging_notification_message_template)
-- else
-- create Result.make_from_string (a_message_id)
-- across
-- a_html_encoded_values as ic
-- loop
-- Result.append ("<li>")
-- Result.append (html_encoded (ic.key))
-- Result.append (": ")
-- Result.append (ic.item) -- Already html encoded.
-- Result.append ("</li>%N")
-- end
-- end
-- create exp.make
-- across
-- a_html_encoded_values as ic
-- loop
-- exp.put (ic.item, ic.key)
-- end
-- exp.expand_string (Result)
-- write_debug_log (generator + ".email_html_message using built-in message:" + Result)
-- end
-- end
end