From 628f380d7c3e4aef895eccc04f7a39ba5f51eaa9 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 22 Jul 2021 14:40:51 +0200 Subject: [PATCH] MOBILE-3780 course: Use right max upload size when set to course limit --- .../mod/assign/services/handlers/prefetch.ts | 3 ++ .../addon-mod-assign-submission-file.html | 2 +- .../component/addon-mod-data-field-file.html | 2 +- .../addon-mod-data-field-picture.html | 2 +- .../mod/data/services/handlers/prefetch.ts | 4 ++ .../forum/components/edit-post/edit-post.html | 2 +- .../mod/forum/components/post/post.html | 2 +- .../pages/new-discussion/new-discussion.html | 2 +- .../new-discussion/new-discussion.page.ts | 2 +- .../mod/forum/services/handlers/prefetch.ts | 4 ++ src/addons/mod/glossary/pages/edit/edit.html | 2 +- .../glossary/services/handlers/prefetch.ts | 5 +++ .../mod/quiz/services/handlers/prefetch.ts | 4 ++ ...ddon-mod-workshop-assessment-strategy.html | 2 +- .../edit-submission/edit-submission.html | 3 +- .../workshop/services/handlers/prefetch.ts | 4 ++ .../essay/component/addon-qtype-essay.html | 2 +- .../components/attachments/attachments.ts | 45 ++++++++++++++----- 18 files changed, 71 insertions(+), 21 deletions(-) diff --git a/src/addons/mod/assign/services/handlers/prefetch.ts b/src/addons/mod/assign/services/handlers/prefetch.ts index 2c909584e..8d84587d0 100644 --- a/src/addons/mod/assign/services/handlers/prefetch.ts +++ b/src/addons/mod/assign/services/handlers/prefetch.ts @@ -35,6 +35,7 @@ import { CoreGroups } from '@services/groups'; import { AddonModAssignSync, AddonModAssignSyncResult } from '../assign-sync'; import { CoreUser } from '@features/user/services/user'; import { CoreGradesHelper } from '@features/grades/services/grades-helper'; +import { CoreCourses } from '@features/courses/services/courses'; /** * Handler to prefetch assigns. @@ -252,6 +253,8 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref promises.push(this.prefetchSubmissions(assign, courseId, module.id, userId, siteId)); promises.push(CoreCourseHelper.getModuleCourseIdByInstance(assign.id, 'assign', siteId)); + // Get course data, needed to determine upload max size if it's configured to be course limit. + promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); // Download intro files and attachments. Do not call getFiles because it'd call some WS twice. let files: CoreWSFile[] = assign.introattachments || []; diff --git a/src/addons/mod/assign/submission/file/component/addon-mod-assign-submission-file.html b/src/addons/mod/assign/submission/file/component/addon-mod-assign-submission-file.html index 92517dd92..af3d5235f 100644 --- a/src/addons/mod/assign/submission/file/component/addon-mod-assign-submission-file.html +++ b/src/addons/mod/assign/submission/file/component/addon-mod-assign-submission-file.html @@ -13,7 +13,7 @@

{{ plugin.name }}

- diff --git a/src/addons/mod/data/fields/file/component/addon-mod-data-field-file.html b/src/addons/mod/data/fields/file/component/addon-mod-data-field-file.html index 4afdd5eb6..286e96940 100644 --- a/src/addons/mod/data/fields/file/component/addon-mod-data-field-file.html +++ b/src/addons/mod/data/fields/file/component/addon-mod-data-field-file.html @@ -1,7 +1,7 @@ + [componentId]="componentId" [allowOffline]="true" [courseId]="database?.course"> diff --git a/src/addons/mod/data/fields/picture/component/addon-mod-data-field-picture.html b/src/addons/mod/data/fields/picture/component/addon-mod-data-field-picture.html index d00754fdc..bf10ea74e 100644 --- a/src/addons/mod/data/fields/picture/component/addon-mod-data-field-picture.html +++ b/src/addons/mod/data/fields/picture/component/addon-mod-data-field-picture.html @@ -1,7 +1,7 @@ + [componentId]="componentId" [allowOffline]="true" acceptedTypes="image" [courseId]="database?.course"> diff --git a/src/addons/mod/data/services/handlers/prefetch.ts b/src/addons/mod/data/services/handlers/prefetch.ts index 92844d596..01446305c 100644 --- a/src/addons/mod/data/services/handlers/prefetch.ts +++ b/src/addons/mod/data/services/handlers/prefetch.ts @@ -16,6 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreComments } from '@features/comments/services/comments'; import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler'; import { CoreCourseCommonModWSOptions, CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; +import { CoreCourses } from '@features/courses/services/courses'; import { CoreFilepool } from '@services/filepool'; import { CoreGroup, CoreGroups } from '@services/groups'; import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites'; @@ -269,6 +270,9 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet // Add Basic Info to manage links. promises.push(CoreCourse.getModuleBasicInfoByInstance(database.id, 'data', siteId)); + // Get course data, needed to determine upload max size if it's configured to be course limit. + promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + await Promise.all(promises); } diff --git a/src/addons/mod/forum/components/edit-post/edit-post.html b/src/addons/mod/forum/components/edit-post/edit-post.html index 60a500105..19f1c65ba 100644 --- a/src/addons/mod/forum/components/edit-post/edit-post.html +++ b/src/addons/mod/forum/components/edit-post/edit-post.html @@ -41,7 +41,7 @@
+ [component]="component" [componentId]="forum.cmid" [courseId]="forum.course">
diff --git a/src/addons/mod/forum/components/post/post.html b/src/addons/mod/forum/components/post/post.html index a3b998b29..89dbb0ed0 100644 --- a/src/addons/mod/forum/components/post/post.html +++ b/src/addons/mod/forum/components/post/post.html @@ -139,7 +139,7 @@
+ [component]="component" [componentId]="forum.cmid" [allowOffline]="true" [courseId]="courseId">
diff --git a/src/addons/mod/forum/pages/new-discussion/new-discussion.html b/src/addons/mod/forum/pages/new-discussion/new-discussion.html index c37f3edef..6155f595b 100644 --- a/src/addons/mod/forum/pages/new-discussion/new-discussion.html +++ b/src/addons/mod/forum/pages/new-discussion/new-discussion.html @@ -68,7 +68,7 @@ + [component]="component" [componentId]="forum.cmid" [allowOffline]="true" [courseId]="courseId"> diff --git a/src/addons/mod/forum/pages/new-discussion/new-discussion.page.ts b/src/addons/mod/forum/pages/new-discussion/new-discussion.page.ts index f47f8a5b4..71e71d97e 100644 --- a/src/addons/mod/forum/pages/new-discussion/new-discussion.page.ts +++ b/src/addons/mod/forum/pages/new-discussion/new-discussion.page.ts @@ -86,8 +86,8 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea advanced = false; // Display all form fields. accessInfo: AddonModForumAccessInformation = {}; + courseId!: number; - protected courseId!: number; protected cmId!: number; protected forumId!: number; protected timeCreated!: number; diff --git a/src/addons/mod/forum/services/handlers/prefetch.ts b/src/addons/mod/forum/services/handlers/prefetch.ts index 7b7f62dbb..41357fcf6 100644 --- a/src/addons/mod/forum/services/handlers/prefetch.ts +++ b/src/addons/mod/forum/services/handlers/prefetch.ts @@ -24,6 +24,7 @@ import { CoreGroups, CoreGroupsProvider } from '@services/groups'; import { CoreUtils } from '@services/utils/utils'; import { AddonModForumSync } from '../forum-sync'; import { makeSingleton } from '@singletons'; +import { CoreCourses } from '@features/courses/services/courses'; /** * Handler to prefetch forums. @@ -229,6 +230,9 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe promises.push(CoreUser.getUserPreference(AddonModForumProvider.PREFERENCE_SORTORDER, siteId)); } + // Get course data, needed to determine upload max size if it's configured to be course limit. + promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + await Promise.all(promises); } diff --git a/src/addons/mod/glossary/pages/edit/edit.html b/src/addons/mod/glossary/pages/edit/edit.html index 1c7d899ff..9ab191489 100644 --- a/src/addons/mod/glossary/pages/edit/edit.html +++ b/src/addons/mod/glossary/pages/edit/edit.html @@ -50,7 +50,7 @@

{{ 'addon.mod_glossary.attachment' | translate }}

+ [allowOffline]="true" [courseId]="courseId"> diff --git a/src/addons/mod/glossary/services/handlers/prefetch.ts b/src/addons/mod/glossary/services/handlers/prefetch.ts index 3c29641d3..16236256d 100644 --- a/src/addons/mod/glossary/services/handlers/prefetch.ts +++ b/src/addons/mod/glossary/services/handlers/prefetch.ts @@ -16,9 +16,11 @@ import { Injectable } from '@angular/core'; import { CoreComments } from '@features/comments/services/comments'; import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; +import { CoreCourses } from '@features/courses/services/courses'; import { CoreUser } from '@features/user/services/user'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; +import { CoreUtils } from '@services/utils/utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModGlossary, AddonModGlossaryEntry, AddonModGlossaryGlossary, AddonModGlossaryProvider } from '../glossary'; @@ -210,6 +212,9 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr promises.push(CoreCourse.getModuleBasicInfo(module.id, siteId)); promises.push(CoreCourse.getModuleBasicInfoByInstance(glossary.id, 'glossary', siteId)); + // Get course data, needed to determine upload max size if it's configured to be course limit. + promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + await Promise.all(promises); } diff --git a/src/addons/mod/quiz/services/handlers/prefetch.ts b/src/addons/mod/quiz/services/handlers/prefetch.ts index 982b5920e..1ee999c75 100644 --- a/src/addons/mod/quiz/services/handlers/prefetch.ts +++ b/src/addons/mod/quiz/services/handlers/prefetch.ts @@ -18,6 +18,7 @@ import { Injectable } from '@angular/core'; import { CoreError } from '@classes/errors/error'; import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler'; import { CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; +import { CoreCourses } from '@features/courses/services/courses'; import { CoreQuestionHelper } from '@features/question/services/question-helper'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; @@ -374,6 +375,9 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet promises.push(this.prefetchGradeAndFeedback(quiz, modOptions, siteId)); promises.push(AddonModQuiz.getAttemptAccessInformation(quiz.id, 0, modOptions)); // Last attempt. + // Get course data, needed to determine upload max size if it's configured to be course limit. + promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + await Promise.all(promises); // We have quiz data, now we'll get specific data for each attempt. diff --git a/src/addons/mod/workshop/components/assessment-strategy/addon-mod-workshop-assessment-strategy.html b/src/addons/mod/workshop/components/assessment-strategy/addon-mod-workshop-assessment-strategy.html index df65c40e7..42baab58b 100644 --- a/src/addons/mod/workshop/components/assessment-strategy/addon-mod-workshop-assessment-strategy.html +++ b/src/addons/mod/workshop/components/assessment-strategy/addon-mod-workshop-assessment-strategy.html @@ -37,7 +37,7 @@
+ [component]="component" [componentId]="componentId" [allowOffline]="true" [courseId]="workshop.course"> diff --git a/src/addons/mod/workshop/pages/edit-submission/edit-submission.html b/src/addons/mod/workshop/pages/edit-submission/edit-submission.html index e39705bf9..ad52ca562 100644 --- a/src/addons/mod/workshop/pages/edit-submission/edit-submission.html +++ b/src/addons/mod/workshop/pages/edit-submission/edit-submission.html @@ -39,7 +39,8 @@ + allowOffline="true" [acceptedTypes]="workshop.submissionfiletypes" [required]="fileRequired" + [courseId]="workshop.course"> diff --git a/src/addons/mod/workshop/services/handlers/prefetch.ts b/src/addons/mod/workshop/services/handlers/prefetch.ts index 088002c86..c0903280a 100644 --- a/src/addons/mod/workshop/services/handlers/prefetch.ts +++ b/src/addons/mod/workshop/services/handlers/prefetch.ts @@ -16,6 +16,7 @@ import { AddonModDataSyncResult } from '@addons/mod/data/services/data-sync'; import { Injectable } from '@angular/core'; import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; +import { CoreCourses } from '@features/courses/services/courses'; import { CoreUser } from '@features/user/services/user'; import { CoreFilepool } from '@services/filepool'; import { CoreGroup, CoreGroups } from '@services/groups'; @@ -372,6 +373,9 @@ export class AddonModWorkshopPrefetchHandlerService extends CoreCourseActivityPr promises.push(CoreCourse.getModuleBasicInfoByInstance(workshop.id, 'workshop', siteId)); promises.push(CoreCourse.getModuleBasicGradeInfo(module.id, siteId)); + // Get course data, needed to determine upload max size if it's configured to be course limit. + promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + await Promise.all(promises); // Prefetch user profiles. diff --git a/src/addons/qtype/essay/component/addon-qtype-essay.html b/src/addons/qtype/essay/component/addon-qtype-essay.html index 40e4359b7..a70656f8a 100644 --- a/src/addons/qtype/essay/component/addon-qtype-essay.html +++ b/src/addons/qtype/essay/component/addon-qtype-essay.html @@ -52,7 +52,7 @@ + [acceptedTypes]="essayQuestion.attachmentsAcceptedTypes" [courseId]="courseId"> 0) { this.maxSizeReadable = CoreTextUtils.bytesToSize(this.maxSize, 2); } else if (this.maxSize === -1) { @@ -97,6 +92,36 @@ export class CoreAttachmentsComponent implements OnInit { } } + /** + * Get max size of the area. + * + * @return Promise resolved when done. + */ + protected async getMaxSizeOfArea(): Promise { + if (this.courseId) { + // Check course max size. + const course = await CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', this.courseId)); + + if (course?.maxbytes) { + this.maxSize = course.maxbytes; + this.maxSizeReadable = CoreTextUtils.bytesToSize(this.maxSize, 2); + + return; + } + } + + // Check user max size. + const currentSite = CoreSites.getCurrentSite(); + const siteInfo = currentSite?.getInfo(); + + if (siteInfo?.usermaxuploadfilesize) { + this.maxSize = siteInfo.usermaxuploadfilesize; + this.maxSizeReadable = CoreTextUtils.bytesToSize(this.maxSize, 2); + } else { + this.maxSizeReadable = Translate.instant('core.unknown'); + } + } + /** * Add a new attachment. */