Skip to content

Commit

Permalink
feat: allow readonly view without logging in (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
satterly authored Apr 23, 2021
1 parent 86b6822 commit 8975410
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
>
<div v-if="!isKiosk">
<v-navigation-drawer
v-if="isLoggedIn || !isAuthRequired"
v-if="isLoggedIn || !isAuthRequired || isAllowReadonly"
v-model="drawer"
:clipped="$vuetify.breakpoint.lgAndUp"
disable-resize-watcher
Expand Down Expand Up @@ -180,7 +180,7 @@

<v-tooltip bottom>
<v-btn
v-show="isLoggedIn || !isAuthRequired"
v-show="isLoggedIn || !isAuthRequired || isAllowReadonly"
slot="activator"
icon
@click="toggleFullScreen"
Expand All @@ -192,7 +192,7 @@

<v-tooltip bottom>
<v-btn
v-show="isLoggedIn || !isAuthRequired"
v-show="isLoggedIn || !isAuthRequired || isAllowReadonly"
slot="activator"
icon
>
Expand Down Expand Up @@ -386,7 +386,7 @@

<v-tooltip bottom>
<v-btn
v-show="isLoggedIn || !isAuthRequired"
v-show="isLoggedIn || !isAuthRequired || isAllowReadonly"
slot="activator"
icon
@click="toggleFullScreen"
Expand All @@ -398,7 +398,7 @@

<v-tooltip bottom>
<v-btn
v-show="isLoggedIn || !isAuthRequired"
v-show="isLoggedIn || !isAuthRequired || isAllowReadonly"
slot="activator"
icon
>
Expand Down Expand Up @@ -589,7 +589,7 @@ export default {
text: i18n.t('APIKeys'),
path: '/keys',
perms: 'read:keys',
show: true
show: this.isLoggedIn || !this.isAuthRequired
},
{
icon: 'assessment',
Expand Down Expand Up @@ -649,6 +649,9 @@ export default {
isAuthRequired() {
return this.$config.auth_required
},
isAllowReadonly() {
return this.$config.allow_readonly
},
isSignupEnabled() {
return this.$config.signup_enabled
},
Expand Down
7 changes: 6 additions & 1 deletion src/directives/hasPerms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import { store } from '@/main'

export default Vue.directive('has-perms', function(el, binding) {
let authRequired = store.getters.getConfig('auth_required')
let allowReadonly = store.getters.getConfig('allow_readonly')
let readonlyScopes = store.getters.getConfig('readonly_scopes')
let authenticated = store.state.auth.isAuthenticated

if (!authRequired) {
return true
}
if (allowReadonly) {
authenticated = true
}
if (!authenticated) {
return false
}
Expand All @@ -29,7 +34,7 @@ export default Vue.directive('has-perms', function(el, binding) {
}

let perm = binding.value
let scopes = store.getters['auth/scopes']
let scopes = allowReadonly ? readonlyScopes : store.getters['auth/scopes']
let action = binding.modifiers.disable ? 'disable' : 'hide'

if (!perm) {
Expand Down
3 changes: 2 additions & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ export function createRouter(basePath): VueRouter {
router.beforeEach((to, from, next) => {
if ((store.getters.getConfig('auth_required') &&
to.matched.some(record => record.meta.requiresAuth))) {
if (!store.getters['auth/isLoggedIn']) {
if (!store.getters['auth/isLoggedIn'] &&
!store.getters.getConfig('allow_readonly')) {
next({
path: '/login',
query: { redirect: to.fullPath }
Expand Down
2 changes: 2 additions & 0 deletions src/store/modules/config.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const state = {
alarm_model: {}, // includes severity, colors and status maps

auth_required: true,
allow_readonly: false,
readonly_scopes: ['read'],
provider: 'basic',
customer_views: false,
signup_enabled: true,
Expand Down

0 comments on commit 8975410

Please sign in to comment.