Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions www/addons/participants/services/courses_nav_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module('mm.addons.participants')
* @ngdoc service
* @name $mmaParticipantsCoursesNavHandler
*/
.factory('$mmaParticipantsCoursesNavHandler', function(mmCoursesAccessMethods) {
.factory('$mmaParticipantsCoursesNavHandler', function($mmaParticipants, mmCoursesAccessMethods) {
return {

/**
Expand All @@ -38,13 +38,14 @@ angular.module('mm.addons.participants')
*
* @param {Number} courseId Course ID.
* @param {Object} accessData Type of access to the course: default, guest, ...
* @return {Boolean} True if handler is enabled, false otherwise.
* @return {Boolean|Promise} Promise resolved with true if handler is enabled,
* false or promise rejected or resolved with false otherwise.
*/
isEnabledForCourse: function(courseId, accessData) {
if (accessData && accessData.type == mmCoursesAccessMethods.guest) {
return false; // Not enabled for guests.
}
return true;
return $mmaParticipants.isPluginEnabledForCourse(courseId);
},

/**
Expand Down
22 changes: 22 additions & 0 deletions www/addons/participants/services/participants.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,27 @@ angular.module('mm.addons.participants')
return $mmSite.invalidateWsCacheForKey(getParticipantsListCacheKey(courseid));
};

/**
* Returns whether or not the participants addon is enabled for a certain course.
*
* @module mm.addons.participants
* @ngdoc method
* @name $mmaParticipants#isPluginEnabledForCourse
* @param {Number} courseId Course ID.
* @return {Promise} Promise resolved with true if plugin is enabled, rejected or resolved with false otherwise.
*/
self.isPluginEnabledForCourse = function(courseId) {
if (!courseId) {
return $q.reject();
}

// Retrieving one participant will fail if browsing users is disabled by capabilities.
return self.getParticipants(courseId, 0, 1).then(function(parcitipants) {
return true;
}).catch(function(error) {
return false;
});
};

return self;
});