Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Core/Core/Features/Notebook/Model/CDNotebookNote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ final public class CDNotebookNote: NSManagedObject {
@NSManaged public var start: NSNumber?
@NSManaged public var startContainer: String?
@NSManaged public var startOffset: NSNumber?
@NSManaged public var userID: String?
}

extension String? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23788" systemVersion="24E263" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23788" systemVersion="24F74" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="AccountNotification" representedClassName="Core.AccountNotification" syncable="YES">
<attribute name="endAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="iconRaw" attributeType="String"/>
Expand Down Expand Up @@ -230,25 +230,6 @@
<attribute name="useOutOfOffice" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="useSignature" attributeType="Boolean" usesScalarValueType="YES"/>
</entity>
<entity name="CDRubricCriterion" representedClassName="Core.CDRubricCriterion" syncable="YES">
<attribute name="assignmentID" attributeType="String"/>
<attribute name="criterionUseRange" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="id" attributeType="String"/>
<attribute name="ignoreForScoring" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="longDescription" attributeType="String"/>
<attribute name="points" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="shortDescription" attributeType="String"/>
<relationship name="assignment" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Assignment" inverseName="rubricRaw" inverseEntity="Assignment"/>
<relationship name="ratingsRaw" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="CDRubricRating" inverseName="rubric" inverseEntity="CDRubricRating"/>
</entity>
<entity name="CDRubricRating" representedClassName="Core.CDRubricRating" syncable="YES">
<attribute name="assignmentID" attributeType="String"/>
<attribute name="id" attributeType="String"/>
<attribute name="longDescription" attributeType="String"/>
<attribute name="points" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="shortDescription" attributeType="String"/>
<relationship name="rubric" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="CDRubricCriterion" inverseName="ratingsRaw" inverseEntity="CDRubricCriterion"/>
</entity>
<entity name="CDLearnCourse" representedClassName="Core.CDLearnCourse" syncable="YES">
<attribute name="enrollmentId" attributeType="String"/>
<attribute name="id" attributeType="String"/>
Expand All @@ -271,6 +252,26 @@
<attribute name="start" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="startContainer" optional="YES" attributeType="String"/>
<attribute name="startOffset" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="userID" optional="YES" attributeType="String"/>
</entity>
<entity name="CDRubricCriterion" representedClassName="Core.CDRubricCriterion" syncable="YES">
<attribute name="assignmentID" attributeType="String"/>
<attribute name="criterionUseRange" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="id" attributeType="String"/>
<attribute name="ignoreForScoring" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="longDescription" attributeType="String"/>
<attribute name="points" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="shortDescription" attributeType="String"/>
<relationship name="assignment" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Assignment" inverseName="rubricRaw" inverseEntity="Assignment"/>
<relationship name="ratingsRaw" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="CDRubricRating" inverseName="rubric" inverseEntity="CDRubricRating"/>
</entity>
<entity name="CDRubricRating" representedClassName="Core.CDRubricRating" syncable="YES">
<attribute name="assignmentID" attributeType="String"/>
<attribute name="id" attributeType="String"/>
<attribute name="longDescription" attributeType="String"/>
<attribute name="points" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="shortDescription" attributeType="String"/>
<relationship name="rubric" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="CDRubricCriterion" inverseName="ratingsRaw" inverseEntity="CDRubricCriterion"/>
</entity>
<entity name="CDScoresAssignment" representedClassName="Core.CDScoresAssignment" syncable="YES">
<attribute name="commentsCount" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// This file is part of Canvas.
// Copyright (C) 2025-present Instructure, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

import Core
import CoreData

