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

Nmc/1992 sharing #84

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
796ba0e
nmc 1992 - sharing feature customisation aaded
TSI-amrutwaghmare Jun 6, 2023
73c83e7
nmc 1992 - ncsharesectionheaderview.swift file lint issue resolve
TSI-amrutwaghmare Jun 6, 2023
05d7271
nmc 1992 - Lint issue fix for NCShare.swift file
TSI-amrutwaghmare Jun 6, 2023
2650b04
nmc 1992 - Share screen Header width update and image shown in header
TSI-amrutwaghmare Jun 7, 2023
ae6fa5d
nmc 1992 - Unit test case added for sharing
TSI-amrutwaghmare Jun 8, 2023
2c38880
nmc 1992 - merging conflict resolve of ncbrand.swift
TSI-amrutwaghmare Jun 9, 2023
4d3b0a2
NMC 1992 NCBrand updated
TSI-shwetawaikar Jun 13, 2023
e47a25c
nmc 1992 - merging conflict resolve after master update with 4.8.3
TSI-amrutwaghmare Jun 14, 2023
93085f9
nmc 1992 - merging conflict resolve after Dashboard cluster
TSI-amrutwaghmare Jun 15, 2023
26a7297
NMC 1992 - download limit issue fix
TSI-amrutwaghmare Jun 19, 2023
640ad77
nmc 1992 - resolve merging conflict of image extension
TSI-amrutwaghmare Jun 20, 2023
ef9e258
NMC 1992 Changed background color for view
TSI-shwetawaikar Jun 23, 2023
9ec0b4a
NMC 1992 header height fix
TSI-shwetawaikar Jun 23, 2023
bce339a
NMC 1992 - Share permission update issue fix
TSI-amrutwaghmare Jun 24, 2023
6aeb0ed
nmc 1992 - can reshare permission update
TSI-amrutwaghmare Jun 26, 2023
dd863d5
NMC 1992 - Share status update issue fix
TSI-amrutwaghmare Jun 26, 2023
d34941d
NMC 1992 - Re sharing message string update
TSI-amrutwaghmare Jun 27, 2023
c584f19
NMC 1992 - Login url changes for Login Screen
TSI-shwetawaikar Jul 5, 2023
32bb19b
NMC 1992 - Configuration changes removed to avoid conflicts
TSI-amrutwaghmare Jul 19, 2023
467406c
NMC 1992 - (NMC - 2388) - The Share Settings window appears empty aft…
TSI-amrutwaghmare Jul 31, 2023
28e2431
NMC 1992 - share list not update after sharing with multiple users or…
TSI-amrutwaghmare Aug 2, 2023
9472c46
NMC 1992, NMC 2457 - file specific shares delete
TSI-amrutwaghmare Sep 18, 2023
6d0ed19
NMC 1992 - NMC 2568 - Contact Button for Sharing
TSI-amrutwaghmare Sep 25, 2023
6386b22
NMC1992 - sharing - 2568 - Reshare message overlapping and contact ic…
TSI-amrutwaghmare Sep 27, 2023
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
58 changes: 58 additions & 0 deletions Brand/NCBrand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ class NCBrandColor: NSObject {
return UIColor(red: 0.0 / 255.0, green: 199.0 / 255.0, blue: 190.0 / 255.0, alpha: 1.0)
}
}

@objc public var iconColor: UIColor{
if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
return UIColor(displayP3Red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0)
}else {
return UIColor(red: 38.0/255.0, green: 38.0/255.0, blue: 38.0/255.0, alpha: 1.0)
}
} else {
return UIColor(red: 38.0/255.0, green: 38.0/255.0, blue: 38.0/255.0, alpha: 1.0)
}
}

