Skip to content

Commit 57d1f74

Browse files
committed
MOBILE-1600 quiz: Check prevent newattempt reasons in prefetch
1 parent ee80a1f commit 57d1f74

File tree

1 file changed

+10
-1
lines changed
  • www/addons/mod/quiz/services

1 file changed

+10
-1
lines changed

www/addons/mod/quiz/services/quiz.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,7 @@ angular.module('mm.addons.mod_quiz')
20742074
startAttempt,
20752075
quiz,
20762076
quizAccessInfo,
2077+
attemptAccessInfo,
20772078
preflightData = {},
20782079
scope,
20792080
prefetchPromise,
@@ -2095,19 +2096,27 @@ angular.module('mm.addons.mod_quiz')
20952096
}).then(function() {
20962097
var promises = [];
20972098

2098-
// Get user attempts and data not related with attempts.
2099+
// Get some quiz data.
20992100
promises.push(self.getQuizAccessInformation(quiz.id, false, true, siteId).then(function(info) {
21002101
quizAccessInfo = info;
21012102
}));
21022103
promises.push(self.getQuizRequiredQtypes(quiz.id, true, siteId));
21032104
promises.push(self.getUserAttempts(quiz.id, 'all', true, false, true, siteId).then(function(atts) {
21042105
attempts = atts;
21052106
}));
2107+
promises.push(self.getAttemptAccessInformation(quiz.id, 0, false, true, siteId).then(function(info) {
2108+
attemptAccessInfo = info;
2109+
}));
21062110

21072111
return $q.all(promises);
21082112
}).then(function() {
21092113
var attempt = attempts[attempts.length - 1];
21102114
if (!attempt || self.isAttemptFinished(attempt.state)) {
2115+
// Check if the user can attempt the quiz.
2116+
if (attemptAccessInfo.preventnewattemptreasons.length) {
2117+
return $q.reject($mmText.buildMessage(attemptAccessInfo.preventnewattemptreasons));
2118+
}
2119+
21112120
startAttempt = true;
21122121
attempt = undefined;
21132122
}

0 commit comments

Comments
 (0)