]> err.no Git - scalable-opengroupware.org/blobdiff - SoObjects/Appointments/SOGoCalendarComponent.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1263 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / Appointments / SOGoCalendarComponent.m
index 15242ccf9771446fbad40c24af9c976d30e461e0..72cb73c3b8da8ce6b8cc974b9348855b32fed441 100644 (file)
  */
 
 #import <Foundation/NSString.h>
-
+#import <Foundation/NSUserDefaults.h>
+
+#import <NGObjWeb/NSException+HTTP.h>
+#import <NGObjWeb/SoSecurityManager.h>
+#import <NGObjWeb/WOApplication.h>
+#import <NGObjWeb/WOContext+SoObjects.h>
+#import <NGExtensions/NSObject+Logs.h>
+#import <NGExtensions/NGHashMap.h>
 #import <NGCards/iCalCalendar.h>
 #import <NGCards/iCalPerson.h>
 #import <NGCards/iCalRepeatableEntityObject.h>
-#import <NGMime/NGMime.h>
-#import <NGMail/NGMail.h>
-#import <NGMail/NGSendMail.h>
+#import <NGMime/NGMimeBodyPart.h>
+#import <NGMime/NGMimeMultipartBody.h>
+#import <NGMail/NGMimeMessage.h>
 
+#import <SoObjects/SOGo/iCalEntityObject+Utilities.h>
 #import <SoObjects/SOGo/LDAPUserManager.h>
+#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
+#import <SoObjects/SOGo/SOGoMailer.h>
 #import <SoObjects/SOGo/SOGoPermissions.h>
 #import <SoObjects/SOGo/SOGoUser.h>
 #import <SoObjects/Appointments/SOGoAppointmentFolder.h>
 
-#import "common.h"
-
 #import "SOGoAptMailNotification.h"
 #import "iCalEntityObject+SOGo.h"
 #import "SOGoCalendarComponent.h"
 
-static NSString *mailTemplateDefaultLanguage = nil;
 static BOOL sendEMailNotifications = NO;
 
 @implementation SOGoCalendarComponent
@@ -55,11 +62,6 @@ static BOOL sendEMailNotifications = NO;
       didInit = YES;
   
       ud = [NSUserDefaults standardUserDefaults];
-      mailTemplateDefaultLanguage = [[ud stringForKey:@"SOGoDefaultLanguage"]
-                                      retain];
-      if (!mailTemplateDefaultLanguage)
-        mailTemplateDefaultLanguage = @"English";
-
       sendEMailNotifications
         = [ud boolForKey: @"SOGoAppointmentSendEMailNotifications"];
     }
@@ -71,7 +73,6 @@ static BOOL sendEMailNotifications = NO;
     {
       calendar = nil;
       calContent = nil;
-      isNew = NO;
     }
 
   return self;