override init() {
brand = customer
Expand Down Expand Up @@ -365,4 +377,50 @@ class NCBrandColor: NSObject {
let palette3 = mixPalette(steps: steps, color1: blue, color2: red)
return palette1 + palette2 + palette3
}

@objc public var notificationAction: UIColor {
return UIColor(red: 0/255.0, green: 153/255.0, blue: 255/255.0, alpha: 1.0)
}

@objc public var secondarySystemGroupedBackground: UIColor = UIColor.secondarySystemGroupedBackground
@objc public var label: UIColor = UIColor.label
@objc public var backgroundForm: UIColor = UIColor(red: 244.0/255.0, green: 244.0/255.0, blue: 244.0/255.0, alpha: 1.0)
@objc public let graySoft: UIColor = UIColor(red: 162.0/255.0, green: 162.0/255.0, blue: 162.0/255.0, alpha: 0.5)
@objc public let systemGray4: UIColor = UIColor.systemGray4
@objc public let systemBackground: UIColor = UIColor.systemBackground
@objc public let textInfo: UIColor = UIColor(red: 153.0/255.0, green: 153.0/255.0, blue: 153.0/255.0, alpha: 1.0)
@objc public let systemGray: UIColor = UIColor.systemGray
@objc public let customerDarkGrey: UIColor = UIColor(red: 38.0/255.0, green: 38.0/255.0, blue: 38.0/255.0, alpha: 1.0)
@objc public var fileFolderName: UIColor = UIColor(displayP3Red: 102.0/255.0, green: 102.0/255.0, blue: 102.0/255.0, alpha: 1.0)
@objc public let optionItem: UIColor = UIColor(red: 178.0/255.0, green: 178.0/255.0, blue: 178.0/255.0, alpha: 1.0)
@objc public var singleTitleColorButton: UIColor = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0)
@objc public var shareCellTitleColor: UIColor = UIColor(displayP3Red: 242.0/255.0, green: 242.0/255.0, blue: 242.0/255.0, alpha: 1.0)
@objc public var gray60: UIColor {
if UITraitCollection.current.userInterfaceStyle == .dark {
return UIColor(red: 178.0/255.0, green: 178.0/255.0, blue: 178.0/255.0, alpha: 1.0)
} else {
return UIColor(red: 102.0/255.0, green: 102.0/255.0, blue: 102.0/255.0, alpha: 1.0)
}
}
@objc public var systemGray2: UIColor = UIColor.systemGray2
@objc public var shareByEmailTextColor: UIColor = UIColor(displayP3Red: 13.0/255.0, green: 57.0/255.0, blue: 223.0/255.0, alpha: 1.0)
@objc public var memoryConsuptionBackground: UIColor {
if UITraitCollection.current.userInterfaceStyle == .dark {
return UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0)
} else {
return UIColor(red: 244.0/255.0, green: 244.0/255.0, blue: 244.0/255.0, alpha: 1.0)
}
}
@objc public var nmcGray0: UIColor{
if UITraitCollection.current.userInterfaceStyle == .dark {
return UIColor(displayP3Red: 242.0/255.0, green: 242.0/255.0, blue: 242.0/255.0, alpha: 1.0)
}else {
return UIColor(red: 19.0/255.0, green: 19.0/255.0, blue: 19.0/255.0, alpha: 1.0)
}
}
@objc public var commonViewInfoText: UIColor = UIColor(displayP3Red: 102.0/255.0, green: 102.0/255.0, blue: 102.0/255.0, alpha: 1.0)
@objc public let progressColorGreen60: UIColor = UIColor(red: 115.0/255.0, green: 195.0/255.0, blue: 84.0/255.0, alpha: 1.0)
@objc public var seperatorRename: UIColor = UIColor(red: 235.0/255.0, green: 235.0/255.0, blue: 235.0/255.0, alpha: 1.0)
@objc public let gray: UIColor = UIColor(red: 104.0/255.0, green: 104.0/255.0, blue: 104.0/255.0, alpha: 1.0)
@objc public var nmcIconSharedWithMe: UIColor = UIColor(displayP3Red: 0.0/255.0, green: 153.0/255.0, blue: 255.0/255.0, alpha: 1.0)
}
232 changes: 232 additions & 0 deletions Tests/NextcloudUnitTests/SharingTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
//
// SharingTest.swift
// NextcloudTests
//
// Created by A200020526 on 07/06/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

