From 6fd5843d929a1d77a1d3cb07ee742bb5a161f066 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 18 Aug 2022 12:09:07 +0200 Subject: [PATCH] MOBILE-4035 groups: Don't call WS that will fail if no group --- scripts/langindex.json | 1 + .../mod/bigbluebuttonbn/components/index/index.ts | 5 +++++ src/addons/mod/data/components/index/index.ts | 2 +- src/addons/mod/data/pages/edit/edit.ts | 2 +- src/addons/mod/data/pages/entry/entry.ts | 2 +- src/addons/mod/forum/services/handlers/prefetch.ts | 4 ++-- src/addons/mod/lesson/services/handlers/prefetch.ts | 2 +- src/addons/mod/wiki/components/index/index.ts | 8 ++++++-- src/addons/mod/wiki/lang.json | 3 ++- src/core/components/group-selector/group-selector.html | 2 +- src/core/services/groups.ts | 10 ++++------ 11 files changed, 25 insertions(+), 16 deletions(-) diff --git a/scripts/langindex.json b/scripts/langindex.json index ae08079ec..f4057dcb9 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -984,6 +984,7 @@ "addon.mod_url.modulenameplural": "url", "addon.mod_url.pointingtourl": "local_moodlemobileapp", "addon.mod_wiki.cannoteditpage": "wiki", + "addon.mod_wiki.cannotviewpage": "wiki", "addon.mod_wiki.createpage": "wiki", "addon.mod_wiki.editingpage": "wiki", "addon.mod_wiki.errorloadingpage": "local_moodlemobileapp", diff --git a/src/addons/mod/bigbluebuttonbn/components/index/index.ts b/src/addons/mod/bigbluebuttonbn/components/index/index.ts index 444de98c2..610226d45 100644 --- a/src/addons/mod/bigbluebuttonbn/components/index/index.ts +++ b/src/addons/mod/bigbluebuttonbn/components/index/index.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Component, OnInit, Optional } from '@angular/core'; +import { CoreError } from '@classes/errors/error'; import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component'; import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { IonContent } from '@ionic/angular'; @@ -68,6 +69,10 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo this.groupId = CoreGroups.validateGroupId(this.groupId, this.groupInfo); + if (this.groupInfo.separateGroups && !this.groupInfo.groups.length) { + throw new CoreError(Translate.instant('addon.mod_bigbluebuttonbn.view_nojoin')); + } + await this.fetchMeetingInfo(); } diff --git a/src/addons/mod/data/components/index/index.ts b/src/addons/mod/data/components/index/index.ts index bb4b1b8dc..07a9190d3 100644 --- a/src/addons/mod/data/components/index/index.ts +++ b/src/addons/mod/data/components/index/index.ts @@ -218,7 +218,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp } this.groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); - if (this.groupInfo.visibleGroups && this.groupInfo.groups?.length) { + if (this.groupInfo.visibleGroups && this.groupInfo.groups.length) { // There is a bug in Moodle with All participants and visible groups (MOBILE-3597). Remove it. this.groupInfo.groups = this.groupInfo.groups.filter(group => group.id !== 0); this.groupInfo.defaultGroupId = this.groupInfo.groups[0].id; diff --git a/src/addons/mod/data/pages/edit/edit.ts b/src/addons/mod/data/pages/edit/edit.ts index 17cfb151d..00278b312 100644 --- a/src/addons/mod/data/pages/edit/edit.ts +++ b/src/addons/mod/data/pages/edit/edit.ts @@ -179,7 +179,7 @@ export class AddonModDataEditPage implements OnInit { if (refresh) { groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); - if (groupInfo.visibleGroups && groupInfo.groups?.length) { + if (groupInfo.visibleGroups && groupInfo.groups.length) { // There is a bug in Moodle with All participants and visible groups (MOBILE-3597). Remove it. groupInfo.groups = groupInfo.groups.filter(group => group.id !== 0); groupInfo.defaultGroupId = groupInfo.groups[0].id; diff --git a/src/addons/mod/data/pages/entry/entry.ts b/src/addons/mod/data/pages/entry/entry.ts index 761962bb1..bf24b7ef3 100644 --- a/src/addons/mod/data/pages/entry/entry.ts +++ b/src/addons/mod/data/pages/entry/entry.ts @@ -174,7 +174,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { this.access = await AddonModData.getDatabaseAccessInformation(this.database.id, { cmId: this.moduleId }); this.groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); - if (this.groupInfo.visibleGroups && this.groupInfo.groups?.length) { + if (this.groupInfo.visibleGroups && this.groupInfo.groups.length) { // There is a bug in Moodle with All participants and visible groups (MOBILE-3597). Remove it. this.groupInfo.groups = this.groupInfo.groups.filter(group => group.id !== 0); this.groupInfo.defaultGroupId = this.groupInfo.groups[0].id; diff --git a/src/addons/mod/forum/services/handlers/prefetch.ts b/src/addons/mod/forum/services/handlers/prefetch.ts index ed48fb29b..6574fb239 100644 --- a/src/addons/mod/forum/services/handlers/prefetch.ts +++ b/src/addons/mod/forum/services/handlers/prefetch.ts @@ -158,7 +158,7 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe return [0]; } - const allPartsGroup = groupInfo.groups?.find(group => group.id === 0); + const allPartsGroup = groupInfo.groups.find(group => group.id === 0); if (allPartsGroup) { return [0]; // Prefetch all participants. } @@ -168,7 +168,7 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe return [groupInfo.defaultGroupId]; } - return groupInfo.groups?.map(group => group.id) ?? [0]; + return groupInfo.groups.map(group => group.id) ?? [0]; } /** diff --git a/src/addons/mod/lesson/services/handlers/prefetch.ts b/src/addons/mod/lesson/services/handlers/prefetch.ts index 011b47b40..a9455ee70 100644 --- a/src/addons/mod/lesson/services/handlers/prefetch.ts +++ b/src/addons/mod/lesson/services/handlers/prefetch.ts @@ -431,7 +431,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref ): Promise { const groupInfo = await CoreGroups.getActivityGroupInfo(moduleId, false, undefined, modOptions.siteId, true); - await Promise.all(groupInfo.groups?.map(async (group) => { + await Promise.all(groupInfo.groups.map(async (group) => { await AddonModLesson.getRetakesOverview(lessonId, { groupId: group.id, ...modOptions, // Include all options. diff --git a/src/addons/mod/wiki/components/index/index.ts b/src/addons/mod/wiki/components/index/index.ts index 73444595e..830572a90 100644 --- a/src/addons/mod/wiki/components/index/index.ts +++ b/src/addons/mod/wiki/components/index/index.ts @@ -249,6 +249,10 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp // Get real groupmode, in case it's forced by the course. const groupInfo = await CoreGroups.getActivityGroupInfo(this.wiki.coursemodule); + if (groupInfo.separateGroups && !groupInfo.groups.length) { + throw new CoreError(Translate.instant('addon.mod_wiki.cannotviewpage')); + } + await this.createSubwikiList(groupInfo.groups); } else { this.subwikiData.count = subwikiList.count; @@ -867,7 +871,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp * @param userGroups Groups. * @return Promise resolved when done. */ - protected async createSubwikiList(userGroups?: CoreGroup[]): Promise { + protected async createSubwikiList(userGroups: CoreGroup[]): Promise { const subwikiList: AddonModWikiSubwikiListSubwiki[] = []; let allParticipants = false; let showMyGroupsLabel = false; @@ -895,7 +899,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp allParticipants = true; } } else { - if (subwiki.groupid != 0 && userGroups && userGroups.length > 0) { + if (subwiki.groupid != 0 && userGroups.length > 0) { // Get groupLabel if it has groupId. const group = userGroups.find(group => group.id == subwiki.groupid); groupLabel = group?.name || ''; diff --git a/src/addons/mod/wiki/lang.json b/src/addons/mod/wiki/lang.json index 246965b9c..debf37ee7 100644 --- a/src/addons/mod/wiki/lang.json +++ b/src/addons/mod/wiki/lang.json @@ -1,5 +1,6 @@ { "cannoteditpage": "You can not edit this page.", + "cannotviewpage": "You can not view this page.", "createpage": "Create page", "editingpage": "Editing this page '{{$a}}'", "errorloadingpage": "An error occurred while loading the page.", @@ -19,4 +20,4 @@ "viewpage": "View page", "wikipage": "Wiki page", "wrongversionlock": "Another user has edited this page while you were editing and your content is obsolete." -} \ No newline at end of file +} diff --git a/src/core/components/group-selector/group-selector.html b/src/core/components/group-selector/group-selector.html index 2b339bc3d..3c667d8ea 100644 --- a/src/core/components/group-selector/group-selector.html +++ b/src/core/components/group-selector/group-selector.html @@ -1,4 +1,4 @@ - + diff --git a/src/core/services/groups.ts b/src/core/services/groups.ts index 39320f09a..bdf537564 100644 --- a/src/core/services/groups.ts +++ b/src/core/services/groups.ts @@ -170,19 +170,17 @@ export class CoreGroupsProvider { }; } - if (result.groups.length <= 0) { - groupInfo.separateGroups = false; - groupInfo.visibleGroups = false; + if (!result.groups.length) { groupInfo.defaultGroupId = 0; } else { if (result.canaccessallgroups || groupInfo.visibleGroups) { - groupInfo.groups!.push({ id: 0, name: Translate.instant('core.allparticipants') }); + groupInfo.groups.push({ id: 0, name: Translate.instant('core.allparticipants') }); groupInfo.defaultGroupId = 0; } else { groupInfo.defaultGroupId = result.groups[0].id; } - groupInfo.groups = groupInfo.groups!.concat(result.groups); + groupInfo.groups = groupInfo.groups.concat(result.groups); } return groupInfo; @@ -458,7 +456,7 @@ export type CoreGroupInfo = { /** * List of groups. */ - groups?: CoreGroup[]; + groups: CoreGroup[]; /** * Whether it's separate groups.