Forum OpenACS Q&A: Mapped host and no connection

Collapse
Posted by Ryan Gallimore on
How do I get the URL of a mapped host when generating this line at the end of each mail?

Getting too much email? Manage your notifications at: http://system_host/notifications/manage

A connection seems to be required to get the subsite url with subsite::get_url. However, since this can't be done in the mail scheduled proc, the best I can do is the SystemURL. I'd like to be able to get my mapped host so I can send my users to the host and theme they expect.

Collapse
Posted by Dave Bauer on
This is a problem overall.

You'd need to look up in the site-map the package that owns the notification in question. I am not sure if a notification request or the notification itself has a package_id.

Collapse
Posted by Ryan Gallimore on
When building the e-mail there seems to be no reference back to an originating package_id.

I suppose one workaround is to remove that footer message from notifications and add it to the message when it is created and a connection exists.

This would of course involve hacking up all packages in the same way...

Collapse
Posted by Dave Bauer on
The notification package could geneate this when you add the notification. Since you have to modify something, it makes sense to fix the notifications package to "know" about the host mapping.

There are a few other places this kind of thing needs to be fixed as well.

Collapse
Posted by Ryan Gallimore on
Where do you suggest the notification package be changed?
Collapse
Posted by Ryan Gallimore on
Here's how to derive the host mapped "manage url" in notifications, given the recipient's user_id:

+  fullquery name="scs::subsite_url_from_user_id.select_group_id_from_user_id"
+      querytext
+        select object_id_one as group_id
+          from acs_rels
+        where object_id_two = :user_id
+          and object_id_one in (select group_id
+                                  from application_groups)
+          and object_id_one > 0
+        limit 1
+      /querytext
+  /fullquery
+
+  fullquery name="scs::subsite_url_from_user_id.select_host"
+      querytext
+        select "http://"||host
+          from host_node_map
+        where node_id = :node_id
+        limit 1
+      /querytext
+  /fullquery
+
/queryset

+
+ad_proc -public scs::subsite_url_from_user_id {
+    {-user_id:required}
+} {
+    Derives the first absolute, host-mapped subsite url given the user_id.
+    Useful for determining the subsite url in a scheduled proc, such as notifications.
+    Assumes that user_id belongs to one and only one subsite application group.
+    If a host-mapped entry is not found, return the system url.
+} {
+
+    db_1row select_group_id_from_user_id {}
+
+    set node_id [site_node::get_node_id_from_object_id \
+            -object_id [application_group::package_id_from_group_id \
+                    -group_id $group_id]]
+
+    return [db_string select_host {} -default "[ad_url]"]
+
+}

Index: notifications/tcl/notification-email-procs.tcl
===================================================================
--- notifications/tcl/notification-email-procs.tcl    (revision 214)
+++ notifications/tcl/notification-email-procs.tcl    (working copy)
@@ -43,10 +43,13 @@
        return $domain
    }

-    ad_proc -public manage_notifications_url {} {
+    ad_proc -public manage_notifications_url {
+    {-to_user_id:required}
+    } {
        Build a url to the "manage notifications" script.
+        Supports host mapped subsites.
    } {
-        return "[ad_url][apm_package_url_from_key [notification::package_key]]manage"
+        return "[scs::subsite_url_from_user_id -user_id $to_user_id][apm_package_url_from_key [notification::package_key]]manage"
    }

    ad_proc -public reply_address_prefix {} {
@@ -123,7 +126,7 @@
        }

        # Variable used in the content
-      set manage_notifications_url [manage_notifications_url]
+      set manage_notifications_url [manage_notifications_url -to_user_id $to_user_id]

        if { [string length $content_html] == 0 } {
            set mime_type "text/plain"

Collapse
Posted by kodisan sby on
Thank you Ryan, this is really help me. I still working on it on my project now.

________________________________________________
kopi luwak