@@ -112,23 +113,38 @@ static BOOL sendEMailNotifications = NO;
 
 - (NSString *) contentAsString
 {
-  NSString *uid;
   iCalCalendar *tmpCalendar;
   iCalRepeatableEntityObject *tmpComponent;
-  NSArray *roles;
+//   NSArray *roles;
+//   NSString *uid;
+  SoSecurityManager *sm;
 
   if (!calContent)
     {
-      uid = [[context activeUser] login];
-      roles = [self aclsForUser: uid];
-      if ([roles containsObject: SOGoCalendarRole_Organizer]
-         || [roles containsObject: SOGoCalendarRole_Participant]
-         || [roles containsObject: SOGoCalendarRole_ComponentViewer])
-       {
-         calContent = content;
-         [calContent retain];
-       }
-      else if ([roles containsObject: SOGoCalendarRole_ComponentDAndTViewer])
+//       uid = [[context activeUser] login];
+//       roles = [self aclsForUser: uid];
+//       if ([roles containsObject: SOGoCalendarRole_Organizer]
+//       || [roles containsObject: SOGoCalendarRole_Participant]
+//       || [roles containsObject: SOGoCalendarRole_ComponentViewer])
+//     calContent = content;
+//       else if ([roles containsObject: SOGoCalendarRole_ComponentDAndTViewer])
+//     {
+//       tmpCalendar = [[self calendar: NO] copy];
+//       tmpComponent = (iCalRepeatableEntityObject *)
+//         [tmpCalendar firstChildWithTag: [self componentTag]];
+//       [self _filterComponent: tmpComponent];
+//       calContent = [tmpCalendar versitString];
+//       [tmpCalendar release];
+//     }
+//       else
+//     calContent = nil;
+
+      sm = [SoSecurityManager sharedSecurityManager];
+      if (![sm validatePermission: SOGoCalendarPerm_ViewAllComponent
+              onObject: self inContext: context])
+       calContent = content;
+      else if (![sm validatePermission: SOGoCalendarPerm_ViewDAndT
+                   onObject: self inContext: context])
        {
          tmpCalendar = [[self calendar: NO] copy];
          tmpComponent = (iCalRepeatableEntityObject *)
@@ -146,21 +162,28 @@ static BOOL sendEMailNotifications = NO;
   return calContent;
 }
 
-- (NSException *) saveContentString: (NSString *) contentString
-                        baseVersion: (unsigned int) baseVersion
+- (void) setContentString: (NSString *) newContent
 {
-  NSException *result;
+  [super setContentString: newContent];
+  ASSIGN (calendar, nil);
+  ASSIGN (calContent, nil);
+}
 
-  result = [super saveContentString: contentString
-                  baseVersion: baseVersion];
-  if (!result && calContent)
-    {
-      [calContent release];
-      calContent = nil;
-    }
+// - (NSException *) saveContentString: (NSString *) contentString
+//                         baseVersion: (unsigned int) baseVersion
+// {
+//   NSException *result;
+
+//   result = [super saveContentString: contentString
+//                   baseVersion: baseVersion];
+//   if (!result && calContent)
+//     {
+//       [calContent release];
+//       calContent = nil;
+//     }
 
-  return result;
-}
+//   return result;
+// }
 
 - (iCalCalendar *) calendar: (BOOL) create
 {
@@ -183,7 +206,6 @@ static BOOL sendEMailNotifications = NO;
               newComponent = [[calendar classForTag: componentTag]
                                groupWithTag: componentTag];
               [calendar addChild: newComponent];
-             isNew = YES;
             }
         }
       if (calendar)
@@ -200,11 +222,6 @@ static BOOL sendEMailNotifications = NO;
                                     firstChildWithTag: [self componentTag]];
 }
 
-- (BOOL) isNew
-{
-  return isNew;
-}
-
 /* raw saving */
 
 - (NSException *) primarySaveContentString: (NSString *) _iCalString
@@ -226,7 +243,7 @@ static BOOL sendEMailNotifications = NO;
 
 - (NSException *) delete
 {
-  return [self deleteWithBaseSequence:0];
+  return [self deleteWithBaseSequence: 0];
 }
 
 /* EMail Notifications */
@@ -259,14 +276,12 @@ static BOOL sendEMailNotifications = NO;
   iCalPerson *person;
   NSString *newContent;
   NSException *ex;
