-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(datastore): filter authrules with invalid ownerfield
- Loading branch information
Showing
13 changed files
with
314 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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 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 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
57 changes: 57 additions & 0 deletions
57
...StoreHostApp/AWSDataStorePluginAuthCognitoTests/Models/TodoCognitoMultiOwner+Schema.swift
This file contains 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,57 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
// swiftlint:disable all | ||
import Amplify | ||
import Foundation | ||
|
||
extension TodoCognitoMultiOwner { | ||
// MARK: - CodingKeys | ||
public enum CodingKeys: String, ModelKey { | ||
case id | ||
case title | ||
case content | ||
case owner | ||
case editors | ||
case createdAt | ||
case updatedAt | ||
} | ||
|
||
public static let keys = CodingKeys.self | ||
// MARK: - ModelSchema | ||
|
||
public static let schema = defineSchema { model in | ||
let todoCognitoMultiOwner = TodoCognitoMultiOwner.keys | ||
|
||
model.authRules = [ | ||
rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", provider: .userPools, operations: [.create, .update, .delete, .read]), | ||
rule(allow: .owner, ownerField: "editors", identityClaim: "cognito:username", provider: .userPools, operations: [.update, .read]) | ||
] | ||
|
||
model.listPluralName = "TodoCognitoMultiOwners" | ||
model.syncPluralName = "TodoCognitoMultiOwners" | ||
|
||
model.attributes( | ||
.primaryKey(fields: [todoCognitoMultiOwner.id]) | ||
) | ||
|
||
model.fields( | ||
.field(todoCognitoMultiOwner.id, is: .required, ofType: .string), | ||
.field(todoCognitoMultiOwner.title, is: .required, ofType: .string), | ||
.field(todoCognitoMultiOwner.content, is: .optional, ofType: .string), | ||
.field(todoCognitoMultiOwner.owner, is: .optional, ofType: .string), | ||
.field(todoCognitoMultiOwner.editors, is: .optional, ofType: .embeddedCollection(of: String.self)), | ||
.field(todoCognitoMultiOwner.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), | ||
.field(todoCognitoMultiOwner.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) | ||
) | ||
} | ||
} | ||
|
||
extension TodoCognitoMultiOwner: ModelIdentifiable { | ||
public typealias IdentifierFormat = ModelIdentifierFormat.Default | ||
public typealias IdentifierProtocol = DefaultModelIdentifier<Self> | ||
} |
49 changes: 49 additions & 0 deletions
49
...ts/DataStoreHostApp/AWSDataStorePluginAuthCognitoTests/Models/TodoCognitoMultiOwner.swift
This file contains 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,49 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
// swiftlint:disable all | ||
import Amplify | ||
import Foundation | ||
|
||
public struct TodoCognitoMultiOwner: Model { | ||
public let id: String | ||
public var title: String | ||
public var content: String? | ||
public var owner: String? | ||
public var editors: [String?]? | ||
public var createdAt: Temporal.DateTime? | ||
public var updatedAt: Temporal.DateTime? | ||
|
||
public init(id: String = UUID().uuidString, | ||
title: String, | ||
content: String? = nil, | ||
owner: String? = nil, | ||
editors: [String?]? = nil) { | ||
self.init(id: id, | ||
title: title, | ||
content: content, | ||
owner: owner, | ||
editors: editors, | ||
createdAt: nil, | ||
updatedAt: nil) | ||
} | ||
internal init(id: String = UUID().uuidString, | ||
title: String, | ||
content: String? = nil, | ||
owner: String? = nil, | ||
editors: [String?]? = nil, | ||
createdAt: Temporal.DateTime? = nil, | ||
updatedAt: Temporal.DateTime? = nil) { | ||
self.id = id | ||
self.title = title | ||
self.content = content | ||
self.owner = owner | ||
self.editors = editors | ||
self.createdAt = createdAt | ||
self.updatedAt = updatedAt | ||
} | ||
} |
This file contains 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.