forked from EVOgeek/Vmeda.Online
		
	MOBILE-3833 data: Fix wrong group list in some cases
This commit is contained in:
		
							parent
							
								
									9917c92e7d
								
							
						
					
					
						commit
						dd60ea6978
					
				| @ -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); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user