-  NSString *myEMail;
   
   ex = nil;
 
   component = [self component: NO];
   if (component)
     {
-      myEMail = [[context activeUser] primaryEmail];
       person = [self findParticipantWithUID: owner];
       if (person)
         {
@@ -321,13 +336,12 @@ static BOOL sendEMailNotifications = NO;
   NSString *pageName;
   iCalPerson *organizer;
   NSString *cn, *email, *sender, *iCalString;
-  NGSendMail *sendmail;
   WOApplication *app;
   unsigned i, count;
   iCalPerson *attendee;
-  NSString *recipient;
+  NSString *recipient, *language;
   SOGoAptMailNotification *p;
-  NSString *subject, *text, *header;
+  NSString *mailDate, *subject, *text, *header;
   NGMutableHashMap *headerMap;
   NGMimeMessage *msg;
   NGMimeBodyPart *bodyPart;
@@ -349,9 +363,6 @@ static BOOL sendEMailNotifications = NO;
       /* generate iCalString once */
       iCalString = [[_newObject parent] versitString];
   
-      /* get sendmail object */
-      sendmail = [NGSendMail sharedSendMail];
-
       /* get WOApplication instance */
       app = [WOApplication application];
 
@@ -371,12 +382,13 @@ static BOOL sendEMailNotifications = NO;
           else
             recipient = email;
 
-#warning this could be optimized in a class hierarchy common with the \
-          SOGoObject's acl notification mechanism
+         language = [[context activeUser] language];
+#warning this could be optimized in a class hierarchy common with the  \
+          SOGoObject acl notification mechanism
           /* create page name */
           // TODO: select user's default language?
           pageName = [NSString stringWithFormat: @"SOGoAptMail%@%@",
-                               mailTemplateDefaultLanguage,
+                               language,
                                _pageName];
           /* construct message content */
           p = [app pageWithName: pageName inContext: context];
@@ -398,7 +410,8 @@ static BOOL sendEMailNotifications = NO;
           [headerMap setObject: @"multipart/mixed" forKey: @"content-type"];
           [headerMap setObject: sender forKey: @"From"];
           [headerMap setObject: recipient forKey: @"To"];
-          [headerMap setObject: [NSCalendarDate date] forKey: @"date"];
+         mailDate = [[NSCalendarDate date] rfc822DateString];
+          [headerMap setObject: mailDate forKey: @"date"];
           [headerMap setObject: subject forKey: @"Subject"];
           msg = [NGMimeMessage messageWithHeader: headerMap];
 
@@ -432,13 +445,19 @@ static BOOL sendEMailNotifications = NO;
           [body release];
 
           /* send the damn thing */
-          [sendmail sendMimePart: msg
-                    toRecipients: [NSArray arrayWithObject: email]
-                    sender: [organizer rfc822Email]];
+          [[SOGoMailer sharedMailer]
+           sendMimePart: msg
+           toRecipients: [NSArray arrayWithObject: email]
+           sender: [organizer rfc822Email]];
         }
     }
 }
 
+- (void) sendResponseToOrganizer
+{
+#warning THIS IS A STUB  
+}
+
 // - (BOOL) isOrganizerOrOwner: (SOGoUser *) user
 // {
 //   BOOL isOrganizerOrOwner;
@@ -458,33 +477,13 @@ static BOOL sendEMailNotifications = NO;
 
 - (iCalPerson *) findParticipantWithUID: (NSString *) uid
 {
+  iCalEntityObject *component;
   SOGoUser *user;
 
   user = [SOGoUser userWithLogin: uid roles: nil];
-
-  return [self findParticipant: user];
-}
-
-- (iCalPerson *) findParticipant: (SOGoUser *) user
-{
-  iCalPerson *participant, *currentParticipant;
-  iCalEntityObject *component;
-  NSEnumerator *participants;
-
-  participant = nil;
   component = [self component: NO];
-  if (component)
-    {
-      participants = [[component participants] objectEnumerator];
-      currentParticipant = [participants nextObject];
-      while (currentParticipant && !participant)
-       if ([user hasEmail: [currentParticipant rfc822Email]])
-         participant = currentParticipant;
-       else
-         currentParticipant = [participants nextObject];
-    }
 
-  return participant;
+  return [component findParticipant: user];
 }
 
 - (iCalPerson *) iCalPersonWithUID: (NSString *) uid
@@ -561,7 +560,7 @@ static BOOL sendEMailNotifications = NO;
     }
   else
     role = SOGoCalendarRole_Organizer;
-  
+
   return role;
 }
 
@@ -614,9 +613,6 @@ static BOOL sendEMailNotifications = NO;
        [roles addObject: SOGoCalendarRole_Organizer];
     }
 
-  NSLog (@"all roles: %@" , roles);
-//     }
-
   return roles;
 }