import XCTest
@testable import Nextcloud
final class SharingTest: XCTestCase {

var button: UIButton?
var ncShare: NCShare?

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
super.setUp()
button = UIButton()
ncShare = NCShare()
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
button = nil
ncShare = nil
super.tearDown()
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}


//Date exntesion test case
func testTomorrow() {
let tomorrow = Date.tomorrow
let expectedTomorrow = Calendar.current.date(byAdding: .day, value: 1, to: Date())!
XCTAssertEqual(tomorrow.extendedIso8601String, expectedTomorrow.extendedIso8601String, "Tomorrow date should be correct.")
}
func testToday() {
let today = Date.today
let currentDate = Date()
XCTAssertEqual(today.extendedIso8601String, currentDate.extendedIso8601String, "Today date should be correct.")
}

func testDayAfter() {
let date = Date()
let dayAfter = date.dayAfter
let expectedDayAfter = Calendar.current.date(byAdding: .day, value: 1, to: date)!
XCTAssertEqual(dayAfter.extendedIso8601String, expectedDayAfter.extendedIso8601String, "Day after date should be correct.")
}

//Date Formatter extension Test Case
func testShareExpDate() {
let dateFormatter = DateFormatter.shareExpDate

XCTAssertEqual(dateFormatter.formatterBehavior, .behavior10_4, "Formatter behavior should be correct.")
XCTAssertEqual(dateFormatter.dateStyle, .medium, "Date style should be correct.")
XCTAssertEqual(dateFormatter.dateFormat, NCShareAdvancePermission.displayDateFormat, "Date format should be correct.")
}

//Button Extension test case
func testSetBackgroundColor() {
// Arrange
let color = UIColor.red
let state: UIControl.State = .normal

// Act
button?.setBackgroundColor(color, for: state)

// Assert
XCTAssertNotNil(button?.currentBackgroundImage, "Button background image not nil")
}

func testSetBackgroundColorForDifferentStates() {
// Arrange

let selectedColor = UIColor.green

// Act
button?.isSelected = true
button?.setBackgroundColor(selectedColor, for: .selected)

// Assert
XCTAssertNotNil(button?.currentBackgroundImage, "Button background image not nil")
button?.isSelected = false
XCTAssertNil(button?.currentBackgroundImage,"Button background image will be nil")
button?.isHighlighted = true
XCTAssertNil(button?.currentBackgroundImage, "Button background image will be nil")
}

//UIView extension shadow test case
func testAddShadowWithLocation() {
// Create a UIView instance
let view = UIView()

// Set the shadow with bottom location
view.addShadow(location: .bottom, height: 2, color: .red, opacity: 0.4, radius: 2)

// Verify that the shadow offset is set correctly for the bottom location
let bottomShadowOffset = view.layer.shadowOffset
XCTAssertEqual(bottomShadowOffset, CGSize(width: 0, height: 2), "Shadow offset not set correctly for bottom location")

// Verify that the shadow color is set correctly
let shadowColor = view.layer.shadowColor
XCTAssertEqual(shadowColor, UIColor.red.cgColor, "Shadow color not set correctly")

// Verify that the shadow opacity is set correctly
let shadowOpacity = view.layer.shadowOpacity
XCTAssertEqual(shadowOpacity, 0.4, "Shadow opacity not set correctly")

// Verify that the shadow radius is set correctly
let shadowRadius = view.layer.shadowRadius
XCTAssertEqual(shadowRadius, 2.0, "Shadow radius not set correctly")
}

