Skip to content
This repository has been archived by the owner on Oct 31, 2018. It is now read-only.

Added calendar-user preferences. #288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ajax/calendar/activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
OCP\JSON::callCheck();

$calendarid = $_POST['calendarid'];
$calendar = OC_Calendar_App::getCalendar($calendarid, true);
$calendar = OC_Calendar_App::getCalendar($calendarid, true, true);
if(!$calendar) {
OCP\JSON::error(array('message'=>'permission denied'));
exit;
Expand All @@ -25,7 +25,8 @@
exit;
}

$calendar = OC_Calendar_App::getCalendar($calendarid);
// We can skip security here, because we just checked it above.
$calendar = OC_Calendar_App::getCalendar($calendarid, false);
OCP\JSON::success(array(
'active' => $calendar['active'],
'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar),
Expand Down
6 changes: 3 additions & 3 deletions ajax/calendar/new.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
OCP\JSON::error(array('message'=>'empty'));
exit;
}
$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
foreach($calendars as $cal) {
if($cal['displayname'] == $_POST['name']) {
$calendar_names = OC_Calendar_Calendar::getCalendarDisplayNames(OCP\USER::getUser());
foreach($calendar_names as $calname) {
if($calname == $_POST['name']) {
OCP\JSON::error(array('message'=>'namenotavailable'));
exit;
}
Expand Down
20 changes: 12 additions & 8 deletions ajax/calendar/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@
OCP\JSON::error(array('message'=>'empty'));
exit;
}
$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
foreach($calendars as $cal) {
if($cal['userid'] != OCP\User::getUser()){
continue;
}
if($cal['displayname'] == $_POST['name'] && $cal['id'] != $_POST['id']) {
$calendar_names = OC_Calendar_Calendar::getCalendarDisplayNames(OCP\USER::getUser());
foreach($calendar_names as $calid => $calname) {
if($calname == $_POST['name'] && $calid != $_POST['id']) {
OCP\JSON::error(array('message'=>'namenotavailable'));
exit;
}
}

$calendarid = $_POST['id'];

$calendar = OC_Calendar_Calendar::find($calendarid);
try {
OC_Calendar_Calendar::editCalendar($calendarid, strip_tags($_POST['name']), null, null, null, $_POST['color']);
OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']);
if ($calendar['userid'] == OCP\User::getUser()) {
// If the user owns the calendar, do a full edit so that default values are updated.
OC_Calendar_Calendar::editCalendar($calendarid, strip_tags($_POST['name']), null, null, null, $_POST['color']);
}
else {
// If the user does not own the calendar, only update the preferences.
OC_Calendar_Calendar::editCalendarPreferences($calendarid, strip_tags($_POST['name']), $_POST['color']);
}
} catch(Exception $e) {
OCP\JSON::error(array('message'=>$e->getMessage()));
exit;
Expand Down
5 changes: 5 additions & 0 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
//General Hooks
OCP\Util::connectHook('OC_User', 'post_createUser', 'OC_Calendar_Hooks', 'createUser');
OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser');
OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC_Calendar_Hooks', 'createShare');
OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC_Calendar_Hooks', 'postDeleteShare');
OCP\Util::connectHook('OC_User', 'post_addToGroup', 'OC_Calendar_Hooks', 'addToGroup');
OCP\Util::connectHook('OC_User', 'post_removeFromGroup', 'OC_Calendar_Hooks', 'postRemoveFromGroup');
OCP\Util::connectHook('OC_User', 'post_deleteGroup', 'OC_Calendar_Hooks', 'postDeleteGroup');
//Repeating Events Hooks
OCP\Util::connectHook('OC_Calendar', 'addEvent', 'OC_Calendar_Repeat', 'generate');
OCP\Util::connectHook('OC_Calendar', 'editEvent', 'OC_Calendar_Repeat', 'update');
Expand Down
72 changes: 64 additions & 8 deletions appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@
<length>255</length>
</field>

<field>
<name>active</name>
<type>integer</type>
<default>1</default>
<notnull>true</notnull>
<length>4</length>
</field>

<field>
<name>ctag</name>
<type>integer</type>
Expand Down Expand Up @@ -290,6 +282,70 @@

</table>

<table>

<name>*dbprefix*clndr_user_preferences</name>

<declaration>

<field>
<name>userid</name>
<type>text</type>
<notnull>true</notnull>
<length>255</length>
</field>

<field>
<name>calendarid</name>
<type>integer</type>
<default></default>
<notnull>true</notnull>
<unsigned>true</unsigned>
<length>11</length>
</field>

<field>
<name>key</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>

<field>
<name>value</name>
<type>clob</type>
<notnull>false</notnull>
</field>

<index>
<name>calendaruserkey</name>
<primary>true</primary>
<field>
<name>calendarid</name>
</field>
<field>
<name>userid</name>
</field>
<field>
<name>key</name>
</field>
</index>

<index>
<name>calendaruser</name>
<primary>false</primary>
<field>
<name>calendarid</name>
</field>
<field>
<name>userid</name>
</field>
</index>

</declaration>

</table>

<table>

<name>*dbprefix*clndr_repeat</name>
Expand Down
18 changes: 18 additions & 0 deletions appinfo/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,21 @@
session_regenerate_id(true);
OC_User::setUserId($user);
}
if (version_compare($installedVersion, '0.6.4', '<')) {
// We need to add default calendar-user preferences for three categories of calendar/user relationships:
// - Those where the user owns the calendar.
// - Those where the calendar is shared with the user.
// - Those where the calendar is shared with a group the user belongs to.
// We handle those categories for each of the three default preferences that need to be set.
// Perhaps this should simply make many calls to OC_Calendar_Calendar::setCalendarUserPreference()?
$stmt = OCP\DB::prepare( 'INSERT INTO `*PREFIX*clndr_user_preferences` (`userid`, `calendarid`, `key`, `value`)
SELECT * FROM
(
SELECT DISTINCT super.`userid`, super.`calendarid`, ?, 1 FROM (SELECT `userid`, `id` AS `calendarid` FROM `*PREFIX*clndr_calendars` UNION SELECT `share_with` AS `userid`, CAST(`item_source` AS integer) AS `calendarid` FROM `*PREFIX*share` WHERE `item_type`=? AND `share_type`=? UNION SELECT gu.`uid` AS `userid`, CAST(s.`item_source` AS integer) AS `calendarid` FROM `*PREFIX*share` s JOIN `*PREFIX*group_user` gu ON gu.`gid`=s.`share_with` WHERE s.`item_type`=? AND s.`share_type`=?) super JOIN `*PREFIX*clndr_calendars` cal ON cal.`id`=super.`calendarid`
UNION
SELECT DISTINCT super.`userid`, super.`calendarid`, ?, cal.`displayname` FROM (SELECT `userid`, `id` AS `calendarid` FROM `*PREFIX*clndr_calendars` UNION SELECT `share_with` AS `userid`, CAST(`item_source` AS integer) AS `calendarid` FROM `*PREFIX*share` WHERE `item_type`=? AND `share_type`=? UNION SELECT gu.`uid` AS `userid`, CAST(s.`item_source` AS integer) AS `calendarid` FROM `*PREFIX*share` s JOIN `*PREFIX*group_user` gu ON gu.`gid`=s.`share_with` WHERE s.`item_type`=? AND s.`share_type`=?) super JOIN `*PREFIX*clndr_calendars` cal ON cal.`id`=super.`calendarid`
UNION
SELECT DISTINCT super.`userid`, super.`calendarid`, ?, cal.`calendarcolor` FROM (SELECT `userid`, `id` AS `calendarid` FROM `*PREFIX*clndr_calendars` UNION SELECT `share_with` AS `userid`, CAST(`item_source` AS integer) AS `calendarid` FROM `*PREFIX*share` WHERE `item_type`=? AND `share_type`=? UNION SELECT gu.`uid` AS `userid`, CAST(s.`item_source` AS integer) AS `calendarid` FROM `*PREFIX*share` s JOIN `*PREFIX*group_user` gu ON gu.`gid`=s.`share_with` WHERE s.`item_type`=? AND s.`share_type`=?) super JOIN `*PREFIX*clndr_calendars` cal ON cal.`id`=super.`calendarid`
)' );
$stmt->execute(array('active', 'calendar', \OCP\Share::SHARE_TYPE_USER, 'calendar', \OCP\Share::SHARE_TYPE_GROUP, 'active', 'displayname', \OCP\Share::SHARE_TYPE_USER, 'calendar', \OCP\Share::SHARE_TYPE_GROUP, 'calendarcolor', 'calendar', \OCP\Share::SHARE_TYPE_USER, 'calendar', \OCP\Share::SHARE_TYPE_GROUP));
}
2 changes: 1 addition & 1 deletion appinfo/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.3
0.6.4
3 changes: 3 additions & 0 deletions js/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ Calendar={
}
}else{
$("#displayname_"+calendarid).css('background-color', '#FF2626');
if ($("#duplicate-calendar-name-"+calendarid).length == 0) {
$("#displayname_"+calendarid).after('<p id="duplicate-calendar-name-'+calendarid+'">Name not available.</p>');
}
$("#displayname_"+calendarid).focus(function(){
$("#displayname_"+calendarid).css('background-color', '#F8F8F8');
});
Expand Down
Loading