From ff58593bff06ce6622e5d26edf494b2272b96e07 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 18 Feb 2016 12:47:21 +0100 Subject: [PATCH] Added functions to get link from menu or link composite. Improved management menu, but using sub menu. --- examples/demo/site/config/blocks.ini | 4 +- library/model/src/link/cms_link.e | 16 ++++ library/model/src/link/cms_link_composite.e | 73 ++++++++++++++++++- library/model/src/link/cms_local_link.e | 12 +-- library/model/src/link/cms_menu.e | 4 +- modules/admin/cms_admin_module.e | 31 ++++---- modules/admin/handler/cms_admin_response.e | 58 ++++++++++++--- modules/auth/cms_authentication_module.e | 2 +- .../feed_aggregator/feed_aggregator_module.e | 2 +- modules/taxonomy/cms_taxonomy_module.e | 2 +- 10 files changed, 160 insertions(+), 44 deletions(-) diff --git a/examples/demo/site/config/blocks.ini b/examples/demo/site/config/blocks.ini index 1afcb15..77a9895 100644 --- a/examples/demo/site/config/blocks.ini +++ b/examples/demo/site/config/blocks.ini @@ -2,8 +2,8 @@ #navigation.region=sidebar_first #navigation.condition=is_front -management.conditions[]=path:admin* -management.conditions[]=is_front +#management.conditions[]=path:admin* +#management.conditions[]=is_front #Feeds feed.news.weight=3 diff --git a/library/model/src/link/cms_link.e b/library/model/src/link/cms_link.e index 10a4361..e497696 100644 --- a/library/model/src/link/cms_link.e +++ b/library/model/src/link/cms_link.e @@ -163,6 +163,22 @@ feature -- Security feature -- Element change + set_title (a_title: detachable READABLE_STRING_GENERAL) + -- Set `title' to `a_title' or `location'. + do + if a_title /= Void then + title := a_title.as_string_32 + else + title := location.as_string_32 + end + end + + set_location (a_loc: READABLE_STRING_8) + -- Set `location' to `a_loc'. + do + location := a_loc + end + set_weight (a_weight: INTEGER) -- Set `weight' to `a_weight'. do diff --git a/library/model/src/link/cms_link_composite.e b/library/model/src/link/cms_link_composite.e index 2c45636..e8df777 100644 --- a/library/model/src/link/cms_link_composite.e +++ b/library/model/src/link/cms_link_composite.e @@ -18,13 +18,82 @@ feature -- Access deferred end -feature -- Element change + item_by_title (a_title: READABLE_STRING_GENERAL): detachable CMS_LINK + -- First link with title `a_title' if any. + do + if attached items as l_items then + across + l_items as ic + until + Result /= Void + loop + Result := ic.item + if not a_title.is_case_insensitive_equal (Result.title) then + Result := Void + end + end + end + ensure + coherent_result: Result /= Void implies Result.title.is_case_insensitive_equal_general (a_title) + end + + item_by_location (a_loc: READABLE_STRING_8): detachable CMS_LINK + -- First link with location `a_loc' if any. + do + if attached items as l_items then + across + l_items as ic + until + Result /= Void + loop + Result := ic.item + if not a_loc.same_string (Result.location) then + Result := Void + end + end + end + ensure + coherent_result: Result /= Void implies Result.location.same_string (a_loc) + end + + new_composite_item (a_title: detachable READABLE_STRING_GENERAL; a_location: READABLE_STRING_8): CMS_LINK_COMPOSITE + -- If exists, item with location `a_location' or title `a_title', + -- otherwise create new local link and extend to Current. + local + lnk: CMS_LOCAL_LINK + do + if attached {CMS_LINK_COMPOSITE} item_by_location (a_location) as l_parent then + Result := l_parent + elseif a_title /= Void and then attached {CMS_LINK_COMPOSITE} item_by_title (a_title) as l_parent then + Result := l_parent + else + create lnk.make (a_title, a_location) + extend (lnk) + Result := lnk + end + if attached {CMS_LOCAL_LINK} Result as l_local_lnk and then not l_local_lnk.is_expanded then + l_local_lnk.set_expandable (True) + l_local_lnk.set_collapsed (True) + end + end + +feature -- Element change extend (lnk: CMS_LINK) -- Add `lnk' as a sub link. deferred end + extend_into (lnk: CMS_LINK; a_parent_title: detachable READABLE_STRING_GENERAL; a_parent_location: READABLE_STRING_8) + -- Extend `lnk' into local link with location `a_parent_location'. + -- If the parent is not found, create it with title `a_parent_title'. + local + l_parent: CMS_LINK_COMPOSITE + do + l_parent := new_composite_item (a_parent_title, a_parent_location) + l_parent.extend (lnk) + end + remove (lnk: CMS_LINK) -- Remove link `lnk' from Current container. deferred @@ -68,6 +137,6 @@ feature -- status report end note - copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" + copyright: "2011-2016, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" end diff --git a/library/model/src/link/cms_local_link.e b/library/model/src/link/cms_local_link.e index 09fa2fc..4dce06c 100644 --- a/library/model/src/link/cms_local_link.e +++ b/library/model/src/link/cms_local_link.e @@ -79,16 +79,6 @@ feature -- Security feature -- Element change - set_title (a_title: detachable READABLE_STRING_GENERAL) - -- Set `title' to `a_title' or `location'. - do - if a_title /= Void then - title := a_title.as_string_32 - else - title := location.as_string_32 - end - end - add_link (lnk: CMS_LINK) -- local @@ -194,6 +184,6 @@ feature {NONE} -- Implementation invariant note - copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" + copyright: "2011-2016, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" end diff --git a/library/model/src/link/cms_menu.e b/library/model/src/link/cms_menu.e index 6f3a292..277d498 100644 --- a/library/model/src/link/cms_menu.e +++ b/library/model/src/link/cms_menu.e @@ -73,7 +73,7 @@ feature -- Status report end end -feature -- Element change +feature -- Element change extend (lnk: CMS_LINK) -- @@ -104,6 +104,6 @@ feature -- Access invariant note - copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" + copyright: "2011-2016, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" end diff --git a/modules/admin/cms_admin_module.e b/modules/admin/cms_admin_module.e index 14231d3..aafe5af 100644 --- a/modules/admin/cms_admin_module.e +++ b/modules/admin/cms_admin_module.e @@ -103,7 +103,7 @@ feature -- Security -- List of permission ids, used by this module, and declared. do Result := Precursor - Result.force ("manage admin") + Result.force ("access admin") Result.force ("admin users") Result.force ("admin roles") Result.force ("admin modules") @@ -132,29 +132,34 @@ feature -- Hooks menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE) local lnk: CMS_LOCAL_LINK + admin_lnk: CMS_LINK_COMPOSITE do if a_response.api.user_is_authenticated then - if - a_response.has_permission ("manage " + {CMS_ADMIN_MODULE}.name) -- Note: admin user has all permissions enabled by default. - then - -- TODO: we should probably use more side menu and less primary_menu. - create lnk.make ("Admin", "admin") - lnk.set_permission_arguments (<<"manage " + {CMS_ADMIN_MODULE}.name>>) - a_menu_system.management_menu.extend (lnk) - - end + admin_lnk := a_menu_system.management_menu.new_composite_item ("Admin", "admin") create lnk.make ("Module", "admin/modules") lnk.set_permission_arguments (<<"manage module">>) - a_menu_system.management_menu.extend (lnk) + admin_lnk.extend (lnk) -- Per module cache permission! create lnk.make ("Cache", "admin/cache") - a_menu_system.management_menu.extend (lnk) + admin_lnk.extend (lnk) -- Per module export permission! create lnk.make ("Export", "admin/export") - a_menu_system.management_menu.extend (lnk) + admin_lnk.extend (lnk) + +-- if +-- a_response.has_permission ("access " + {CMS_ADMIN_MODULE}.name) -- Note: admin user has all permissions enabled by default. +-- then +-- lnk := admin_lnk +-- lnk.set_title ("Admin") + +-- a_menu_system.management_menu.extend (lnk) +-- elseif admin_lnk.has_children then +-- a_menu_system.management_menu.extend (admin_lnk) +-- end +-- admin_lnk.set_permission_arguments (<<"access " + {CMS_ADMIN_MODULE}.name>>) end end diff --git a/modules/admin/handler/cms_admin_response.e b/modules/admin/handler/cms_admin_response.e index fb7dea4..07e6226 100644 --- a/modules/admin/handler/cms_admin_response.e +++ b/modules/admin/handler/cms_admin_response.e @@ -17,22 +17,58 @@ feature -- Process process local b: STRING + l_admin_links: ARRAYED_LIST [TUPLE [package: READABLE_STRING_8; permissions: ARRAY [READABLE_STRING_GENERAL]; link: CMS_LINK; help: READABLE_STRING_GENERAL]] + lst: detachable ARRAYED_LIST [TUPLE [permissions: ARRAY [READABLE_STRING_GENERAL]; link: CMS_LINK; help: READABLE_STRING_GENERAL]] + categories: STRING_TABLE [ARRAYED_LIST [TUPLE [permissions: ARRAY [READABLE_STRING_GENERAL]; link: CMS_LINK; help: READABLE_STRING_GENERAL]]] + l_package: READABLE_STRING_8 do + create l_admin_links.make (5) + l_admin_links.force (["core", <<"admin users">>, local_link ("Users", "admin/users"), "View/Edit/Add Users"]) + l_admin_links.force (["core", <<"admin roles">>, local_link ("Roles", "admin/roles"), "View/Edit/Add Roles"]) + l_admin_links.force (["core", <<"admin modules">>, local_link ("Modules", "admin/modules"), "(un)Install modules"]) + l_admin_links.force (["support", <<"admin cache">>, local_link ("Cache", "admin/cache"), "Clear caches"]) + l_admin_links.force (["support", <<"admin export">>, local_link ("Export", "admin/export"), "Export CMS contents, and modules contents."]) + create categories.make_caseless (3) + across + l_admin_links as ic + loop + l_package := ic.item.package + lst := categories.item (l_package) + if lst = Void then + create lst.make (1) + categories.force (lst, l_package) + end + lst.force ([ic.item.permissions, ic.item.link, ic.item.help]) + end + create b.make_empty set_title (translation ("Admin Page", Void)) - b.append ("
    ") fixme ("Check how to make it configurable") - if has_permissions (<< "admin users">>) then - b.append ("
  • " + link ("Users", "admin/users", Void)) - b.append ("
    View/Edit/Add Users
    ") - b.append ("
  • ") + across + categories as cats_ic + loop + lst := cats_ic.item + b.append ("

    ") + b.append (html_encoded (cats_ic.key)) + b.append ("

    ") + b.append ("
      ") + across + lst as ic + loop + if has_permissions (ic.item.permissions) then + b.append ("
    • ") + if attached ic.item.link as lnk then + b.append (link (lnk.title, lnk.location, Void)) + end + b.append ("
      ") + b.append (html_encoded (ic.item.help)) + b.append ("
      ") + b.append ("
    • ") + end + end + b.append ("
    ") end - if has_permissions (<< "admin roles">>) then - b.append ("
  • " + link ("Roles", "admin/roles", Void)) - b.append ("
    View/Edit/Add Roles
    ") - b.append ("
  • ") - end - b.append ("