func testAddShadowWithOffset() {
// Create a UIView instance
let view = UIView()

// Set the shadow with a custom offset
view.addShadow(offset: CGSize(width: 0, height: -4), color: .blue, opacity: 0.6, radius: 3)

// Verify that the shadow offset is set correctly
let shadowOffset = view.layer.shadowOffset
XCTAssertEqual(shadowOffset, CGSize(width: 0, height: -4), "Shadow offset not set correctly")

// Verify that the shadow color is set correctly
let shadowColor = view.layer.shadowColor
XCTAssertEqual(shadowColor, UIColor.blue.cgColor, "Shadow color not set correctly")

// Verify that the shadow opacity is set correctly
let shadowOpacity = view.layer.shadowOpacity
XCTAssertEqual(shadowOpacity, 0.6, "Shadow opacity not set correctly")

// Verify that the shadow radius is set correctly
let shadowRadius = view.layer.shadowRadius
XCTAssertEqual(shadowRadius, 3.0, "Shadow radius not set correctly")
}

func testAddShadowForLocation() {
// Create a UIView instance
let view = UIView()

// Add shadow to the bottom
view.addShadow(location: .bottom, color: UIColor.black)

// Verify that the shadow properties are set correctly for the bottom location
XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 0, height: 2), "Shadow offset not set correctly for bottom location")
XCTAssertEqual(view.layer.shadowColor, UIColor.black.cgColor, "Shadow color not set correctly for bottom location")
XCTAssertEqual(view.layer.shadowOpacity, 0.4, "Shadow opacity not set correctly for bottom location")
XCTAssertEqual(view.layer.shadowRadius, 2.0, "Shadow radius not set correctly for bottom location")

// Add shadow to the top
view.addShadow(location: .top)

// Verify that the shadow properties are set correctly for the top location
XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 0, height: -2), "Shadow offset not set correctly for top location")
XCTAssertEqual(view.layer.shadowColor, NCBrandColor.shared.customerDarkGrey.cgColor, "Shadow color not set correctly for top location")
XCTAssertEqual(view.layer.shadowOpacity, 0.4, "Shadow opacity not set correctly for top location")
XCTAssertEqual(view.layer.shadowRadius, 2.0, "Shadow radius not set correctly for top location")
}

func testAddShadowForOffset() {
// Create a UIView instance
let view = UIView()

// Add shadow with custom offset
view.addShadow(offset: CGSize(width: 2, height: 2))

// Verify that the shadow properties are set correctly for the custom offset
XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 2, height: 2), "Shadow offset not set correctly for custom offset")
XCTAssertEqual(view.layer.shadowColor, UIColor.black.cgColor, "Shadow color not set correctly for custom offset")
XCTAssertEqual(view.layer.shadowOpacity, 0.5, "Shadow opacity not set correctly for custom offset")
XCTAssertEqual(view.layer.shadowRadius, 5.0, "Shadow radius not set correctly for custom offset")
}


func testHasUploadPermission() {
// Create an instance of NCShare
let share = NCShare()

// Define the input parameters
let tableShareWithUploadPermission = tableShare()
tableShareWithUploadPermission.permissions = NCGlobal.shared.permissionMaxFileShare

let tableShareWithoutUploadPermission = tableShare()
tableShareWithoutUploadPermission.permissions = NCGlobal.shared.permissionReadShare

// Call the hasUploadPermission function
let hasUploadPermission1 = share.hasUploadPermission(tableShare: tableShareWithUploadPermission)
let hasUploadPermission2 = share.hasUploadPermission(tableShare: tableShareWithoutUploadPermission)

// Verify the results
XCTAssertTrue(hasUploadPermission1, "hasUploadPermission returned false for a tableShare with upload permission")
XCTAssertFalse(hasUploadPermission2, "hasUploadPermission returned true for a tableShare without upload permission")
}

