diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index 1c643b2..2f600f8 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -46,4 +46,23 @@ class DataStore: ObservableObject { self.objectWillChange.send() } + var globalRights: UserRight { + if let _ = Guard.main.currentPlan { + return .creation + } + if let user = self.user, user.club_id != nil { + if user.umpire_code != nil { + return .creation + } else { + return .edition + } + } + + // TODO what are the rules when testing the app? + // scenario example: one cancelled tournament + + + return .none + } + } diff --git a/PadelClub/Views/Subscription/Guard.swift b/PadelClub/Views/Subscription/Guard.swift index 95e8017..67a4576 100644 --- a/PadelClub/Views/Subscription/Guard.swift +++ b/PadelClub/Views/Subscription/Guard.swift @@ -103,7 +103,7 @@ import LeStorage return transaction } - var currentPlan: StoreItem { + var currentPlan: StoreItem? { #if DEBUG return .monthly @@ -116,7 +116,7 @@ import LeStorage let plan = StorePlan(rawValue: vf.productId) { return plan } - return .none + return nil #endif } diff --git a/PadelClub/Views/User/User.swift b/PadelClub/Views/User/User.swift index f0ca1f2..d65d9fb 100644 --- a/PadelClub/Views/User/User.swift +++ b/PadelClub/Views/User/User.swift @@ -8,11 +8,19 @@ import Foundation import LeStorage +enum UserRight: Int, Codable { + case none = 0 + case edition = 1 + case creation = 2 +} + class User: UserBase { public var id: String = Store.randomId() public var username: String public var email: String? + var club_id: String? + var umpire_code: String? init(username: String, email: String? = nil) { self.username = username