MOBILE-4035 groups: Don't call WS that will fail if no group

main
Dani Palou 2022-08-18 12:09:07 +02:00
parent 33b3d7db78
commit 6fd5843d92
11 changed files with 25 additions and 16 deletions

View File

@ -984,6 +984,7 @@
"addon.mod_url.modulenameplural": "url", "addon.mod_url.modulenameplural": "url",
"addon.mod_url.pointingtourl": "local_moodlemobileapp", "addon.mod_url.pointingtourl": "local_moodlemobileapp",
"addon.mod_wiki.cannoteditpage": "wiki", "addon.mod_wiki.cannoteditpage": "wiki",
"addon.mod_wiki.cannotviewpage": "wiki",
"addon.mod_wiki.createpage": "wiki", "addon.mod_wiki.createpage": "wiki",
"addon.mod_wiki.editingpage": "wiki", "addon.mod_wiki.editingpage": "wiki",
"addon.mod_wiki.errorloadingpage": "local_moodlemobileapp", "addon.mod_wiki.errorloadingpage": "local_moodlemobileapp",

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
import { Component, OnInit, Optional } from '@angular/core'; import { Component, OnInit, Optional } from '@angular/core';
import { CoreError } from '@classes/errors/error';
import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component'; import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component';
import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { CoreCourseContentsPage } from '@features/course/pages/contents/contents';
import { IonContent } from '@ionic/angular'; import { IonContent } from '@ionic/angular';
@ -68,6 +69,10 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo
this.groupId = CoreGroups.validateGroupId(this.groupId, this.groupInfo); 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(); await this.fetchMeetingInfo();
} }

View File

@ -218,7 +218,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
} }
this.groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); 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. // 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.groups = this.groupInfo.groups.filter(group => group.id !== 0);
this.groupInfo.defaultGroupId = this.groupInfo.groups[0].id; this.groupInfo.defaultGroupId = this.groupInfo.groups[0].id;

View File