func testGetImageShareType() {
let sut = NCShareCommon() // Replace with the actual class containing the getImageShareType function

// Test case 1: SHARE_TYPE_USER
let shareType1 = sut.SHARE_TYPE_USER
let result1 = sut.getImageShareType(shareType: shareType1)
XCTAssertEqual(result1, UIImage(named: "shareTypeEmail")?.imageColor(NCBrandColor.shared.label))

// Test case 2: SHARE_TYPE_GROUP
let shareType2 = sut.SHARE_TYPE_GROUP
let result2 = sut.getImageShareType(shareType: shareType2)
XCTAssertEqual(result2, UIImage(named: "shareTypeGroup")?.imageColor(NCBrandColor.shared.label))

// Test case 3: SHARE_TYPE_LINK
let shareType3 = sut.SHARE_TYPE_LINK
let result3 = sut.getImageShareType(shareType: shareType3)
XCTAssertEqual(result3, UIImage(named: "shareTypeLink")?.imageColor(NCBrandColor.shared.label))

// Test case 4: SHARE_TYPE_EMAIL (with isDropDown=false)
let shareType4 = sut.SHARE_TYPE_EMAIL
let result4 = sut.getImageShareType(shareType: shareType4)
XCTAssertEqual(result4, UIImage(named: "shareTypeUser")?.imageColor(NCBrandColor.shared.label))

// Test case 5: SHARE_TYPE_EMAIL (with isDropDown=true)
let shareType5 = sut.SHARE_TYPE_EMAIL
let isDropDown5 = true
let result5 = sut.getImageShareType(shareType: shareType5, isDropDown: isDropDown5)
XCTAssertEqual(result5, UIImage(named: "email")?.imageColor(NCBrandColor.shared.label))
}
}
25 changes: 25 additions & 0 deletions iOSClient/Data/NCManageDatabase+Share.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class tableShareV2: Object {
override static func primaryKey() -> String {
return "primaryKey"
}

func setPermission(value: Int) {
let realm = try! Realm()
try! realm.write {
permissions = value
}
}
}

extension NCManageDatabase {
Expand Down Expand Up @@ -253,6 +260,24 @@ extension NCManageDatabase {
NextcloudKit.shared.nkCommonInstance.writeLog("Could not write to database: \(error)")
}
}

/// Delete shares of specific file
/// - Parameters:
/// - account: account url for specific user
/// - filePath: file path of media which shares need to delete
func deleteTableShare(account: String, filePath: String) {

do {
let realm = try Realm()

try realm.write {
let result = realm.objects(tableShare.self).filter("account == %@ AND path == %@", account, "/"+filePath)
realm.delete(result)
}
} catch let error as NSError {
NextcloudKit.shared.nkCommonInstance.writeLog("Could not write to database: \(error)")
}
}

// There is currently only one share attribute “download” from the scope “permissions”. This attribute is only valid for user and group shares, not for public link shares.
func setAttibuteDownload(state: Bool) -> String? {
Expand Down
10 changes: 10 additions & 0 deletions iOSClient/Extensions/DateFormatter+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ extension DateFormatter {
let dateFormatter = DateFormatter()
dateFormatter.formatterBehavior = .behavior10_4
dateFormatter.dateStyle = .medium
dateFormatter.dateFormat = NCShareAdvancePermission.displayDateFormat
return dateFormatter
}()
}


extension Date {
static var tomorrow: Date { return Date().dayAfter }
static var today: Date {return Date()}
var dayAfter: Date {
return Calendar.current.date(byAdding: .day, value: 1, to: Date())!
}
}
22 changes: 22 additions & 0 deletions iOSClient/Extensions/UIButton+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// UIButton+Extension.swift
// Nextcloud
//
// Created by A200020526 on 30/05/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

import UIKit

extension UIButton {

func setBackgroundColor(_ color: UIColor, for forState: UIControl.State) {
UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
UIGraphicsGetCurrentContext()!.setFillColor(color.cgColor)
UIGraphicsGetCurrentContext()!.fill(CGRect(x: 0, y: 0, width: 1, height: 1))
let colorImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.setBackgroundImage(colorImage, for: forState)
}
}

Loading