From e580f0a169e77b5e332fd9c53e44a54b87ee495e Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 23 Dec 2015 11:09:07 +0100 Subject: [PATCH] MOBILE-1362 participants: Check if the Participants option must be displayed --- .../services/courses_nav_handler.js | 7 +++--- .../participants/services/participants.js | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/www/addons/participants/services/courses_nav_handler.js b/www/addons/participants/services/courses_nav_handler.js index 000dc40ffe2..fdcfadac01f 100644 --- a/www/addons/participants/services/courses_nav_handler.js +++ b/www/addons/participants/services/courses_nav_handler.js @@ -21,7 +21,7 @@ angular.module('mm.addons.participants') * @ngdoc service * @name $mmaParticipantsCoursesNavHandler */ -.factory('$mmaParticipantsCoursesNavHandler', function(mmCoursesAccessMethods) { +.factory('$mmaParticipantsCoursesNavHandler', function($mmaParticipants, mmCoursesAccessMethods) { return { /** @@ -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); }, /** diff --git a/www/addons/participants/services/participants.js b/www/addons/participants/services/participants.js index 030b242d7e6..97dd0ecca0b 100644 --- a/www/addons/participants/services/participants.js +++ b/www/addons/participants/services/participants.js @@ -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; });