-
Notifications
You must be signed in to change notification settings - Fork 9
Extended support for files_lock server app #190
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| import Foundation | ||
| import SwiftyXMLParser | ||
|
|
||
| /// | ||
| /// Description of a file lock. | ||
| /// | ||
| /// This is based on the description of the [`files_lock`](https://github.com/nextcloud/files_lock) server app. | ||
| /// | ||
| public struct NKLock: Equatable, Sendable { | ||
| /// | ||
| /// User id of the owning user. | ||
| /// | ||
| public let owner: String | ||
|
|
||
| /// | ||
| /// App id of an app owned lock to allow clients to suggest joining the collaborative editing session through the web or direct editing. | ||
| /// | ||
| public let ownerEditor: String | ||
|
|
||
| /// | ||
| /// What kind of lock this is. | ||
| /// | ||
| public let ownerType: NKLockType | ||
|
|
||
| /// | ||
| /// Display name of the lock owner. | ||
| /// | ||
| public let ownerDisplayName: String | ||
|
|
||
| /// | ||
| /// Timestamp of the lock creation time. | ||
| /// | ||
| public let time: Date? | ||
|
|
||
| /// | ||
| /// TTL of the lock in seconds staring from the creation time. | ||
| /// A value of 0 means the timeout is infinite. | ||
| /// Client implementations should properly handle this specific value. | ||
| /// | ||
| public let timeOut: Date? | ||
|
|
||
| /// | ||
| /// Unique lock token (to be preserved on the client side while holding the lock to sent once full webdav locking is implemented). | ||
| /// | ||
| public let token: String? | ||
|
|
||
| /// | ||
| /// Initialize from a SwiftyXML accessor. | ||
| /// | ||
| /// This is intended for creating an instance based on a superset of required properties returned by a `PROPFIND` request to the server about an item. | ||
| /// | ||
| public init?(xml properties: XML.Accessor) { | ||
| guard let isLocked = properties["nc:lock"].bool else { | ||
| return nil | ||
| } | ||
|
|
||
| guard let owner = properties["nc:lock-owner"].text else { | ||
| return nil | ||
| } | ||
|
|
||
| guard let ownerDisplayName = properties["nc:lock-owner-displayname"].text else { | ||
| return nil | ||
| } | ||
|
|
||
| guard let ownerEditor = properties["nc:lock-owner-editor"].text else { | ||
| return nil | ||
| } | ||
|
|
||
| guard let rawOwnerTypeValue = properties["nc:lock-owner-type"].int, let lockOwnerType = NKLockType(rawValue: rawOwnerTypeValue) else { | ||
| return nil | ||
| } | ||
|
|
||
| guard let rawTime = properties["nc:lock-time"].double else { | ||
| return nil | ||
| } | ||
|
|
||
| guard let rawTimeOut = properties["nc:lock-timeout"].double else { | ||
| return nil | ||
| } | ||
|
|
||
| let lockToken = properties["nc:lock-token"].text | ||
|
|
||
| self.owner = owner | ||
| self.ownerEditor = ownerEditor | ||
| self.ownerType = lockOwnerType | ||
| self.ownerDisplayName = ownerDisplayName | ||
| self.time = Date(timeIntervalSince1970: rawTime) | ||
| self.timeOut = Date(timeIntervalSince1970: rawTime + rawTimeOut) | ||
| self.token = lockToken | ||
| } | ||
|
|
||
| /// | ||
| /// Initialize from the response body data of an WebDAV request. | ||
| /// | ||
| public init?(data: Data) { | ||
| let properties = XML.parse(data)["d:prop"] | ||
| self.init(xml: properties) | ||
| } | ||
|
|
||
| /// | ||
| /// Initialize from raw values. | ||
| /// | ||
| public init(owner: String, ownerEditor: String, ownerType: NKLockType, ownerDisplayName: String, time: Date?, timeOut: Date?, token: String?) { | ||
| self.owner = owner | ||
| self.ownerEditor = ownerEditor | ||
| self.ownerType = ownerType | ||
| self.ownerDisplayName = ownerDisplayName | ||
| self.time = time | ||
| self.timeOut = timeOut | ||
| self.token = token | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| /// | ||
| /// The [`files_lock`](https://github.com/nextcloud/files_lock) server apps distinguishes between different lock types which are represented by this type. | ||
| /// | ||
| public enum NKLockType: Int, Sendable { | ||
| /// | ||
| /// This lock type is initiated by a user manually through the WebUI or Clients and will limit editing capabilities on the file to the lock owning user. | ||
| /// | ||
| case user = 0 | ||
|
|
||
| /// | ||
| /// This lock type is created by collaborative apps like Text or Office to avoid outside changes through WebDAV or other apps. | ||
| /// | ||
| case app = 1 | ||
|
|
||
| /// | ||
| /// This lock type will bind the ownership to the provided lock token. | ||
| /// Any request that aims to modify the file will be required to sent the token, the user itself is not able to write to files without the token. | ||
| /// This will allow to limit the locking to an individual client. | ||
| /// | ||
| /// This is mostly used for automatic client locking, e.g. when a file is opened in a client or with WebDAV clients that support native WebDAV locking. | ||
| /// The lock token can be skipped on follow up requests using the OCS API or the X-User-Lock header for WebDAV requests, but in that case the server will not be able to validate the lock ownership when unlocking the file from the client. | ||
| /// | ||
| case token = 2 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.