@@ -59,8 +59,8 @@ angular.module('mm.addons.mod_forum')
5959 // We need to check which of the returned groups the user can post to.
6060 promise = validateVisibleGroups ( forumgroups , refresh ) ;
6161 } else {
62- // WS already filters groups, no need to do it ourselves.
63- promise = $q . when ( forumgroups ) ;
62+ // WS already filters groups, no need to do it ourselves. Add "All participants" if needed.
63+ promise = addAllParticipantsOption ( forumgroups , true ) ;
6464 }
6565
6666 return promise . then ( function ( forumgroups ) {
@@ -135,8 +135,8 @@ angular.module('mm.addons.mod_forum')
135135 return false ;
136136 } ) . then ( function ( canAdd ) {
137137 if ( canAdd ) {
138- // The user can post to all groups, return them all.
139- return forumgroups ;
138+ // The user can post to all groups, add the "All participants" option and return them all.
139+ return addAllParticipantsOption ( forumgroups ) ;
140140 } else {
141141 // The user can't post to all groups, let's check which groups he can post to.
142142 var promises = [ ] ,
@@ -189,6 +189,34 @@ angular.module('mm.addons.mod_forum')
189189 return filtered ;
190190 }
191191
192+ // Add the "All participants" option to a list of groups if the user can add a discussion to all participants.
193+ function addAllParticipantsOption ( groups , check ) {
194+ var promise ;
195+
196+ if ( check ) {
197+ // We need to check if the user can add a discussion to all participants.
198+ promise = $mmaModForum . canAddDiscussionToAll ( forumId ) . catch ( function ( ) {
199+ // The call failed, let's assume he can't.
200+ return false ;
201+ } ) ;
202+ } else {
203+ // No need to check, assume the user can.
204+ promise = $q . when ( true ) ;
205+ }
206+
207+ return promise . then ( function ( canAdd ) {
208+ if ( canAdd ) {
209+ groups . unshift ( {
210+ courseid : courseId ,
211+ id : - 1 ,
212+ name : $translate . instant ( 'mm.core.allparticipants' )
213+ } ) ;
214+ }
215+
216+ return groups ;
217+ } ) ;
218+ }
219+
192220 fetchDiscussionData ( ) . finally ( function ( ) {
193221 $scope . groupsLoaded = true ;
194222 } ) ;
0 commit comments