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. * @returns Promise resolved with the files.
*/ */
async applyOfflineData( async applyOfflineData(
submission: AddonModWorkshopSubmissionDataWithOfflineData = { submission?: AddonModWorkshopSubmissionDataWithOfflineData,
actions: AddonModWorkshopOfflineSubmission[] = [],
): Promise<AddonModWorkshopSubmissionDataWithOfflineData | undefined> {
if (actions.length === 0) {
return submission;
}
const baseSubmission = submission ?? {
id: 0, id: 0,
workshopid: 0, workshopid: 0,
title: '', title: '',
@ -462,12 +469,7 @@ export class AddonModWorkshopHelperProvider {
attachment: 0, attachment: 0,
published: false, published: false,
late: 0, late: 0,
}, };
actions: AddonModWorkshopOfflineSubmission[] = [],
): Promise<AddonModWorkshopSubmissionDataWithOfflineData | undefined> {
if (actions.length === 0) {
return submission;
}
let attachmentsId: CoreFileUploaderStoreFilesResult | undefined; let attachmentsId: CoreFileUploaderStoreFilesResult | undefined;
const workshopId = actions[0].workshopid; const workshopId = actions[0].workshopid;
@ -476,17 +478,17 @@ export class AddonModWorkshopHelperProvider {
switch (action.action) { switch (action.action) {
case AddonModWorkshopAction.ADD: case AddonModWorkshopAction.ADD:
case AddonModWorkshopAction.UPDATE: case AddonModWorkshopAction.UPDATE:
submission.title = action.title; baseSubmission.title = action.title;
submission.content = action.content; baseSubmission.content = action.content;
submission.title = action.title; baseSubmission.title = action.title;
submission.courseid = action.courseid; baseSubmission.courseid = action.courseid;
submission.submissionmodified = action.timemodified / 1000; baseSubmission.submissionmodified = action.timemodified / 1000;
submission.offline = true; baseSubmission.offline = true;
attachmentsId = action.attachmentsid as CoreFileUploaderStoreFilesResult; attachmentsId = action.attachmentsid as CoreFileUploaderStoreFilesResult;
break; break;
case AddonModWorkshopAction.DELETE: case AddonModWorkshopAction.DELETE:
submission.deleted = true; baseSubmission.deleted = true;
submission.submissionmodified = action.timemodified / 1000; baseSubmission.submissionmodified = action.timemodified / 1000;
break; break;
default: default:
} }
@ -494,13 +496,13 @@ export class AddonModWorkshopHelperProvider {
// Check offline files for latest attachmentsid. // Check offline files for latest attachmentsid.
if (attachmentsId) { if (attachmentsId) {
submission.attachmentfiles = baseSubmission.attachmentfiles =
await this.getSubmissionFilesFromOfflineFilesObject(attachmentsId, workshopId); await this.getSubmissionFilesFromOfflineFilesObject(attachmentsId, workshopId);
} else { } 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 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 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 "Title" to "The Answer" in the app
And I set the field "Submission content" to "42" in the app And I set the field "Submission content" to "42" in the app
And I press "Save" 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 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 "The Answer" in the app
And I should find "42" 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 Given I entered the workshop activity "workshop" on course "Course 1" as "teacher1" in the app
When I pull to refresh in the app When I pull to refresh in the app