Skip to content

Commit 4a2d4bf

Browse files
committed
chore(passport): dynamic settings for vue
1 parent 6745830 commit 4a2d4bf

6 files changed

Lines changed: 42 additions & 15 deletions

File tree

rootfs/api/settings/production.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,16 @@
177177
REST_FRAMEWORK = {
178178
'DATETIME_FORMAT': DRYCC_DATETIME_FORMAT,
179179
'DEFAULT_MODEL_SERIALIZER_CLASS': 'rest_framework.serializers.ModelSerializer',
180-
'DEFAULT_PERMISSION_CLASSES': (
180+
'DEFAULT_PERMISSION_CLASSES': [
181181
'rest_framework.permissions.IsAuthenticated',
182-
),
183-
'DEFAULT_RENDERER_CLASSES': (
182+
],
183+
'DEFAULT_AUTHENTICATION_CLASSES': [
184+
'rest_framework.authentication.SessionAuthentication',
185+
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
186+
],
187+
'DEFAULT_RENDERER_CLASSES': [
184188
'rest_framework.renderers.JSONRenderer',
185-
),
189+
],
186190
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
187191
'PAGE_SIZE': 30,
188192
'TEST_REQUEST_DEFAULT_FORMAT': 'json',
@@ -305,12 +309,6 @@
305309
"DEFAULT_SCOPES": ['openid', ],
306310
"DEFAULT_CODE_CHALLENGE_METHOD": 'S256',
307311
}
308-
REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'] = (
309-
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
310-
'rest_framework.authentication.SessionAuthentication',
311-
'rest_framework.authentication.BasicAuthentication',
312-
)
313-
314312
# Redis Configuration
315313
DRYCC_REDIS_ADDRS = os.environ.get('DRYCC_REDIS_ADDRS', '127.0.0.1:6379').split(",")
316314
DRYCC_REDIS_PASSWORD = os.environ.get('DRYCC_REDIS_PASSWORD', '')

rootfs/passport/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from django.contrib import admin
2020
from django.views.generic.base import TemplateView
2121
from api.views import LivenessCheckView, ReadinessCheckView
22+
from . import views
2223

2324
if settings.ADMIN_ENABLED:
2425
urlpatterns = [path('admin/', admin.site.urls)]
@@ -28,6 +29,7 @@
2829
urlpatterns += [
2930
url(r'^healthz$', LivenessCheckView.as_view()),
3031
url(r'^readiness$', ReadinessCheckView.as_view()),
32+
re_path(r"settings/?$", views.SettingsViewSet.as_view({'get': 'retrieve'})),
3133
re_path(r"^user/", include('api.urls')),
3234
re_path(r'^oauth/', include('oauth2_provider.urls', namespace='oauth2_provider')),
3335
re_path(r'^accounts/', include('django.contrib.auth.urls')),

rootfs/passport/views.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from django.conf import settings
2+
from rest_framework.viewsets import GenericViewSet
3+
from rest_framework.permissions import AllowAny
4+
from rest_framework.response import Response
5+
6+
7+
class SettingsViewSet(GenericViewSet):
8+
9+
permission_classes = (AllowAny, )
10+
11+
def retrieve(self, request, *args, **kwargs):
12+
return Response(data={
13+
"legal": settings.LEGAL_ENABLED,
14+
"registration_enabled": settings.REGISTRATION_ENABLED,
15+
})

rootfs/web/src/components/MainFooter.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {toRefs, reactive} from 'vue'
1+
import {toRefs, reactive, onMounted} from 'vue'
2+
3+
import { getSettings } from '../services/settings'
24

35
export default {
46
name: "Footer",
@@ -7,7 +9,10 @@ export default {
79
year: new Date().getFullYear(),
810
legalEnabled: false,
911
})
10-
state.legalEnabled = process.env.VUE_APP_LEGAL_ENABLED == "true" ? true : false;
12+
onMounted(async () => {
13+
var res = await getSettings()
14+
state.legalEnabled = res.data.legal
15+
})
1116
return {
1217
...toRefs(state),
1318
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import axios from "../utils/axios";
2+
3+
export function getSettings() {
4+
return axios.get(`/settings/`)
5+
}

rootfs/web/vite.config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { defineConfig } from 'vite'
22
import vue from '@vitejs/plugin-vue'
33

44
VUE_APP_BASE_URL = process.env.VUE_APP_BASE_URL ? process.env.VUE_APP_BASE_URL : ''
5-
VUE_APP_LEGAL_ENABLED = process.env.VUE_APP_LEGAL_ENABLED ? process.env.VUE_APP_LEGAL_ENABLED : "false"
65

76
// https://vitejs.dev/config/
87
export default defineConfig({
@@ -24,13 +23,16 @@ export default defineConfig({
2423
'/assets': {
2524
target: VUE_APP_BASE_URL,
2625
changeOrigin: true,
27-
}
26+
},
27+
'/settings': {
28+
target: VUE_APP_BASE_URL,
29+
changeOrigin: true,
30+
},
2831
},
2932
},
3033
define: {
3134
'process.env': {
3235
VUE_APP_BASE_URL: VUE_APP_BASE_URL,
33-
VUE_APP_LEGAL_ENABLED: VUE_APP_LEGAL_ENABLED,
3436
},
3537
}
3638
})

0 commit comments

Comments
 (0)