MDL-82349 course: fix guest access to course

This commit is contained in:
ferranrecio 2024-10-08 20:09:31 +02:00 committed by ferran
parent cccacbdc04
commit 0d04567882
3 changed files with 14 additions and 3 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -13,6 +13,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
import Config from 'core/config';
import {getString} from 'core/str';
import {Reactive} from 'core/reactive';
import notification from 'core/notification';
@ -218,6 +219,16 @@ export default class extends Reactive {
* @returns {Object} the current course state
*/
async getServerCourseState() {
// Only logged users can get the course state. Filtering here will prevent unnecessary
// calls to the server and login page redirects. Especially for home activities with
// guest access.
if (Config.userId == 0) {
return {
course: {},
section: [],
cm: [],
};
}
const courseState = await ajax.call([{
methodname: 'core_courseformat_get_state',
args: {