@ -179,7 +179,7 @@ export class AddonModDataEditPage implements OnInit {
if (refresh) { if (refresh) {
groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); 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. // 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.groups = groupInfo.groups.filter(group => group.id !== 0);
groupInfo.defaultGroupId = groupInfo.groups[0].id; groupInfo.defaultGroupId = groupInfo.groups[0].id;

View File

@ -174,7 +174,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
this.access = await AddonModData.getDatabaseAccessInformation(this.database.id, { cmId: this.moduleId }); this.access = await AddonModData.getDatabaseAccessInformation(this.database.id, { cmId: this.moduleId });
this.groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); 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. // 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.groups = this.groupInfo.groups.filter(group => group.id !== 0);
this.groupInfo.defaultGroupId = this.groupInfo.groups[0].id; this.groupInfo.defaultGroupId = this.groupInfo.groups[0].id;

View File

@ -158,7 +158,7 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe
return [0]; return [0];
} }
const allPartsGroup = groupInfo.groups?.find(group => group.id === 0); const allPartsGroup = groupInfo.groups.find(group => group.id === 0);
if (allPartsGroup) { if (allPartsGroup) {
return [0]; // Prefetch all participants. return [0]; // Prefetch all participants.
} }
@ -168,7 +168,7 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe
return [groupInfo.defaultGroupId]; return [groupInfo.defaultGroupId];
} }
return groupInfo.groups?.map(group => group.id) ?? [0]; return groupInfo.groups.map(group => group.id) ?? [0];
} }
/** /**

View File

@ -431,7 +431,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref
): Promise<void> { ): Promise<void> {
const groupInfo = await CoreGroups.getActivityGroupInfo(moduleId, false, undefined, modOptions.siteId, true); 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, { await AddonModLesson.getRetakesOverview(lessonId, {
groupId: group.id, groupId: group.id,
...modOptions, // Include all options. ...modOptions, // Include all options.

View File

@ -249,6 +249,10 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
// Get real groupmode, in case it's forced by the course. // Get real groupmode, in case it's forced by the course.
const groupInfo = await CoreGroups.getActivityGroupInfo(this.wiki.coursemodule); 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); await this.createSubwikiList(groupInfo.groups);
} else { } else {
this.subwikiData.count = subwikiList.count; this.subwikiData.count = subwikiList.count;
@ -867,7 +871,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
* @param userGroups Groups. * @param userGroups Groups.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async createSubwikiList(userGroups?: CoreGroup[]): Promise<void> { protected async createSubwikiList(userGroups: CoreGroup[]): Promise<void> {
const subwikiList: AddonModWikiSubwikiListSubwiki[] = []; const subwikiList: AddonModWikiSubwikiListSubwiki[] = [];
let allParticipants = false; let allParticipants = false;
let showMyGroupsLabel = false; let showMyGroupsLabel = false;
@ -895,7 +899,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
allParticipants = true; allParticipants = true;
} }
} else { } else {
if (subwiki.groupid != 0 && userGroups && userGroups.length > 0) { if (subwiki.groupid != 0 && userGroups.length > 0) {
// Get groupLabel if it has groupId. // Get groupLabel if it has groupId.
const group = userGroups.find(group => group.id == subwiki.groupid); const group = userGroups.find(group => group.id == subwiki.groupid);
groupLabel = group?.name || ''; groupLabel = group?.name || '';

View File

@ -1,5 +1,6 @@
{ {
"cannoteditpage": "You can not edit this page.", "cannoteditpage": "You can not edit this page.",
"cannotviewpage": "You can not view this page.",
"createpage": "Create page", "createpage": "Create page",
"editingpage": "Editing this page '{{$a}}'", "editingpage": "Editing this page '{{$a}}'",
"errorloadingpage": "An error occurred while loading the page.", "errorloadingpage": "An error occurred while loading the page.",
@ -19,4 +20,4 @@
"viewpage": "View page", "viewpage": "View page",
"wikipage": "Wiki page", "wikipage": "Wiki page",
"wrongversionlock": "Another user has edited this page while you were editing and your content is obsolete." "wrongversionlock": "Another user has edited this page while you were editing and your content is obsolete."
} }

View File

@ -1,4 +1,4 @@
<ng-container *ngIf="groupInfo && (groupInfo.separateGroups || groupInfo.visibleGroups)"> <ng-container *ngIf="groupInfo && groupInfo.groups.length > 0 && (groupInfo.separateGroups || groupInfo.visibleGroups)">
<ion-card class="core-info-card" *ngIf="multipleGroupsMessage && groupInfo.groups && groupInfo.groups.length > 1"> <ion-card class="core-info-card" *ngIf="multipleGroupsMessage && groupInfo.groups && groupInfo.groups.length > 1">
<ion-item> <ion-item>
<ion-icon name="fas-question-circle" slot="start" aria-hidden="true"></ion-icon> <ion-icon name="fas-question-circle" slot="start" aria-hidden="true"></ion-icon>

View File

@ -170,19 +170,17 @@ export class CoreGroupsProvider {
}; };
} }
if (result.groups.length <= 0) { if (!result.groups.length) {
groupInfo.separateGroups = false;
groupInfo.visibleGroups = false;
groupInfo.defaultGroupId = 0; groupInfo.defaultGroupId = 0;
} else { } else {
if (result.canaccessallgroups || groupInfo.visibleGroups) { 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; groupInfo.defaultGroupId = 0;
} else { } else {
groupInfo.defaultGroupId = result.groups[0].id; groupInfo.defaultGroupId = result.groups[0].id;
} }
groupInfo.groups = groupInfo.groups!.concat(result.groups); groupInfo.groups = groupInfo.groups.concat(result.groups);
} }
return groupInfo; return groupInfo;
@ -458,7 +456,7 @@ export type CoreGroupInfo = {
/** /**
* List of groups. * List of groups.
*/ */
groups?: CoreGroup[]; groups: CoreGroup[];
/** /**
* Whether it's separate groups. * Whether it's separate groups.