") + set_main_content (b) end diff --git a/modules/auth/cms_authentication_module.e b/modules/auth/cms_authentication_module.e index 0591517..31f1d58 100644 --- a/modules/auth/cms_authentication_module.e +++ b/modules/auth/cms_authentication_module.e @@ -192,7 +192,7 @@ feature -- Hooks configuration -- Add the link to the taxonomy to the main menu if a_response.has_permission ("admin registration") then create lnk.make ("Registration", "admin/pending-registrations/") - a_menu_system.management_menu.extend (lnk) + a_menu_system.management_menu.extend_into (lnk, "Admin", "admin") end end diff --git a/modules/feed_aggregator/feed_aggregator_module.e b/modules/feed_aggregator/feed_aggregator_module.e index d827875..e81e4fc 100644 --- a/modules/feed_aggregator/feed_aggregator_module.e +++ b/modules/feed_aggregator/feed_aggregator_module.e @@ -349,7 +349,7 @@ feature -- Hook if a_response.is_authenticated then a_menu_system.navigation_menu.extend (create {CMS_LOCAL_LINK}.make ("Feeds", "feed_aggregation/")) if a_response.has_permission (permission__manage_feed_aggregator) then - a_menu_system.management_menu.extend (create {CMS_LOCAL_LINK}.make ("Feeds (admin)", "admin/feed_aggregator/")) + a_menu_system.management_menu.extend_into (create {CMS_LOCAL_LINK}.make ("Feeds (admin)", "admin/feed_aggregator/"), "Admin", "admin") end end end diff --git a/modules/taxonomy/cms_taxonomy_module.e b/modules/taxonomy/cms_taxonomy_module.e index 8b0d873..1c3902c 100644 --- a/modules/taxonomy/cms_taxonomy_module.e +++ b/modules/taxonomy/cms_taxonomy_module.e @@ -187,7 +187,7 @@ feature -- Hooks -- Add the link to the taxonomy to the main menu if a_response.has_permission ("admin taxonomy") then create lnk.make ("Taxonomy", "admin/taxonomy/") - a_menu_system.management_menu.extend (lnk) + a_menu_system.management_menu.extend_into (lnk, "Admin", "admin") end end