Added CMS_CORE_MODULE which is the mandatory module for ROC CMS.

Added CMS_USER.profile_name .
Improved module managements with install vs enable.
  - enabled/disabled status can also be stored in database.
Install procedure do not install all available modules anymore.
This commit is contained in:
2017-02-07 16:52:08 +01:00
parent f0a3b2bd3a
commit d97542f797
45 changed files with 738 additions and 253 deletions

View File

@@ -57,8 +57,9 @@ feature {NONE} -- Initialize
end
-- Keep enable modules list.
l_enabled_modules := setup.enabled_modules
create l_enabled_modules.make (setup.modules.count)
enabled_modules := l_enabled_modules
setup.fill_enabled_modules (Current)
-- Complete storage setup.
storage.set_api (Current)
@@ -72,6 +73,11 @@ feature {NONE} -- Initialize
-- or the reverse, or merge installation and initialization
-- and leave the responsability to the module to know
-- if this is installed or not...
if attached {CMS_CORE_MODULE} l_module as l_core_module then
if not l_core_module.is_installed (Current) then
l_core_module.install (Current)
end
end
-- if not l_module.is_installed (Current) then
-- l_module.install (Current)
-- end
@@ -119,7 +125,7 @@ feature {NONE} -- Initialize
formats.extend (f)
end
feature {CMS_ACCESS} -- Installation
feature {CMS_ACCESS} -- Module management
install_all_modules
-- Install CMS or uninstalled module which are enabled.
@@ -134,12 +140,19 @@ feature {CMS_ACCESS} -- Installation
-- or the reverse, or merge installation and initialization
-- and leave the responsability to the module to know
-- if this is installed or not...
if not l_module.is_installed (Current) then
if l_module.is_enabled and not l_module.is_installed (Current) then
install_module (l_module)
end
end
end
installed_module_version (m: CMS_MODULE): detachable READABLE_STRING_32
require
module_installed: is_module_installed (m)
do
Result := m.installed_version (Current)
end
install_module (m: CMS_MODULE)
-- Install module `m'.
require
@@ -159,6 +172,22 @@ feature {CMS_ACCESS} -- Installation
m.uninstall (Current)
end
enable_module (m: CMS_MODULE)
-- Enable module `m'.
do
m.update_status_in_storage (True, Current)
ensure
module_enabled: is_module_enabled (m)
end
disable_module (m: CMS_MODULE)
-- Disable module `m'.
do
m.update_status_in_storage (False, Current)
ensure
module_disabled: not is_module_enabled (m)
end
feature -- Access
setup: CMS_SETUP
@@ -431,13 +460,18 @@ feature -- Query: module
Result := a_module.is_installed (Current)
end
is_module_enabled (a_module: CMS_MODULE): BOOLEAN
do
Result := a_module.is_enabled or a_module.is_enabled_in_storage (Current)
end
enabled_modules: CMS_MODULE_COLLECTION
module (a_type: TYPE [CMS_MODULE]): detachable CMS_MODULE
-- Enabled module typed `a_type', if any.
--| usage: if attached module ({FOO_MODULE}) as mod then ...
do
Result := setup.modules.item (a_type)
Result := installed_module (a_type)
if Result /= Void and then not Result.is_enabled then
Result := Void
end
@@ -445,6 +479,16 @@ feature -- Query: module
Result /= Void implies (Result.is_enabled) -- and a_type.is_conforming_to (Result.generating_type))
end
installed_module (a_type: TYPE [CMS_MODULE]): detachable CMS_MODULE
-- Module typed `a_type', if any.
-- It may not be enabled!
--| usage: if attached module ({FOO_MODULE}) as mod then ...
do
Result := setup.modules.item (a_type)
ensure
--FIXME Result /= Void implies (Result.is_enabled) -- and a_type.is_conforming_to (Result.generating_type))
end
module_api (a_type: TYPE [CMS_MODULE]): detachable CMS_MODULE_API
-- Enabled module API associated with module typed `a_type'.
do

View File

@@ -111,6 +111,9 @@ feature -- Export
u := ic.item
create j.make_empty
j.put_string (u.name, "name")
if attached u.profile_name as pn then
j.put_string (pn, "profile_name")
end
j.put_integer (u.status, "status")
put_string_into_json (u.email, "email", j)
put_string_into_json (u.password, "password", j)

View File

@@ -203,6 +203,10 @@ feature -- Import
if attached json_string_8_item (j, "email") as l_email then
Result.set_email (l_email)
end
if attached json_string_8_item (j, "profile_name") as l_profile_name then
Result.set_profile_name (l_profile_name)
end
if attached {JSON_ARRAY} j.item ("roles") as j_roles then
create l_roles.make (j_roles.count)
across

View File

