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.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",

View File

@ -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();
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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];
}
/**

View File

@ -431,7 +431,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref
): Promise<void> {
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.

View File

@ -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<void> {
protected async createSubwikiList(userGroups: CoreGroup[]): Promise<void> {
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 || '';

View File

@ -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."
}
}

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-item>
<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) {
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.