From: Casey A. S. <li...@se...> - 2006-02-24 09:52:09
|
This patch could likely be done better - I didn't poke around to see how to properly feed shared_calendar's "calendar_domain" into the query - I'm not really sure why it has the dots changed to underscores, and didn't dig around enough to find out. I have to wonder why the plugin stores that data, mangled or not, if it doesn't actually use it. From a DBA perspective, I'd greatly prefer the domain was stored intact with the dots. However this patch does a very effective job of allowing calendar admins to create public calendars that anyone on their domain can use, but nobody outside of their domain can see. The problem with the current shared_calendars plugin is that anyone in the same webmail database can see every public calendar in existance. This patch is an alternate choice to the one I sent to the users list a while ago which removes public calendar functionality from the shared_calendars plugin interface. If you need to get the domain set correctly for each user, the vlogin plugin will handle that. One final note - I'm using PostgreSQL. If you're using MySQL without the ANSI-compliant quoting option enabled, you'll need to change the query to use MySQL's proprietary quoting style. Simply change the \'%1\' to "%1" and the same for %2. --- calendar_sql_backend.orig/calendar_functions.php 2006-02-24 06:46:15.000000000 +0000 +++ calendar_sql_backend/calendar_functions.php 2006-02-24 09:36:58.000000000 +0000 @@ -186,16 +186,15 @@ function cal_sql_get_all_public_calendars_do() { - global $all_calendars_of_type_query, $color; + global $all_public_calendars_query, $color, $domain; // get database connection // $db = cal_get_database_connection(); - - $sql = $all_calendars_of_type_query; - $sql = str_replace('%1', SM_CAL_TYPE_PUBLIC, $sql); + $sql = $all_public_calendars_query; + $sql = str_replace(array('%1', '%2'), array(str_replace('.', '_', $domain), SM_CAL_TYPE_PUBLIC), $sql); $IDs = $db->getAll($sql); diff -Naur calendar_sql_backend.orig/config.php calendar_sql_backend/config.php --- calendar_sql_backend.orig/config.php 2006-02-24 06:46:16.000000000 +0000 +++ calendar_sql_backend/config.php 2006-02-24 09:39:58.000000000 +0000 @@ -22,7 +22,7 @@ $delete_event_queries, $update_event_query, $newline_regexp, $wildcard_calendar_owners_query, $wildcard_calendar_owners_of_type_query, $wildcard_calendar_readers_of_type_query, - $wildcard_calendar_writers_of_type_query; + $wildcard_calendar_writers_of_type_query, $all_public_calendars_query; // cal_dsn @@ -78,6 +78,22 @@ + // all_public_calendars_query + // + // The SQL query that will grap all public calendars. For a + // single-domain install, this can simply query for all public + // calendars (previous default). Hosts of multiple domains will + // most likely wish to limit the query to return only public + // calendars for the user's domain rather than all domains. + // + // %1 in this query will be replaced with the user's domain + // %2 in this query will be replaced with the internal + // calendar type for public calendars. + // + $all_public_calendars_query = 'SELECT id FROM calendars WHERE domain = \'%1\' AND type = \'%2\''; + + + // owned_calendars_query // // The SQL query that will grab all calendars the the given user owns. Cheers, -- Casey Allen Shobe | cs...@se... | 206-381-2800 SeattleServer.com, Inc. | http://www.seattleserver.com |