Merge pull request #3223 from dpalou/MOBILE-3833

MOBILE-3833 data: Fix wrong group list in some cases
main
Pau Ferrer Ocaña 2022-04-01 14:40:54 +02:00 committed by GitHub
commit 97f5e053cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 9 deletions

View File

@ -171,31 +171,34 @@ export class AddonModDataEditPage implements OnInit {
// Check permissions when adding a new entry or offline entry. // Check permissions when adding a new entry or offline entry.
if (!this.isEditing) { if (!this.isEditing) {
let haveAccess = false; let haveAccess = false;
let groupInfo: CoreGroupInfo | undefined = this.groupInfo;
if (refresh) { if (refresh) {
this.groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule);
if (this.groupInfo.visibleGroups && this.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.
this.groupInfo.groups = this.groupInfo.groups.filter(group => group.id !== 0); groupInfo.groups = groupInfo.groups.filter(group => group.id !== 0);
this.groupInfo.defaultGroupId = this.groupInfo.groups[0].id; groupInfo.defaultGroupId = groupInfo.groups[0].id;
} }
this.selectedGroup = CoreGroups.validateGroupId(this.selectedGroup, this.groupInfo); this.selectedGroup = CoreGroups.validateGroupId(this.selectedGroup, groupInfo);
this.initialSelectedGroup = this.selectedGroup; this.initialSelectedGroup = this.selectedGroup;
} }
if (this.groupInfo?.groups && this.groupInfo.groups.length > 0) { if (groupInfo?.groups && groupInfo?.groups.length > 0) {
if (refresh) { if (refresh) {
const canAddGroup: Record<number, boolean> = {}; const canAddGroup: Record<number, boolean> = {};
await Promise.all(this.groupInfo.groups.map(async (group) => { await Promise.all(groupInfo.groups.map(async (group) => {
const accessData = await AddonModData.getDatabaseAccessInformation(this.database!.id, { const accessData = await AddonModData.getDatabaseAccessInformation(this.database!.id, {
cmId: this.moduleId, groupId: group.id }); cmId: this.moduleId,
groupId: group.id,
});
canAddGroup[group.id] = accessData.canaddentry; canAddGroup[group.id] = accessData.canaddentry;
})); }));
this.groupInfo.groups = this.groupInfo.groups.filter((group) => !!canAddGroup[group.id]); groupInfo.groups = groupInfo.groups.filter((group) => !!canAddGroup[group.id]);
haveAccess = canAddGroup[this.selectedGroup]; haveAccess = canAddGroup[this.selectedGroup];
} else { } else {
@ -207,6 +210,8 @@ export class AddonModDataEditPage implements OnInit {
haveAccess = accessData.canaddentry; haveAccess = accessData.canaddentry;
} }
this.groupInfo = groupInfo;
if (!haveAccess) { if (!haveAccess) {
// You shall not pass, go back. // You shall not pass, go back.
CoreDomUtils.showErrorModal('addon.mod_data.noaccess', true); CoreDomUtils.showErrorModal('addon.mod_data.noaccess', true);