Skip to content

Commit

Permalink
#351 added first draft of Sharing with users, groups, remotes
Browse files Browse the repository at this point in the history
  • Loading branch information
hosy committed Apr 12, 2019
1 parent 6583d9f commit d0d21c0
Show file tree
Hide file tree
Showing 11 changed files with 500 additions and 4 deletions.
24 changes: 24 additions & 0 deletions ownCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
23EC775D2137FB6B0032D4E6 /* WebViewDisplayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EC775C2137FB6B0032D4E6 /* WebViewDisplayViewController.swift */; };
23F6238120B587EF004FDE8B /* SortMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23F6238020B587EF004FDE8B /* SortMethod.swift */; };
23FA23E620BFD3D8009A6D73 /* SortBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23FA23E520BFD3D8009A6D73 /* SortBar.swift */; };
3907CA76225F5393001CFBD4 /* SharingSearchResultsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3907CA75225F5393001CFBD4 /* SharingSearchResultsTableViewController.swift */; };
39104E10223991C8002FC02F /* UIButton+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39104E0A223991C8002FC02F /* UIButton+Extension.swift */; };
39607CBC2225D480007B386D /* UITableViewController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39607CBB2225D480007B386D /* UITableViewController+Extension.swift */; };
3971B48F221B23FE006FB441 /* ThemeableColoredView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3971B48E221B23FE006FB441 /* ThemeableColoredView.swift */; };
Expand All @@ -43,6 +44,9 @@
3998F5D3224102FE00B66713 /* UITableView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3998F5D2224102FE00B66713 /* UITableView+Extension.swift */; };
3998F5D522411EDF00B66713 /* BorderedLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3998F5D422411EDF00B66713 /* BorderedLabel.swift */; };
3998F5D72241486F00B66713 /* OCCertificate+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3998F5D62241486F00B66713 /* OCCertificate+Extension.swift */; };
39A5135322608836002CF1AA /* OCShare+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39A5135222608836002CF1AA /* OCShare+Extension.swift */; };
39AFC3D1225E72FB00A6D3AE /* SharingTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39AFC3D0225E72FB00A6D3AE /* SharingTableViewController.swift */; };
39AFC3D8225E79CD00A6D3AE /* SharingEditUserGroupsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39AFC3D7225E79CD00A6D3AE /* SharingEditUserGroupsTableViewController.swift */; };
39E2FDED21FDEC7500F0117F /* ServerListTableHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39E2FDEC21FDEC7500F0117F /* ServerListTableHeaderView.swift */; };
39E2FE0021FF814A00F0117F /* ThemeRoundedButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39E2FDFF21FF814A00F0117F /* ThemeRoundedButton.swift */; };
4C1561E8222321E0009C4EF3 /* PhotoSelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C1561E7222321E0009C4EF3 /* PhotoSelectionViewController.swift */; };
Expand Down Expand Up @@ -474,6 +478,7 @@
23EC775C2137FB6B0032D4E6 /* WebViewDisplayViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewDisplayViewController.swift; sourceTree = "<group>"; };
23F6238020B587EF004FDE8B /* SortMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortMethod.swift; sourceTree = "<group>"; };
23FA23E520BFD3D8009A6D73 /* SortBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortBar.swift; sourceTree = "<group>"; };
3907CA75225F5393001CFBD4 /* SharingSearchResultsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingSearchResultsTableViewController.swift; sourceTree = "<group>"; };
39104E0A223991C8002FC02F /* UIButton+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+Extension.swift"; sourceTree = "<group>"; };
39607CBB2225D480007B386D /* UITableViewController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITableViewController+Extension.swift"; sourceTree = "<group>"; };
3971B48E221B23FE006FB441 /* ThemeableColoredView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeableColoredView.swift; sourceTree = "<group>"; };
Expand All @@ -482,6 +487,9 @@
3998F5D2224102FE00B66713 /* UITableView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITableView+Extension.swift"; sourceTree = "<group>"; };
3998F5D422411EDF00B66713 /* BorderedLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorderedLabel.swift; sourceTree = "<group>"; };
3998F5D62241486F00B66713 /* OCCertificate+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OCCertificate+Extension.swift"; sourceTree = "<group>"; };
39A5135222608836002CF1AA /* OCShare+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OCShare+Extension.swift"; sourceTree = "<group>"; };
39AFC3D0225E72FB00A6D3AE /* SharingTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingTableViewController.swift; sourceTree = "<group>"; };
39AFC3D7225E79CD00A6D3AE /* SharingEditUserGroupsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingEditUserGroupsTableViewController.swift; sourceTree = "<group>"; };
39E2FDEC21FDEC7500F0117F /* ServerListTableHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListTableHeaderView.swift; sourceTree = "<group>"; };
39E2FDFF21FF814A00F0117F /* ThemeRoundedButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeRoundedButton.swift; sourceTree = "<group>"; };
4C1561E7222321E0009C4EF3 /* PhotoSelectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoSelectionViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -902,6 +910,16 @@
path = Viewer;
sourceTree = "<group>";
};
3907CA6F225F5355001CFBD4 /* Sharing */ = {
isa = PBXGroup;
children = (
39AFC3D0225E72FB00A6D3AE /* SharingTableViewController.swift */,
39AFC3D7225E79CD00A6D3AE /* SharingEditUserGroupsTableViewController.swift */,
3907CA75225F5393001CFBD4 /* SharingSearchResultsTableViewController.swift */,
);
path = Sharing;
sourceTree = "<group>";
};
5917244820D3DB1F00809B38 /* Security */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1022,6 +1040,7 @@
DC3BE0DB2077CC13002A0AC0 /* Client */ = {
isa = PBXGroup;
children = (
3907CA6F225F5355001CFBD4 /* Sharing */,
236735A421217C2300E5834A /* Actions */,
DCFED971208095E200A2D984 /* ClientItemCell.swift */,
DC3BE0DC2077CC13002A0AC0 /* ClientQueryViewController.swift */,
Expand Down Expand Up @@ -1268,6 +1287,7 @@
DC136581208223F000FC0F60 /* OCBookmark+Extension.swift */,
DC4FEAE6209E3A7700D4476B /* OCIssue+Extension.swift */,
3998F5D62241486F00B66713 /* OCCertificate+Extension.swift */,
39A5135222608836002CF1AA /* OCShare+Extension.swift */,
);
path = "SDK Extensions";
sourceTree = "<group>";
Expand Down Expand Up @@ -1862,7 +1882,9 @@
DC6428D02081406800493A01 /* CollapsibleProgressBar.swift in Sources */,
DCB44D87218718BA00DAA4CC /* VendorServices.swift in Sources */,
DC63208521FCEBE9007EC0A8 /* ClientActivityCell.swift in Sources */,
39AFC3D1225E72FB00A6D3AE /* SharingTableViewController.swift in Sources */,
DC9BFBBD20A1C37B007064B5 /* PasswordManagerAccess.swift in Sources */,
39A5135322608836002CF1AA /* OCShare+Extension.swift in Sources */,
23D5241521491C670002C566 /* DisplayViewController.swift in Sources */,
DC0B379420514E4700189B9A /* ServerListBookmarkCell.swift in Sources */,
233E0FD82099F11D00C3D8D5 /* SecuritySettingsSection.swift in Sources */,
Expand Down Expand Up @@ -1910,6 +1932,7 @@
23C56538212167BE00BD4B47 /* CardTransitionDelegate.swift in Sources */,
6E3A104D219D6F0100F90C96 /* DuplicateAction.swift in Sources */,
DC1B270A209CF0D3004715E1 /* ConnectionIssueViewController.swift in Sources */,
3907CA76225F5393001CFBD4 /* SharingSearchResultsTableViewController.swift in Sources */,
DC0B37972051681600189B9A /* ThemeButton.swift in Sources */,
DCF4F17B20519F9D00189B9A /* StaticTableViewSection.swift in Sources */,
23C56537212167BE00BD4B47 /* CardPresentationController.swift in Sources */,
Expand All @@ -1923,6 +1946,7 @@
DCF4F17F2051A0D000189B9A /* StaticTableViewRow.swift in Sources */,
4C6B78102226B83300C5F3DB /* PhotoAlbumTableViewController.swift in Sources */,
23EC77592137F3DD0032D4E6 /* DisplayExtension.swift in Sources */,
39AFC3D8225E79CD00A6D3AE /* SharingEditUserGroupsTableViewController.swift in Sources */,
DC321261207EB01B00DB171D /* ThemeImage.swift in Sources */,
DC7DBA54207FA80C00E7337D /* TVGImage.swift in Sources */,
6E586CFE2199A75900F680C4 /* MoveAction.swift in Sources */,
Expand Down
78 changes: 78 additions & 0 deletions ownCloud/Client/Actions/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,84 @@ class Action : NSObject {
let header = MoreViewHeader(for: item, with: context.core!)
let moreViewController = MoreViewController(item: item, core: context.core!, header: header, viewController: tableViewController)

if context.core!.connectionStatus == .online, context.core!.connection.capabilities?.sharingAPIEnabled == 1, item.isShareable {

var shareRows: [StaticTableViewRow] = []
let shareTitle = NSAttributedString(string: "Sharing".localized, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20, weight: .heavy)])

if item.isShared() {
if context.core!.connection.capabilities?.sharingGroupSharing == 1 {

let shareQuery = OCShareQuery(scope: .itemWithReshares, item: item)

context.core!.start(shareQuery!)
shareQuery?.changesAvailableNotificationHandler = { query in
//print("--> query: \(query.queryResults)")

OnMainThread {
if query.queryResults.count > 0 {
let privateShares = query.queryResults.filter { (OCShare) -> Bool in
if OCShare.type != .link {
return true
}
return false
}
let linkSharesCounter = query.queryResults.count - privateShares.count

var userTitle = ""
if privateShares.count > 0 {
var title = "Recipient".localized
if privateShares.count > 1 {
title = "Recipients".localized
}
userTitle = "\(privateShares.count) \(title)"
}
if linkSharesCounter > 0 {
var title = "Public Link".localized
if userTitle.count > 0 {
userTitle.append(", ")
}
if linkSharesCounter > 1 {
title = "Public Links".localized
}
userTitle.append("\(linkSharesCounter) \(title)")
}

let roundAddButton = UIImageView(image: UIImage(named: "round-add-button"))
roundAddButton.tintColor = Theme.shared.activeCollection.tableRowColors.labelColor
let addGroupRow = StaticTableViewRow(rowWithAction: { (_, _) in

let sharingViewController = SharingTableViewController(style: .grouped)
sharingViewController.shares = query.queryResults
sharingViewController.core = context.core!
sharingViewController.item = item
let navigationController = ThemeNavigationController(rootViewController: sharingViewController)

moreViewController.present(navigationController, animated: true, completion: nil)

}, title: userTitle, alignment: .left, accessoryView: roundAddButton, multiline: true)
shareRows.append(addGroupRow)
}

if shareRows.count > 0 {
tableViewController.insertSection(MoreStaticTableViewSection(headerAttributedTitle: shareTitle, identifier: "share-section", rows: shareRows), at: 0, animated: true)
}
}
}
}
} else {
var title = "Share this file".localized
if item.type == .collection {
title = "Share this folder".localized
}

let addGroupRow = StaticTableViewRow(buttonWithAction: nil, title: title, style: .plain, identifier: "share-add-group")
shareRows.append(addGroupRow)

tableViewController.insertSection(MoreStaticTableViewSection(headerAttributedTitle: shareTitle, identifier: "share-section", rows: shareRows), at: 0, animated: true)
}
}

