Skip to content

Commit

Permalink
- SDK update to add OCUser.permissions
Browse files Browse the repository at this point in the history
- AccountControllerSpacesGridViewController: determine canManageSpaces based on logged in user's permissions
- OCDrive+ManagementActions: add alert asking user for confirmation before deleting a space
  • Loading branch information
felix-schwarz committed Feb 4, 2025
1 parent 322718a commit e1ed8ff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
6 changes: 6 additions & 0 deletions ownCloud/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -6697,6 +6697,9 @@
}
}
}
},
"Are you sure you want to delete this space? This action cannot be undone." : {

},
"Are you sure you want to unshare these items?" : {
"localizations" : {
Expand Down Expand Up @@ -18370,6 +18373,9 @@
}
}
}
},
"Delete space \"{{driveName}}\"?" : {

},
"Delete unused local copies" : {
"localizations" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class AccountControllerSpacesGridViewController: CollectionViewController, ViewC
var noSpacesCondition: DataSourceCondition?

var canManageSpaces: Bool {
return true
if let userPermissions = clientContext?.core?.connection.loggedInUser?.permissions {
return userPermissions.canCreateSpaces
}
return false
}

var spacesDataSource: OCDataSourceComposition = OCDataSourceComposition(sources: [])
Expand Down
38 changes: 24 additions & 14 deletions ownCloudAppShared/Client/Spaces/OCDrive+ManagementActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,30 @@ extension OCDrive {
}

func delete(with clientContext: ClientContext?) {
guard let core = clientContext?.core else { return }

core.deleteDrive(self, completionHandler: { error in
if let error {
OnMainThread {
let alertController = ThemedAlertController(
with: OCLocalizedFormat("Error deleting {{driveName}}", ["driveName" : self.name ?? OCLocalizedString("space", nil)]),
message: error.localizedDescription,
okLabel: OCLocalizedString("OK", nil),
action: nil)

clientContext?.present(alertController, animated: true)
let alertController = ThemedAlertController(
title: OCLocalizedFormat("Delete space \"{{driveName}}\"?", ["driveName" : self.name ?? OCLocalizedString("space", nil)]),
message: OCLocalizedString("Are you sure you want to delete this space? This action cannot be undone.", nil),
preferredStyle: .alert)

alertController.addAction(UIAlertAction(title: OCLocalizedString("Cancel", nil), style: .cancel, handler: nil))
alertController.addAction(UIAlertAction(title: OCLocalizedString("Delete", nil), style: .destructive, handler: { [weak clientContext] (_) in
guard let core = clientContext?.core else { return }

core.deleteDrive(self, completionHandler: { error in
if let error {
OnMainThread {
let alertController = ThemedAlertController(
with: OCLocalizedFormat("Error deleting {{driveName}}", ["driveName" : self.name ?? OCLocalizedString("space", nil)]),
message: error.localizedDescription,
okLabel: OCLocalizedString("OK", nil),
action: nil)

clientContext?.present(alertController, animated: true)
}
}
}
})
})
}))

clientContext?.present(alertController, animated: true)
}
}

0 comments on commit e1ed8ff

Please sign in to comment.