From d0b4b50456cf3e23aa12d5cf7165531a7670edf6 Mon Sep 17 00:00:00 2001 From: Hivert Quentin Date: Fri, 3 Nov 2023 18:20:12 +0100 Subject: [PATCH] feat(core): add SOGoDisableExport option to disable export for mail, calendar and contacts --- Documentation/SOGoInstallationGuide.asciidoc | 4 ++ SoObjects/SOGo/SOGoSystemDefaults.h | 1 + SoObjects/SOGo/SOGoSystemDefaults.m | 12 ++++ UI/Contacts/UIxContactFolderActions.m | 64 +++++++++++-------- UI/Contacts/UIxContactFoldersView.m | 14 ++++ UI/MailerUI/UIxMailFolderActions.m | 14 +++- UI/MailerUI/UIxMailMainFrame.m | 14 ++++ UI/Scheduler/UIxCalFolderActions.m | 28 +++++--- UI/Scheduler/UIxCalMainView.m | 14 ++++ .../ContactsUI/UIxContactFoldersView.wox | 12 ++-- UI/Templates/MailerUI/UIxMailMainFrame.wox | 12 ++-- UI/Templates/SchedulerUI/UIxCalMainView.wox | 12 ++-- 12 files changed, 152 insertions(+), 49 deletions(-) diff --git a/Documentation/SOGoInstallationGuide.asciidoc b/Documentation/SOGoInstallationGuide.asciidoc index fb5e0d74f..2adf306a3 100644 --- a/Documentation/SOGoInstallationGuide.asciidoc +++ b/Documentation/SOGoInstallationGuide.asciidoc @@ -696,6 +696,10 @@ Defaults to `NO` when unset. |S |SOGoDisableSharingAnyAuthUser |List of modules where sharing with any authenticated user option should be disabled, for example `(Mail, Calendar)`. Modules can be `Mail`, `Contacts` and `Calendar`. Default value empty list (sharing enabled for everybody). +|S |SOGoDisableExport +|List of modules where export should be disabled, for example `(Mail, Calendar)`. Modules can be `Mail`, `Contacts` and `Calendar`. Default value empty list (export enabled for everybody). + + |S |SOGoPasswordChangeEnabled |Parameter used to allow or not users to change their passwords from SOGo. diff --git a/SoObjects/SOGo/SOGoSystemDefaults.h b/SoObjects/SOGo/SOGoSystemDefaults.h index c435a9950..4ba556b76 100644 --- a/SoObjects/SOGo/SOGoSystemDefaults.h +++ b/SoObjects/SOGo/SOGoSystemDefaults.h @@ -131,6 +131,7 @@ NSComparisonResult languageSort(id el1, id el2, void *context); - (NSArray *) disableSharing; - (NSArray *) disableSharingAnyAuthUser; +- (NSArray *) disableExport; @end diff --git a/SoObjects/SOGo/SOGoSystemDefaults.m b/SoObjects/SOGo/SOGoSystemDefaults.m index b97e1896a..2b54f74af 100644 --- a/SoObjects/SOGo/SOGoSystemDefaults.m +++ b/SoObjects/SOGo/SOGoSystemDefaults.m @@ -832,5 +832,17 @@ NSComparisonResult languageSort(id el1, id el2, void *context) return disableSharingAnyAuthUser; } +- (NSArray *) disableExport +{ + static NSArray *disableExport = nil; + + if (!disableExport) + { + disableExport = [self stringArrayForKey: @"SOGoDisableExport"]; + [disableExport retain]; + } + + return disableExport; +} @end diff --git a/UI/Contacts/UIxContactFolderActions.m b/UI/Contacts/UIxContactFolderActions.m index f3e99f667..ff43664c0 100644 --- a/UI/Contacts/UIxContactFolderActions.m +++ b/UI/Contacts/UIxContactFolderActions.m @@ -19,6 +19,8 @@ 02111-1307, USA. */ +#import + #import #import #import @@ -78,35 +80,47 @@ static NSArray *photoTags = nil; id currentChild; SOGoContactGCSFolder *sourceFolder; NSMutableString *content; + SOGoSystemDefaults *sd; - content = [NSMutableString string]; - sourceFolder = [self clientObject]; - contactsId = [[[[context request] contentAsString] objectFromJSONString] objectForKey: @"uids"]; + sd = [SOGoSystemDefaults sharedSystemDefaults]; + if (nil != [sd disableExport] && NSNotFound != [[sd disableExport] indexOfObject: kDisableSharingContacts]) + { + response = [self responseWithStatus: 401 + andJSONRepresentation: [NSDictionary dictionaryWithObject: @"Exporting contacts folder is not authorized" + forKey: @"message"]]; - if (!contactsId) - contactsId = [sourceFolder toOneRelationshipKeys]; + } + else + { + content = [NSMutableString string]; + sourceFolder = [self clientObject]; + contactsId = [[[[context request] contentAsString] objectFromJSONString] objectForKey: @"uids"]; - uids = [contactsId objectEnumerator]; - while ((uid = [uids nextObject])) - { - currentChild = [sourceFolder lookupName: uid - inContext: [self context] - acquire: NO]; - if ([currentChild respondsToSelector: @selector (vCard)]) - [content appendFormat: @"%@", [[currentChild ldifRecord] ldifRecordAsString]]; - else if ([currentChild respondsToSelector: @selector (vList)]) - [content appendFormat: @"%@", [[currentChild vList] ldifString]]; - [content appendString: @"\n"]; - } + if (!contactsId) + contactsId = [sourceFolder toOneRelationshipKeys]; - response = [context response]; - [response setHeader: @"application/directory; charset=utf-8" - forKey: @"content-type"]; - filename = [NSString stringWithFormat: @"%@.ldif", - [[sourceFolder displayName] asQPSubjectString: @"utf-8"]]; - disposition = [NSString stringWithFormat: @"attachment; filename=\"%@\"", filename]; - [response setHeader: disposition forKey: @"Content-Disposition"]; - [response setContent: [content dataUsingEncoding: NSUTF8StringEncoding]]; + uids = [contactsId objectEnumerator]; + while ((uid = [uids nextObject])) + { + currentChild = [sourceFolder lookupName: uid + inContext: [self context] + acquire: NO]; + if ([currentChild respondsToSelector: @selector (vCard)]) + [content appendFormat: @"%@", [[currentChild ldifRecord] ldifRecordAsString]]; + else if ([currentChild respondsToSelector: @selector (vList)]) + [content appendFormat: @"%@", [[currentChild vList] ldifString]]; + [content appendString: @"\n"]; + } + + response = [context response]; + [response setHeader: @"application/directory; charset=utf-8" + forKey: @"content-type"]; + filename = [NSString stringWithFormat: @"%@.ldif", + [[sourceFolder displayName] asQPSubjectString: @"utf-8"]]; + disposition = [NSString stringWithFormat: @"attachment; filename=\"%@\"", filename]; + [response setHeader: disposition forKey: @"Content-Disposition"]; + [response setContent: [content dataUsingEncoding: NSUTF8StringEncoding]]; + } return response; } diff --git a/UI/Contacts/UIxContactFoldersView.m b/UI/Contacts/UIxContactFoldersView.m index 87ad98f0f..51f5dfc53 100644 --- a/UI/Contacts/UIxContactFoldersView.m +++ b/UI/Contacts/UIxContactFoldersView.m @@ -507,6 +507,20 @@ Class SOGoContactSourceFolderK, SOGoGCSFolderK; return result; } +- (BOOL) isContactExportEnabled { + BOOL result; + SOGoSystemDefaults *sd; + + result = YES; + sd = [SOGoSystemDefaults sharedSystemDefaults]; + if (nil != [sd disableExport] + && NSNotFound != [[sd disableExport] indexOfObject: kDisableSharingContacts]) { + result = NO; + } + + return result; +} + - (id) defaultAction { // NSString *check; diff --git a/UI/MailerUI/UIxMailFolderActions.m b/UI/MailerUI/UIxMailFolderActions.m index 64a0f7c6e..660b81a4b 100644 --- a/UI/MailerUI/UIxMailFolderActions.m +++ b/UI/MailerUI/UIxMailFolderActions.m @@ -590,8 +590,20 @@ - (WOResponse *) exportFolderAction { WOResponse *response; + SOGoSystemDefaults *sd; - response = [[self clientObject] archiveAllMessagesInContext: context]; + sd = [SOGoSystemDefaults sharedSystemDefaults]; + if (nil != [sd disableExport] && NSNotFound != [[sd disableExport] indexOfObject: kDisableSharingMail]) + { + response = [self responseWithStatus: 401 + andJSONRepresentation: [NSDictionary dictionaryWithObject: @"Exporting mail folder is not authorized" + forKey: @"message"]]; + + } + else + { + response = [[self clientObject] archiveAllMessagesInContext: context]; + } return response; } diff --git a/UI/MailerUI/UIxMailMainFrame.m b/UI/MailerUI/UIxMailMainFrame.m index caa4275aa..82dea706c 100644 --- a/UI/MailerUI/UIxMailMainFrame.m +++ b/UI/MailerUI/UIxMailMainFrame.m @@ -597,6 +597,20 @@ return result; } +- (BOOL) isMailExportEnabled { + BOOL result; + SOGoSystemDefaults *sd; + + result = YES; + sd = [SOGoSystemDefaults sharedSystemDefaults]; + if (nil != [sd disableExport] + && NSNotFound != [[sd disableExport] indexOfObject: kDisableSharingMail]) { + result = NO; + } + + return result; +} + @end /* UIxMailMainFrame */ @interface UIxMailFolderTemplate : UIxComponent diff --git a/UI/Scheduler/UIxCalFolderActions.m b/UI/Scheduler/UIxCalFolderActions.m index 86a9e057b..572e65afa 100644 --- a/UI/Scheduler/UIxCalFolderActions.m +++ b/UI/Scheduler/UIxCalFolderActions.m @@ -34,6 +34,7 @@ #import #import +#import #import #import @@ -47,15 +48,26 @@ WOResponse *response; SOGoAppointmentFolderICS *folderICS; NSString *disposition; + SOGoSystemDefaults *sd; - folderICS = [self clientObject]; - response = [self responseWithStatus: 200 - andString: [folderICS contentAsString]]; - [response setHeader: @"text/calendar; charset=utf-8" - forKey: @"content-type"]; - disposition = [NSString stringWithFormat: @"attachment; filename=\"%@.ics\"", - [[folderICS displayName] asQPSubjectString: @"utf-8"]]; - [response setHeader: disposition forKey: @"Content-Disposition"]; + sd = [SOGoSystemDefaults sharedSystemDefaults]; + if (nil != [sd disableExport] && NSNotFound != [[sd disableExport] indexOfObject: kDisableSharingCalendar]) + { + response = [self responseWithStatus: 401 + andJSONRepresentation: [NSDictionary dictionaryWithObject: @"Exporting calendar folder is not authorized" + forKey: @"message"]]; + } + else + { + folderICS = [self clientObject]; + response = [self responseWithStatus: 200 + andString: [folderICS contentAsString]]; + [response setHeader: @"text/calendar; charset=utf-8" + forKey: @"content-type"]; + disposition = [NSString stringWithFormat: @"attachment; filename=\"%@.ics\"", + [[folderICS displayName] asQPSubjectString: @"utf-8"]]; + [response setHeader: disposition forKey: @"Content-Disposition"]; + } return response; } diff --git a/UI/Scheduler/UIxCalMainView.m b/UI/Scheduler/UIxCalMainView.m index 450b7c14c..5616ecf71 100644 --- a/UI/Scheduler/UIxCalMainView.m +++ b/UI/Scheduler/UIxCalMainView.m @@ -376,6 +376,20 @@ return result; } +- (BOOL) isCalendarExportEnabled { + BOOL result; + SOGoSystemDefaults *sd; + + result = YES; + sd = [SOGoSystemDefaults sharedSystemDefaults]; + if (nil != [sd disableExport] + && NSNotFound != [[sd disableExport] indexOfObject: kDisableSharingCalendar]) { + result = NO; + } + + return result; +} + @end /* Component Viewer, parent class of Appointment Viewer and Task Viewer */ diff --git a/UI/Templates/ContactsUI/UIxContactFoldersView.wox b/UI/Templates/ContactsUI/UIxContactFoldersView.wox index 86505d966..55df4c221 100644 --- a/UI/Templates/ContactsUI/UIxContactFoldersView.wox +++ b/UI/Templates/ContactsUI/UIxContactFoldersView.wox @@ -104,11 +104,13 @@ - - - - - + + + + + + + diff --git a/UI/Templates/MailerUI/UIxMailMainFrame.wox b/UI/Templates/MailerUI/UIxMailMainFrame.wox index 7386eecaa..8fffd8fa1 100644 --- a/UI/Templates/MailerUI/UIxMailMainFrame.wox +++ b/UI/Templates/MailerUI/UIxMailMainFrame.wox @@ -243,11 +243,13 @@ - - - - - + + + + + + + diff --git a/UI/Templates/SchedulerUI/UIxCalMainView.wox b/UI/Templates/SchedulerUI/UIxCalMainView.wox index 4d23b0b28..2c1f82bb9 100644 --- a/UI/Templates/SchedulerUI/UIxCalMainView.wox +++ b/UI/Templates/SchedulerUI/UIxCalMainView.wox @@ -579,11 +579,13 @@ - - - - - + + + + + + +