MOBILE-4362 workshop: Fix phantom offline submissions

main
Pau Ferrer Ocaña 2023-10-19 10:45:48 +02:00
parent 4e210350e5
commit 95cd22e76f
2 changed files with 22 additions and 19 deletions

View File

@ -449,7 +449,14 @@ export class AddonModWorkshopHelperProvider {
* @returns Promise resolved with the files.
*/
async applyOfflineData(
submission: AddonModWorkshopSubmissionDataWithOfflineData = {
submission?: AddonModWorkshopSubmissionDataWithOfflineData,
actions: AddonModWorkshopOfflineSubmission[] = [],
): Promise<AddonModWorkshopSubmissionDataWithOfflineData | undefined> {
if (actions.length === 0) {
return submission;
}
const baseSubmission = submission ?? {
id: 0,
workshopid: 0,
title: '',
@ -462,12 +469,7 @@ export class AddonModWorkshopHelperProvider {
attachment: 0,
published: false,
late: 0,
},
actions: AddonModWorkshopOfflineSubmission[] = [],
): Promise<AddonModWorkshopSubmissionDataWithOfflineData | undefined> {
if (actions.length === 0) {
return submission;
}
};
let attachmentsId: CoreFileUploaderStoreFilesResult | undefined;
const workshopId = actions[0].workshopid;
@ -476,17 +478,17 @@ export class AddonModWorkshopHelperProvider {
switch (action.action) {
case AddonModWorkshopAction.ADD:
case AddonModWorkshopAction.UPDATE:
submission.title = action.title;
submission.content = action.content;
submission.title = action.title;
submission.courseid = action.courseid;
submission.submissionmodified = action.timemodified / 1000;
submission.offline = true;
baseSubmission.title = action.title;
baseSubmission.content = action.content;
baseSubmission.title = action.title;
baseSubmission.courseid = action.courseid;
baseSubmission.submissionmodified = action.timemodified / 1000;
baseSubmission.offline = true;
attachmentsId = action.attachmentsid as CoreFileUploaderStoreFilesResult;
break;
case AddonModWorkshopAction.DELETE:
submission.deleted = true;
submission.submissionmodified = action.timemodified / 1000;
baseSubmission.deleted = true;
baseSubmission.submissionmodified = action.timemodified / 1000;
break;
default:
}
@ -494,13 +496,13 @@ export class AddonModWorkshopHelperProvider {
// Check offline files for latest attachmentsid.
if (attachmentsId) {
submission.attachmentfiles =
baseSubmission.attachmentfiles =
await this.getSubmissionFilesFromOfflineFilesObject(attachmentsId, workshopId);
} else {
submission.attachmentfiles = [];
baseSubmission.attachmentfiles = [];
}
return submission;
return baseSubmission;
}
/**

View File

@ -49,13 +49,14 @@ Feature: Test basic usage of workshop activity in app
Given I entered the workshop activity "workshop" on course "Course 1" as "student1" in the app
Then I should find "Task to do" within "Submit your work" "ion-item" in the app
When I press "Edit submission" in the app
When I press "Add submission" in the app
And I set the field "Title" to "The Answer" in the app
And I set the field "Submission content" to "42" in the app
And I press "Save" in the app
Then I should find "Task done" within "Submit your work" "ion-item" in the app
And I should find "The Answer" in the app
And I should find "42" in the app
And I should find "Edit submission" in the app
Given I entered the workshop activity "workshop" on course "Course 1" as "teacher1" in the app
When I pull to refresh in the app