Skip to content

Commit 61bdea1

Browse files
committed
Merge pull request #335 from jleyva/MOBILE-1362
MOBILE-1362 participants: Check if the Participants option must be di…
2 parents fa3065e + e580f0a commit 61bdea1

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

www/addons/participants/services/courses_nav_handler.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff 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
/**

www/addons/participants/services/participants.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)