@@ -92,10 +92,24 @@ feature {CMS_API} -- Access: API
feature {CMS_API} -- Module management
installed_version (api: CMS_API): detachable READABLE_STRING_32
require
is_installed (api)
do
Result := api.storage.custom_value ("is_installed", "module-" + name)
end
is_installed (api: CMS_API): BOOLEAN
-- Is Current module installed?
local
v: detachable READABLE_STRING_32
do
if attached api.storage.custom_value ("is_initialized", "module-" + name) as v then
v := api.storage.custom_value ("is_installed", "module-" + name)
if v = Void then
-- Kept for backward compabilitiy
v := api.storage.custom_value ("is_initialized", "module-" + name)
end
if v /= Void then
if v.is_case_insensitive_equal_general (version) then
Result := True
elseif v.is_case_insensitive_equal_general ("yes") then
@@ -112,18 +126,58 @@ feature {CMS_API} -- Module management
end
end
is_enabled_in_storage (api: CMS_API): BOOLEAN
-- Is Current module installed?
local
v: detachable READABLE_STRING_32
do
v := api.storage.custom_value ("is_enabled", "module-" + name)
if v /= Void then
if v.is_case_insensitive_equal_general (version) then
Result := True
elseif v.is_case_insensitive_equal_general ("yes") then
-- Backward compatibility.
Result := True
elseif v.is_case_insensitive_equal_general ("no") then
-- Probably a module that was installed, but now uninstalled.
Result := False
else
-- Maybe a different version is installed.
-- For now, let's assume this is installed.
Result := True
end
end
end
update_status_in_storage (a_is_enabled: BOOLEAN; api: CMS_API)
-- Is Current module installed?
do
if a_is_enabled then
api.storage.set_custom_value ("is_enabled", version, "module-" + name)
enable
else
api.storage.unset_custom_value ("is_enabled", "module-" + name)
disable
end
end
install (api: CMS_API)
require
is_not_installed: not is_installed (api)
do
api.storage.set_custom_value ("is_initialized", version, "module-" + name)
api.storage.set_custom_value ("is_installed", version, "module-" + name)
if is_enabled then
api.storage.set_custom_value ("is_enabled", version, "module-" + name)
else
api.storage.unset_custom_value ("is_enabled", "module-" + name)
end
end
uninstall (api: CMS_API)
require
is_installed: is_installed (api)
do
api.storage.set_custom_value ("is_initialized", "no", "module-" + name)
api.storage.set_custom_value ("is_installed", "no", "module-" + name)
end
feature -- Router
@@ -195,6 +249,6 @@ invariant
version_set: not version.is_whitespace
note
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -48,8 +48,6 @@ feature -- Access
Result := Void
end
end
ensure
Result /= Void implies (Result.is_enabled)
end
item_by_name (a_name: READABLE_STRING_GENERAL): detachable CMS_MODULE
@@ -129,6 +127,6 @@ feature {NONE} -- Implementation
-- List of available modules.
;note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -32,7 +32,7 @@ feature -- Access
feature -- Conversion
append_content_as_html_to (a_content: G; is_teaser: BOOLEAN; a_output: STRING; a_response: detachable CMS_RESPONSE)
append_content_as_html_to (a_content: G; is_teaser: BOOLEAN; a_output: STRING; a_response: CMS_RESPONSE)
-- Append `a_content' as html to `a_output', and adapt output according to `is_teaser' (full output, or teaser).
-- In the context of optional `a_response'.
deferred
@@ -49,6 +49,6 @@ feature -- Conversion
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -91,9 +91,11 @@ feature -- HTTP Methods
if api.is_module_installed (l_module) then
s.append (" was successfully installed.")
else
elseif l_module.is_enabled then
s.append (" could not be installed!")
s.append (" <span class=%"error%">[ERROR]</span>")
else
s.append (" is not enabled!")
end
s.append ("</li>%N")
end
@@ -105,6 +107,6 @@ feature -- HTTP Methods
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -1127,7 +1127,8 @@ feature -- Generation
add_to_primary_menu (lnk)
api.hooks.invoke_menu_system_alter (menu_system, Current)
if api.enabled_modules.count = 0 then
if api.enabled_modules.count = 1 then
-- It is the required CMS_CORE_MODULE!
add_to_primary_menu (create {CMS_LOCAL_LINK}.make ("Install", "admin/install"))
end
@@ -1261,6 +1262,7 @@ feature -- Generation
page.register_variable (request.is_https, "is_https")
if attached user as l_user then
page.register_variable (l_user.name, "user")
page.register_variable (user_profile_name (l_user), "user_profile_name")
end
if attached title as l_title then
page.register_variable (l_title, "site_title")
@@ -1373,17 +1375,28 @@ feature -- Helpers: cms link
if a_opt_title /= Void then
create Result.make (a_opt_title, user_url (u))
else
create Result.make (u.name, user_url (u))
create Result.make (user_profile_name (u), user_url (u))
end
end
feature -- Helpers: html links
feature -- Helpers: html links
user_profile_name (u: CMS_USER): READABLE_STRING_32
do
if attached u.profile_name as pn and then not pn.is_whitespace then
Result := pn
elseif not u.name.is_whitespace then
Result := u.name
else
Result := {STRING_32} "user #" + u.id.out
end
end
user_html_link (u: CMS_USER): STRING
require
u_with_name: not u.name.is_whitespace
do
Result := link (u.name, "user/" + u.id.out, Void)
Result := link (user_profile_name (u), "user/" + u.id.out, Void)
end
feature -- Helpers: URLs