Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove activity logs after logging out #19930

Merged
merged 5 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-----
* [*] Fix a layout issue impacting the "No media matching your search" empty state message of the Media Picker screen. [#19820]
* [***] [Jetpack-only] Stats Insights Update. Helps you understand how your content is performing and what’s resonating with your audience. [#19909]
* [***] [internal] Delete all the activity logs after logging out. [#19930]

21.5
-----
Expand Down
7 changes: 7 additions & 0 deletions WordPress/Classes/Utility/AccountHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ import Foundation

service.removeDefaultWordPressComAccount()

deleteAccountData()
}

@objc static func deleteAccountData() {
// Delete saved dashboard states
BlogDashboardState.resetAllStates()

Expand All @@ -97,5 +101,8 @@ import Foundation

// Refresh Remote Feature Flags
WordPressAppDelegate.shared?.updateFeatureFlags()

// Delete all the logs after logging out
WPLogger.shared().deleteAllLogs()
}
}
10 changes: 10 additions & 0 deletions WordPress/Classes/Utility/Logging/WPLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@
*/
+ (WPLogger * _Nonnull)shared;

/**
* @brief Deletes all the logs from the device
*/
- (void)deleteAllLogs;

/**
* @brief Deletes all the old archived logs from the device
*/
- (void)deleteArchivedLogs;

@end
24 changes: 24 additions & 0 deletions WordPress/Classes/Utility/Logging/WPLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,30 @@ - (NSString *)getLogFilesContentWithMaxSize:(NSInteger)maxSize
return description;
}

#pragma mark - Deleting

- (void)deleteAllLogs
{
NSArray *logFiles = self.fileLogger.logFileManager.sortedLogFileInfos;
for (DDLogFileInfo *logFileInfo in logFiles) {
[[NSFileManager defaultManager] removeItemAtPath:logFileInfo.filePath error:nil];
}

DDLogWarn(@"All log files erased.");
}

- (void)deleteArchivedLogs
{
NSArray *logFiles = self.fileLogger.logFileManager.sortedLogFileInfos;
for (DDLogFileInfo *logFileInfo in logFiles) {
if (logFileInfo.isArchived) {
[[NSFileManager defaultManager] removeItemAtPath:logFileInfo.filePath error:nil];
}
}

DDLogWarn(@"All archived log files erased.");
}

#pragma mark - Public static methods

+ (void)configureLoggerLevelWithExtraDebug {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,11 @@ - (void)confirmRemoveSite
if ([Feature enabled:FeatureFlagContentMigration] && [AppConfiguration isWordPress]) {
[ContentMigrationCoordinator.shared cleanupExportedDataIfNeeded];
}

// Delete local data after removing the last site
if (!AccountHelper.isLoggedIn) {
[AccountHelper deleteAccountData];
}

[self.navigationController popToRootViewControllerAnimated:YES];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,11 @@ - (void)confirmRemoveSiteForIndexPath:(NSIndexPath *)indexPath
if ([Feature enabled:FeatureFlagContentMigration] && [AppConfiguration isWordPress]) {
[ContentMigrationCoordinator.shared cleanupExportedDataIfNeeded];
}

// Delete local data after removing the last site
if (!AccountHelper.isLoggedIn) {
[AccountHelper deleteAccountData];
}

[self.tableView reloadData];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
actionWithTitle:trashButtonTitle
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
for (DDLogFileInfo *logFileInfo in self.logFiles) {
if (logFileInfo.isArchived) {
[[NSFileManager defaultManager] removeItemAtPath:logFileInfo.filePath error:nil];
}
}
DDLogWarn(@"All archived log files erased.");
[WPLogger.shared deleteArchivedLogs];
[self loadLogFiles];
[self.tableView reloadData];
}];
Expand Down