$GLOBALS['notification']->push(sprintf(_("There was an error editing the event: %s"), $e->getMessage()), 'horde.error');
}
$tagger = Kronolith::getTagger();
- $tagger->replaceTags($event->uid, Horde_Util::getFormData('tags'));
+ $tagger->replaceTags($event->uid, Horde_Util::getFormData('tags'), $event->creator);
Kronolith::notifyOfResourceRejection($event);
}
$content = array('id' => $post['resource'], 'type' => $post['type']);
$tags = rawurldecode($post['tags']);
- // Check perms
+ // Check perms only calendar owners may tag a calendar, only event
+ // creator can tag an event.
if ($post['type'] == 'calendar') {
$cal = $GLOBALS['kronolith_shares']->getShare($post['resource']);
- $perm = $cal->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT);
+ $owner = $cal->get('owner');
} elseif($post['type'] == 'event') {
$event = Kronolith::getDriver()->getByUID($post['resource']);
- $perm = $event->hasPermission(Horde_Perms::EDIT, Horde_Auth::getAuth());
+ $owner = $event->creator;
}
+ // $owner is null for system-owned shares, so an admin has perms,
+ // otherwise, make sure the resource owner is the current user
+ $perm = empty($owner) ? Horde_Auth::isAdmin() : $owner == Horde_Auth::getAuth();
+
if ($perm) {
- /* Get the resource owner */
$tagger = Kronolith::getTagger();
switch ($request) {
case 'add':
- $tagger->tag($post['resource'], $tags, $post['type']);
+ $tagger->tag($post['resource'], $tags, $owner, $post['type']);
break;
case 'remove':
$tagger->untag($post['resource'], (int)$tags, $post['type']);
/* Deal with tags */
$tagger = Kronolith::getTagger();
if (!empty($edit)) {
- $tagger->replaceTags($event->uid, $event->tags, 'event');
+ $tagger->replaceTags($event->uid, $event->tags, $event->creator, 'event');
} else {
- $tagger->tag($event->uid, $event->tags, 'event');
+ $tagger->tag($event->uid, $event->tags, $event->creator, 'event');
}
/* Notify about the changed event. */
/* Update tags */
$tagger = Kronolith::getTagger();
- $tagger->replaceTags($event->uid, $event->tags, 'event');
+ $tagger->replaceTags($event->uid, $event->tags, $event->creator, 'event');
/* Update Geolocation */
if ($gDriver = Kronolith::getGeoDriver()) {
/* Deal with any tags */
$tagger = Kronolith::getTagger();
- $tagger->tag($event->uid, $event->tags, 'event');
+ $tagger->tag($event->uid, $event->tags, $event->creator, 'event');
/* Update Geolocation */
if ($event->geoLocation && $gDriver = Kronolith::getGeoDriver()) {
/* Remove any tags */
$tagger = Kronolith::getTagger();
- $tagger->replaceTags($event->uid, array(), 'event');
+ $tagger->replaceTags($event->uid, array(), $event->creator, 'event');
/* Remove any geolocation data */
if ($gDriver = Kronolith::getGeoDriver()) {
$calendar->set('owner', null);
}
$tagger = self::getTagger();
- $tagger->tag($calendar->getName(), $info['tags'], 'calendar');
+ $tagger->tag($calendar->getName(), $info['tags'], $calendar->get('owner'), 'calendar');
$result = $GLOBALS['kronolith_shares']->addShare($calendar);
if ($result instanceof PEAR_Error) {
}
$tagger = self::getTagger();
- $tagger->replaceTags($calendar->getName(), $info['tags'], 'calendar');
+ $tagger->replaceTags($calendar->getName(), $info['tags'], $calendar->get('owner'), 'calendar');
}
/**
protected $_tagger;
/**
- * Constructor - needs to instantiate the Content_Tagger object if it's not
- * already present.
+ * Const'r
+ *
+ * @return Kronolith_Tagger
*/
public function __construct()
{
*
* @param string $localId The identifier of the kronolith object.
* @param mixed $tags Either a single tag string or an array of tags.
+ * @param string $owner The tag owner (should normally be the owner of the resource).
* @param string $content_type The type of object we are tagging (event/calendar).
*
* @return void
*/
- public function tag($localId, $tags, $content_type = 'event')
+ public function tag($localId, $tags, $owner, $content_type = 'event')
{
// If we don't have an array - split the string.
if (!is_array($tags)) {
$tags = $this->_tagger->splitTags($tags);
}
- $this->_tagger->tag(Horde_Auth::getAuth(),
+ $this->_tagger->tag($owner,
array('object' => $localId,
'type' => $this->_type_ids[$content_type]),
$tags);
*
* @param string $localId The identifier for the kronolith object.
* @param mixed $tags Either a tag_id, tag_name, or array of tag_ids.
+ * @param string $owner The tag owner - should normally be the resource owner.
* @param $content_type The type of object that $localId represents.
*
* @return void
*/
- public function replaceTags($localId, $tags, $content_type = 'event')
+ public function replaceTags($localId, $tags, $owner, $content_type = 'event')
{
// First get a list of existing tags.
$existing_tags = $this->getTags($localId, $content_type);
foreach ($existing_tags as $tag_id => $existing_tag) {
$found = false;
foreach ($tags as $tag_text) {
- //if ($existing_tag == Horde_String::lower($tag_text, true)) {
if ($existing_tag == $tag_text) {
$found = true;
break;
}
}
- $this->tag($localId, $add, $content_type);
+ $this->tag($localId, $add, $owner, $content_type);
}
/**