let title = NSAttributedString(string: "Actions".localized, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20, weight: .heavy)])

let actions = Action.sortedApplicableActions(for: context)
Expand Down
131 changes: 131 additions & 0 deletions ownCloud/Client/Sharing/SharingEditUserGroupsTableViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//
// SharingEditUserGroupsTableViewController.swift
// ownCloud
//
// Created by Matthias Hühne on 10.04.19.
// Copyright © 2019 ownCloud GmbH. All rights reserved.
//

/*
* Copyright (C) 2019, ownCloud GmbH.
*
* This code is covered by the GNU Public License Version 3.
*
* For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/
* You should have received a copy of this license along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/

import UIKit
import ownCloudSDK

class SharingEditUserGroupsTableViewController: StaticTableViewController {

var share : OCShare?
var reshares : [OCShare]?
var showSubtitles : Bool = false

override func viewDidLoad() {
super.viewDidLoad()

self.navigationItem.title = share?.recipient!.displayName!

let infoButton = UIButton(type: .infoLight)
infoButton.addTarget(self, action: #selector(showInfoSubtitles), for: .touchUpInside)
let infoBarButtonItem = UIBarButtonItem(customView: infoButton)
navigationItem.rightBarButtonItem = infoBarButtonItem

loadPermissionRow()
loadReshares()
}

func loadPermissionRow() {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .short
var footer = ""
if let date = share?.creationDate {
footer = "Shared since: \(dateFormatter.string(from: date))"
}

let section = StaticTableViewSection(headerTitle: "Permissions".localized, footerTitle: footer, identifier: "permission-section")
guard let share = share else { return }
var permissions : [[String: Bool]] = []
var subtitles : [String]?

if share.itemType == .collection {
permissions = [
["Share" : share.canShare],
["Edit" : share.canReadWrite],
["Create" : share.canCreate],
["Change" : share.canUpdate],
["Delete" : share.canDelete]
]
if showSubtitles {
subtitles = [
"Allows the users you share with to re-share".localized,
"Allows the users you share with to edit your shared files, and to collaborate".localized,
"Allows the users you share with to create new files and add them to the share".localized,
"Allows uploading a new version of a shared file and replacing it".localized,
"Allows the users you share with to delete shared files".localized
]
}
} else {
permissions = [
["Share" : share.canShare],
["Edit" : share.canReadWrite],
["Change" : share.canUpdate]
]
if showSubtitles {
subtitles = [
"Allows the users you share with to re-share".localized,
"Allows the users you share with to edit your shared files, and to collaborate".localized,
"Allows uploading a new version of a shared file and replacing it".localized
]
}
}

section.add(toogleGroupWithArrayOfLabelValueDictionaries: permissions, radioAction: { (row, _) in
let selectedValueFromSection = row.section?.selectedValue(forGroupIdentifier: row.groupIdentifier!)

Log.log("Radio value for \(row.groupIdentifier!) changed to \(row.value!)")
Log.log("Values can also be read from the section object: \(selectedValueFromSection!)")

}, subtitles: subtitles, groupIdentifier: "radioExample", selectedValue:true)
self.insertSection(section, at: 0, animated: false)
//self.addSection(section)
}

func loadReshares() {
var shareRows: [StaticTableViewRow] = []

if let reshares = reshares, reshares.count > 0 {
for share in reshares {
shareRows.append( StaticTableViewRow(rowWithAction: { (_, _) in
let editSharingViewController = SharingEditUserGroupsTableViewController(style: .grouped)
editSharingViewController.share = share
self.navigationController?.pushViewController(editSharingViewController, animated: true)
}, title: share.recipient!.displayName!, subtitle: "Share, Edit, Change", accessoryType: .disclosureIndicator) )
}

let section = StaticTableViewSection(headerTitle: "Shared to".localized, footerTitle: nil, rows: shareRows)
self.addSection(section)
}

let section = StaticTableViewSection(headerTitle: nil, footerTitle: nil)
section.add(rows: [
StaticTableViewRow(buttonWithAction: { (_, _) in
Log.log("Destructive pressed")
}, title: "Revoke Recipient", style: StaticTableViewRowButtonStyle.destructive)
])

self.addSection(section)
}

@objc func showInfoSubtitles() {
showSubtitles.toggle()
guard let removeSection = self.sectionForIdentifier("permission-section") else { return }
self.removeSection(removeSection)
loadPermissionRow()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SharingSearchResultsTableViewController.swift
// ownCloud
//
// Created by Matthias Hühne on 11.04.19.
// Copyright © 2019 ownCloud GmbH. All rights reserved.
//

/*
* Copyright (C) 2019, ownCloud GmbH.
*
* This code is covered by the GNU Public License Version 3.
*
* For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/
* You should have received a copy of this license along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/

import UIKit

class SharingSearchResultsTableViewController: StaticTableViewController, UISearchResultsUpdating {

override func viewDidLoad() {
super.viewDidLoad()
}

// MARK: - UISearchResultsUpdating Delegate
func updateSearchResults(for searchController: UISearchController) {
}
}
Loading

0 comments on commit d0d21c0

Please sign in to comment.