From 4d17ed2f71c8cbb0d34c039aa7953b2427ce5c78 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 25 Jul 2012 16:33:08 -0400 Subject: Make file actions permissions aware --- apps/calendar/js/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/calendar') diff --git a/apps/calendar/js/loader.js b/apps/calendar/js/loader.js index cef95afc3aa..57cf5adff0e 100644 --- a/apps/calendar/js/loader.js +++ b/apps/calendar/js/loader.js @@ -75,7 +75,7 @@ Calendar_Import={ } $(document).ready(function(){ if(typeof FileActions !== 'undefined'){ - FileActions.register('text/calendar','importcal', '', Calendar_Import.importdialog); + FileActions.register('text/calendar','importcal', FileActions.PERMISSION_READ, '', Calendar_Import.importdialog); FileActions.setDefault('text/calendar','importcal'); }; }); -- cgit v1.2.3 From 9580d0ef290c5ba2431e6c2c52c7a6d660b031ec Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 7 Aug 2012 14:57:52 -0400 Subject: Initial calendar sharing backend --- apps/calendar/appinfo/app.php | 2 + apps/calendar/lib/share/calendar.php | 58 ++++++++++++++++++++++ .../templates/part.choosecalendar.rowfields.php | 2 +- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 apps/calendar/lib/share/calendar.php (limited to 'apps/calendar') diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php index 4fdba291262..8a793d1fac2 100644 --- a/apps/calendar/appinfo/app.php +++ b/apps/calendar/appinfo/app.php @@ -10,6 +10,7 @@ OC::$CLASSPATH['OC_Calendar_Share'] = 'apps/calendar/lib/share.php'; OC::$CLASSPATH['OC_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php'; OC::$CLASSPATH['OC_Calendar_Export'] = 'apps/calendar/lib/export.php'; OC::$CLASSPATH['OC_Calendar_Import'] = 'apps/calendar/lib/import.php'; +OC::$CLASSPATH['OC_Share_Backend_Calendar'] = 'apps/calendar/lib/share/calendar.php'; //General Hooks OCP\Util::connectHook('OC_User', 'post_createUser', 'OC_Calendar_Hooks', 'createUser'); OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser'); @@ -35,3 +36,4 @@ OCP\App::addNavigationEntry( array( 'name' => $l->t('Calendar'))); OCP\App::registerPersonal('calendar', 'settings'); OC_Search::registerProvider('OC_Search_Provider_Calendar'); +OCP\Share::registerBackend('calendar', 'OC_Share_Backend_Calendar'); diff --git a/apps/calendar/lib/share/calendar.php b/apps/calendar/lib/share/calendar.php new file mode 100644 index 00000000000..9b68437531f --- /dev/null +++ b/apps/calendar/lib/share/calendar.php @@ -0,0 +1,58 @@ +. +*/ + +class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection { + + const FORMAT_CALENDAR = 0; + + private static $calendar; + + public function isValidSource($itemSource, $uidOwner) { + if (self::$calendar = OC_Calendar_App::getCalendar($itemSource)) { + return true; + } + return false; + } + + public function generateTarget($itemSource, $shareWith, $exclude = null) { + if (isset(self::$calendar)) { + return self::$calendar['displayname']; + } + return false; + } + + public function formatItems($items, $format, $parameters = null) { + $calendars = array(); + if ($format == self::FORMAT_CALENDAR) { + foreach ($items as $item) { + $calendar = OC_Calendar_App::getCalendar($item['item_source']); + $calendar['displaynamename'] = $item['item_target']; + $calendars[] = $calendar; + } + } + return $calendars; + } + + public function getChildren($itemSource) { + // TODO + } + +} \ No newline at end of file diff --git a/apps/calendar/templates/part.choosecalendar.rowfields.php b/apps/calendar/templates/part.choosecalendar.rowfields.php index d29113c9a61..64aaa797197 100644 --- a/apps/calendar/templates/part.choosecalendar.rowfields.php +++ b/apps/calendar/templates/part.choosecalendar.rowfields.php @@ -5,7 +5,7 @@ - + -- cgit v1.2.3 From 1e644b5a53856b2b4e2310e96ce6155fe32982d9 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 7 Aug 2012 23:27:06 +0200 Subject: Add Event share backend --- apps/calendar/appinfo/app.php | 2 ++ apps/calendar/lib/share/event.php | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 apps/calendar/lib/share/event.php (limited to 'apps/calendar') diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php index 8a793d1fac2..72ddde60152 100644 --- a/apps/calendar/appinfo/app.php +++ b/apps/calendar/appinfo/app.php @@ -11,6 +11,7 @@ OC::$CLASSPATH['OC_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php'; OC::$CLASSPATH['OC_Calendar_Export'] = 'apps/calendar/lib/export.php'; OC::$CLASSPATH['OC_Calendar_Import'] = 'apps/calendar/lib/import.php'; OC::$CLASSPATH['OC_Share_Backend_Calendar'] = 'apps/calendar/lib/share/calendar.php'; +OC::$CLASSPATH['OC_Share_Backend_Event'] = 'apps/calendar/lib/share/event.php'; //General Hooks OCP\Util::connectHook('OC_User', 'post_createUser', 'OC_Calendar_Hooks', 'createUser'); OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser'); @@ -37,3 +38,4 @@ OCP\App::addNavigationEntry( array( OCP\App::registerPersonal('calendar', 'settings'); OC_Search::registerProvider('OC_Search_Provider_Calendar'); OCP\Share::registerBackend('calendar', 'OC_Share_Backend_Calendar'); +OCP\Share::registerBackend('event', 'OC_Share_Backend_Event'); diff --git a/apps/calendar/lib/share/event.php b/apps/calendar/lib/share/event.php new file mode 100644 index 00000000000..5bb72ee6c98 --- /dev/null +++ b/apps/calendar/lib/share/event.php @@ -0,0 +1,40 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class OC_Share_Backend_Event implements OCP\Share_Backend { + + const FORMAT_EVENT = 0; + + private static $event; + + public function isValidSource($itemSource, $uidOwner) { + self::$event = OC_Calendar_Object::find($itemSource); + if (self::$event) { + return true; + } + return false; + } + + public function generateTarget($itemSource, $shareWith, $exclude = null) { + // TODO Get default calendar and check for conflicts + return self::$event['summary']; + } + + public function formatItems($items, $format, $parameters = null) { + $events = array(); + if ($format == self::FORMAT_EVENT) { + foreach ($items as $item) { + $event = OC_Calendar_Object::find($item['item_source']); + $event['summary'] = $item['item_target']; + $events[] = $event; + } + } + return $events; + } + +} -- cgit v1.2.3 From 35a1738a39fbce50ec22561a0308d9a672eb6c78 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 7 Aug 2012 23:31:06 +0200 Subject: Use new sharing API in OC_Calendar_Share::allSharedwithuser --- apps/calendar/lib/share.php | 21 +++++++++------------ apps/calendar/lib/share/calendar.php | 8 +++++++- 2 files changed, 16 insertions(+), 13 deletions(-) (limited to 'apps/calendar') diff --git a/apps/calendar/lib/share.php b/apps/calendar/lib/share.php index 4fe88171403..e5ffc04143a 100644 --- a/apps/calendar/lib/share.php +++ b/apps/calendar/lib/share.php @@ -18,19 +18,16 @@ class OC_Calendar_Share{ * @return: array $return - information about calendars */ public static function allSharedwithuser($userid, $type, $active=null, $permission=null){ - $group_where = self::group_sql(OC_Group::getUserGroups($userid)); - $permission_where = self::permission_sql($permission); - if($type == self::CALENDAR){ - $active_where = self::active_sql($active); - }else{ - $active_where = ''; - } - $stmt = OCP\DB::prepare("SELECT * FROM *PREFIX*calendar_share_" . $type . " WHERE ((share = ? AND sharetype = 'user') " . $group_where . ") AND owner <> ? " . $permission_where . " " . $active_where); - $result = $stmt->execute(array($userid, $userid)); - $return = array(); - while( $row = $result->fetchRow()){ - $return[] = $row; + $format = OC_Share_Backend_Calendar::FORMAT_CALENDAR; + if ($type == self::EVENT) { + $format = OC_Share_Backend_Event::FORMAT_EVENT; } + $return = OCP\Share::getItemsSharedWith($type, + $format, + array( + 'active' => $active, + 'permissions' => $permission, + )); return $return; } /** diff --git a/apps/calendar/lib/share/calendar.php b/apps/calendar/lib/share/calendar.php index 9b68437531f..0ddca2400a9 100644 --- a/apps/calendar/lib/share/calendar.php +++ b/apps/calendar/lib/share/calendar.php @@ -43,8 +43,14 @@ class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection { $calendars = array(); if ($format == self::FORMAT_CALENDAR) { foreach ($items as $item) { - $calendar = OC_Calendar_App::getCalendar($item['item_source']); + $calendar = OC_Calendar_App::getCalendar($item['item_source'], false); + // TODO: really check $parameters['permissions'] == 'rw'/'r' + if ($parameters['permissions'] == 'rw') { + continue; // TODO + } $calendar['displaynamename'] = $item['item_target']; + $calendar['calendarid'] = $calendar['id']; + $calendar['owner'] = $calendar['userid']; $calendars[] = $calendar; } } -- cgit v1.2.3 From fb493c45dd4ecadeaa5b1b112a156054318af0a2 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 10 Aug 2012 14:36:41 +0200 Subject: Calendar: update share backend using contacts backend as template --- apps/calendar/lib/share/calendar.php | 69 ++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 11 deletions(-) (limited to 'apps/calendar') diff --git a/apps/calendar/lib/share/calendar.php b/apps/calendar/lib/share/calendar.php index 0ddca2400a9..7f498292419 100644 --- a/apps/calendar/lib/share/calendar.php +++ b/apps/calendar/lib/share/calendar.php @@ -4,6 +4,7 @@ * * @author Michael Gapczynski * @copyright 2012 Michael Gapczynski mtgap@owncloud.com +* Copyright (c) 2012 Bart Visscher * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -20,25 +21,65 @@ */ class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection { + const FORMAT_CALENDAR = 1; - const FORMAT_CALENDAR = 0; - - private static $calendar; - + /** + * @brief Get the source of the item to be stored in the database + * @param string Item + * @param string Owner of the item + * @return mixed|array|false Source + * + * Return an array if the item is file dependent, the array needs two keys: 'item' and 'file' + * Return false if the item does not exist for the user + * + * The formatItems() function will translate the source returned back into the item + */ public function isValidSource($itemSource, $uidOwner) { - if (self::$calendar = OC_Calendar_App::getCalendar($itemSource)) { - return true; + $calendar = OC_Calendar_App::getCalendar( $itemSource ); + if ($calendar || $calendar['userid'] != $uidOwner) { + return false; } - return false; + return true; } + /** + * @brief Get a unique name of the item for the specified user + * @param string Item + * @param string|false User the item is being shared with + * @param array|null List of similar item names already existing as shared items + * @return string Target name + * + * This function needs to verify that the user does not already have an item with this name. + * If it does generate a new name e.g. name_# + */ public function generateTarget($itemSource, $shareWith, $exclude = null) { - if (isset(self::$calendar)) { - return self::$calendar['displayname']; + $calendar = OC_Calendar_App::getCalendar( $itemSource ); + $user_calendars = array(); + foreach(OC_Contacts_Addressbook::all($uid) as $user_calendar) { + $user_calendars[] = $user_calendar['displayname']; } - return false; + $name = $calendar['userid']."'s ".$calendar['displayname']; + $suffix = ''; + while (in_array($name.$suffix, $user_calendars)) { + $suffix++; + } + + return $name.$suffix; } + /** + * @brief Converts the shared item sources back into the item in the specified format + * @param array Shared items + * @param int Format + * @return ? + * + * The items array is a 3-dimensional array with the item_source as the first key and the share id as the second key to an array with the share info. + * The key/value pairs included in the share info depend on the function originally called: + * If called by getItem(s)Shared: id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source + * If called by getItem(s)SharedWith: id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target + * This function allows the backend to control the output of shared items with custom formats. + * It is only called through calls to the public getItem(s)Shared(With) functions. + */ public function formatItems($items, $format, $parameters = null) { $calendars = array(); if ($format == self::FORMAT_CALENDAR) { @@ -58,7 +99,13 @@ class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection { } public function getChildren($itemSource) { - // TODO + $query = OCP\DB::prepare('SELECT id FROM *PREFIX*calendar_objects WHERE calendarid = ?'); + $result = $query->execute(array($itemSource)); + $sources = array(); + while ($object = $result->fetchRow()) { + $sources[] = $object['id']; + } + return $sources; } } \ No newline at end of file -- cgit v1.2.3