diff --git a/OpenChange/MAPIStoreGCSMessage.h b/OpenChange/MAPIStoreGCSMessage.h index cac182874..2cfd480d0 100644 --- a/OpenChange/MAPIStoreGCSMessage.h +++ b/OpenChange/MAPIStoreGCSMessage.h @@ -23,6 +23,8 @@ #ifndef MAPISTOREGCSMESSAGE_H #define MAPISTOREGCSMESSAGE_H +#import + #import "MAPIStoreMessage.h" @interface MAPIStoreGCSMessage : MAPIStoreMessage @@ -30,6 +32,11 @@ } /* subclass helpers */ + +/* Return the message original creator */ +- (NSString *) creator; +- (NSString *) owner; +- (SOGoUser *) ownerUser; - (void) updateVersions; @end diff --git a/OpenChange/MAPIStoreGCSMessage.m b/OpenChange/MAPIStoreGCSMessage.m index 97898ae50..e1792fbdf 100644 --- a/OpenChange/MAPIStoreGCSMessage.m +++ b/OpenChange/MAPIStoreGCSMessage.m @@ -20,10 +20,12 @@ * Boston, MA 02111-1307, USA. */ +#import #import #import #import #import +#import #import #import #import @@ -35,6 +37,7 @@ #import "MAPIStoreTypes.h" #import "MAPIStoreUserContext.h" #import "NSData+MAPIStore.h" +#import "NSString+MAPIStore.h" #import "MAPIStoreGCSMessage.h" @@ -54,6 +57,24 @@ return [sogoObject lastModified]; } +- (enum mapistore_error) getPidTagCreatorName: (void **) data + inMemCtx: (TALLOC_CTX *) memCtx +{ + enum mapistore_error rc; + NSString *creator; + + creator = [self creator]; + if (creator) + { + *data = [creator asUnicodeInMemCtx: memCtx]; + rc = MAPISTORE_SUCCESS; + } + else + rc = MAPISTORE_ERR_NOT_FOUND; + + return rc; +} + - (enum mapistore_error) getPidTagChangeKey: (void **) data inMemCtx: (TALLOC_CTX *) memCtx { @@ -175,4 +196,69 @@ andPredecessorChangeList: predecessorChangeList]; } +//---------------------- +// Sharing +//---------------------- + +- (NSString *) creator +{ + return [self owner]; +} + +- (NSString *) owner +{ + return [sogoObject ownerInContext: nil]; +} + +- (SOGoUser *) ownerUser +{ + NSString *ownerName; + SOGoUser *owner = nil; + + ownerName = [self owner]; + if ([ownerName length] != 0) + owner = [SOGoUser userWithLogin: ownerName]; + + return owner; +} + +- (BOOL) subscriberCanModifyMessage +{ + BOOL rc; + NSArray *roles; + + roles = [self activeUserRoles]; + + if (isNew) + rc = [roles containsObject: SOGoRole_ObjectCreator]; + else + rc = [roles containsObject: SOGoRole_ObjectEditor]; + + /* Check if the message is owned and it has permission to edit it */ + if (!rc && [roles containsObject: MAPIStoreRightEditOwn]) + rc = [[[container context] activeUser] isEqual: [self ownerUser]]; + + return rc; +} + +- (BOOL) subscriberCanDeleteMessage +{ + BOOL rc; + NSArray *roles; + + roles = [self activeUserRoles]; + rc = [roles containsObject: SOGoRole_ObjectEraser]; + + /* Check if the message is owned and it has permission to delete it */ + if (!rc && [roles containsObject: MAPIStoreRightDeleteOwn]) + { + NSString *currentUser; + + currentUser = [[container context] activeUser]; + rc = [currentUser isEqual: [self ownerUser]]; + } + + return rc; +} + @end