Enforce user locks for AI updates

This commit is contained in:
diyaa
2026-09-13 21:20:57 +02:00
parent a39bdbe6fc
commit ae88c6e533
15 changed files with 507 additions and 59 deletions
@@ -23,6 +23,7 @@ public struct SongProject: Codable, Equatable, Identifiable, Sendable {
public var lyrics: Lyrics
public var productionDirections: [ProductionDirection]
public var productionMode: ControlMode?
public var userLocks: SongProjectUserLocks?
public var sunoOutput: SunoOutput?
public var versions: [SongVersion]
public let createdAt: Date
@@ -51,6 +52,7 @@ public struct SongProject: Codable, Equatable, Identifiable, Sendable {
lyrics: Lyrics = Lyrics(),
productionDirections: [ProductionDirection] = [],
productionMode: ControlMode? = .auto,
userLocks: SongProjectUserLocks? = SongProjectUserLocks(),
sunoOutput: SunoOutput? = nil,
versions: [SongVersion] = [],
createdAt: Date = Date(),
@@ -78,6 +80,7 @@ public struct SongProject: Codable, Equatable, Identifiable, Sendable {
self.lyrics = lyrics
self.productionDirections = productionDirections
self.productionMode = productionMode
self.userLocks = userLocks
self.sunoOutput = sunoOutput
self.versions = versions
self.createdAt = createdAt
@@ -102,6 +105,26 @@ public extension SongProject {
productionMode = mode
}
var lockedUpdateScopes: [SongProjectUpdateScope] {
userLocks?.scopes ?? []
}
func isUpdateScopeLocked(_ scope: SongProjectUpdateScope) -> Bool {
userLocks?.contains(scope) ?? false
}
mutating func lockUpdateScope(_ scope: SongProjectUpdateScope) {
var userLocks = userLocks ?? SongProjectUserLocks()
userLocks.insert(scope)
self.userLocks = userLocks
}
mutating func unlockUpdateScope(_ scope: SongProjectUpdateScope) {
guard var userLocks else { return }
userLocks.remove(scope)
self.userLocks = userLocks
}
var orderedSections: [SongSection] {
sections
.enumerated()
@@ -393,6 +416,7 @@ public extension SongProject {
lyrics = snapshot.lyrics
productionDirections = snapshot.productionDirections
productionMode = snapshot.productionMode
userLocks = snapshot.userLocks
sunoOutput = snapshot.sunoOutput
self.updatedAt = updatedAt
}
@@ -795,6 +819,7 @@ public struct SongProjectSnapshot: Codable, Equatable, Sendable {
public var lyrics: Lyrics
public var productionDirections: [ProductionDirection]
public var productionMode: ControlMode?
public var userLocks: SongProjectUserLocks?
public var sunoOutput: SunoOutput?
public init(
@@ -819,6 +844,7 @@ public struct SongProjectSnapshot: Codable, Equatable, Sendable {
lyrics: Lyrics = Lyrics(),
productionDirections: [ProductionDirection] = [],
productionMode: ControlMode? = .auto,
userLocks: SongProjectUserLocks? = SongProjectUserLocks(),
sunoOutput: SunoOutput? = nil
) {
self.title = title
@@ -842,6 +868,7 @@ public struct SongProjectSnapshot: Codable, Equatable, Sendable {
self.lyrics = lyrics
self.productionDirections = productionDirections
self.productionMode = productionMode
self.userLocks = userLocks
self.sunoOutput = sunoOutput
}
@@ -868,6 +895,7 @@ public struct SongProjectSnapshot: Codable, Equatable, Sendable {
lyrics: project.lyrics,
productionDirections: project.productionDirections,
productionMode: project.productionMode,
userLocks: project.userLocks,
sunoOutput: project.sunoOutput
)
}