extension CDNotebookNote {
@discardableResult
public static func save(
_ item: RedwoodNote,
userID: String,
notebookNote: CDNotebookNote? = nil,
in context: NSManagedObjectContext
) -> CDNotebookNote {
let model: CDNotebookNote = notebookNote ?? context.first(where: #keyPath(CDNotebookNote.id), equals: item.id) ?? context.insert()
model.userID = userID
model.content = item.userText
model.courseID = item.courseId
model.date = item.createdAt
if let end = item.highlightData?.textPosition.end {
model.end = NSNumber(value: end)
}
model.endContainer = item.highlightData?.range.endContainer
if let endOffset = item.highlightData?.range.endOffset {
model.endOffset = NSNumber(value: endOffset)
}
model.id = item.id
model.labels = item.reaction?.serializeLabels
model.objectType = item.objectType
model.pageID = item.objectId
model.selectedText = item.highlightData?.selectedText
if let start = item.highlightData?.textPosition.start {
model.start = NSNumber(value: start)
}
model.startContainer = item.highlightData?.range.startContainer
if let startOffset = item.highlightData?.range.startOffset {
model.startOffset = NSNumber(value: startOffset)
}

return model
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ class AddNotebookNoteUseCase: UseCase {

func write(response: RedwoodCreateNoteMutationResponse?, urlResponse: URLResponse?, to client: NSManagedObjectContext) {
if let redwoodNote = response?.data.createNote {
CDNotebookNote.save(redwoodNote, in: client)
CDNotebookNote.save(
redwoodNote,
userID: Context.currentUser.id,
in: client
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class GetNotebookNotesUseCase: CollectionUseCase {
let request = GetNotesQuery()

public var scope: Scope {
var predicates: [NSPredicate] = []
var predicates: [NSPredicate] = [
NSPredicate(format: "%K == %@", #keyPath(CDNotebookNote.userID), Context.currentUser.id)
]
if let courseID = courseID {
predicates.append(NSPredicate(format: "%K == %@", #keyPath(CDNotebookNote.courseID), courseID))
}
Expand Down Expand Up @@ -101,7 +103,11 @@ class GetNotebookNotesUseCase: CollectionUseCase {
let removed = tuple.1

changed.forEach { redwoodNote in
CDNotebookNote.save(redwoodNote, in: client)
CDNotebookNote.save(
redwoodNote,
userID: Context.currentUser.id,
in: client
)
}

removed.forEach { cdNotebookNote in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,17 @@ class UpdateNotebookNoteUseCase: UseCase {
.store(in: &subscriptions)
}

func write(response: RedwoodUpdateNoteMutationResponse?, urlResponse: URLResponse?, to client: NSManagedObjectContext) {
func write(
response: RedwoodUpdateNoteMutationResponse?,
urlResponse: URLResponse?,
to client: NSManagedObjectContext
) {
if let redwoodNote = response?.data.updateNote {
CDNotebookNote.save(redwoodNote, in: client)
}
}
}

extension CDNotebookNote {
@discardableResult
public static func save(
_ item: RedwoodNote,
notebookNote: CDNotebookNote? = nil,
in context: NSManagedObjectContext
) -> CDNotebookNote {
let model: CDNotebookNote = notebookNote ?? context.first(where: #keyPath(CDNotebookNote.id), equals: item.id) ?? context.insert()

model.content = item.userText
model.courseID = item.courseId
model.date = item.createdAt
if let end = item.highlightData?.textPosition.end {
model.end = NSNumber(value: end)
}
model.endContainer = item.highlightData?.range.endContainer
if let endOffset = item.highlightData?.range.endOffset {
model.endOffset = NSNumber(value: endOffset)
}
model.id = item.id
model.labels = item.reaction?.serializeLabels
model.objectType = item.objectType
model.pageID = item.objectId
model.selectedText = item.highlightData?.selectedText
if let start = item.highlightData?.textPosition.start {
model.start = NSNumber(value: start)
}
model.startContainer = item.highlightData?.range.startContainer
if let startOffset = item.highlightData?.range.startOffset {
model.startOffset = NSNumber(value: startOffset)
CDNotebookNote.save(
redwoodNote,
userID: Context.currentUser.id,
in: client
)
}

return model
}
}