From 91f47c5e0d8f5380eeafd6799771917c17c20427 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Thu, 7 Dec 2023 21:49:56 +0000 Subject: [PATCH] force app moodle create public-root moodle --- orchestra/contrib/webapps/admin.py | 32 ++++++++++++++++++++ orchestra/contrib/webapps/backends/moodle.py | 1 + 2 files changed, 33 insertions(+) diff --git a/orchestra/contrib/webapps/admin.py b/orchestra/contrib/webapps/admin.py index afa9c8ab..8da41282 100644 --- a/orchestra/contrib/webapps/admin.py +++ b/orchestra/contrib/webapps/admin.py @@ -22,10 +22,30 @@ from .models import WebApp, WebAppOption from .options import AppOption from .types import AppType +from django.db.models.signals import post_save +from django.dispatch import receiver + +class WebAppOptionForm(forms.ModelForm): + + class Meta: + model = WebAppOption + fields = '__all__' + + # en las app de moodle el public-root sera siempre moodle + def clean(self): + data = self.cleaned_data + webapp = self.cleaned_data.get("webapp") + if webapp.type == 'moodle-php': + if self.cleaned_data.get("name") == 'public-root': + data['value'] = 'moodle' + data['DELETE'] = False + return data + class WebAppOptionInline(admin.TabularInline): model = WebAppOption extra = 1 + form = WebAppOptionForm OPTIONS_HELP_TEXT = { op.name: force_str(op.help_text) for op in AppOption.get_plugins() @@ -124,4 +144,16 @@ class WebAppAdmin(SelectPluginAdminMixin, AccountAdminMixin, ExtendedModelAdmin) obj.sftpuser = user super(WebAppAdmin, self).save_model(request, obj, form, change) + # fuerza a las app Moodle a crear public-root moodle + def response_add(self, request, obj, post_url_continue=None): + if obj.type == 'moodle-php': + mywebapp = WebApp.objects.get(id=obj.id) + WebAppOption.objects.update_or_create( + webapp=mywebapp, + name='public-root', + defaults={'value':'moodle'} + ) + return super().response_add(request, obj, post_url_continue) + admin.site.register(WebApp, WebAppAdmin) + diff --git a/orchestra/contrib/webapps/backends/moodle.py b/orchestra/contrib/webapps/backends/moodle.py index fa1f4b6b..e879dc09 100644 --- a/orchestra/contrib/webapps/backends/moodle.py +++ b/orchestra/contrib/webapps/backends/moodle.py @@ -43,6 +43,7 @@ class MoodleController(WebAppServiceMixin, ServiceController): # Prevent other backends from writting here touch %(app_path)s/.lock # Weekly caching + mkdir %(cms_cache_dir)s &> /dev/null || true moodle_date=$(date -r $(readlink %(cms_cache_dir)s/moodle) +%%s || echo 0) if [[ $moodle_date -lt $(($(date +%%s)-7*24*60*60)) ]]; then moodle_url=$(wget https://download.moodle.org/releases/latest/ -O - -q \\