File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
www/addons/participants/services Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ angular.module('mm.addons.participants')
2121 * @ngdoc service
2222 * @name $mmaParticipantsCoursesNavHandler
2323 */
24- . factory ( '$mmaParticipantsCoursesNavHandler' , function ( mmCoursesAccessMethods ) {
24+ . factory ( '$mmaParticipantsCoursesNavHandler' , function ( $mmaParticipants , mmCoursesAccessMethods ) {
2525 return {
2626
2727 /**
@@ -38,13 +38,14 @@ angular.module('mm.addons.participants')
3838 *
3939 * @param {Number } courseId Course ID.
4040 * @param {Object } accessData Type of access to the course: default, guest, ...
41- * @return {Boolean } True if handler is enabled, false otherwise.
41+ * @return {Boolean|Promise } Promise resolved with true if handler is enabled,
42+ * false or promise rejected or resolved with false otherwise.
4243 */
4344 isEnabledForCourse : function ( courseId , accessData ) {
4445 if ( accessData && accessData . type == mmCoursesAccessMethods . guest ) {
4546 return false ; // Not enabled for guests.
4647 }
47- return true ;
48+ return $mmaParticipants . isPluginEnabledForCourse ( courseId ) ;
4849 } ,
4950
5051 /**
Original file line number Diff line number Diff line change @@ -117,5 +117,27 @@ angular.module('mm.addons.participants')
117117 return $mmSite . invalidateWsCacheForKey ( getParticipantsListCacheKey ( courseid ) ) ;
118118 } ;
119119
120+ /**
121+ * Returns whether or not the participants addon is enabled for a certain course.
122+ *
123+ * @module mm.addons.participants
124+ * @ngdoc method
125+ * @name $mmaParticipants#isPluginEnabledForCourse
126+ * @param {Number } courseId Course ID.
127+ * @return {Promise } Promise resolved with true if plugin is enabled, rejected or resolved with false otherwise.
128+ */
129+ self . isPluginEnabledForCourse = function ( courseId ) {
130+ if ( ! courseId ) {
131+ return $q . reject ( ) ;
132+ }
133+
134+ // Retrieving one participant will fail if browsing users is disabled by capabilities.
135+ return self . getParticipants ( courseId , 0 , 1 ) . then ( function ( parcitipants ) {
136+ return true ;
137+ } ) . catch ( function ( error ) {
138+ return false ;
139+ } ) ;
140+ } ;
141+
120142 return self ;
121143} ) ;
You can’t perform that action at this time.
0 commit comments