Settings resource; oauth2 app authorization model; UI cleanup

This commit is contained in:
garrettmills
2020-05-17 21:13:38 -05:00
parent d558f21375
commit 2b2e7d2ebe
19 changed files with 393 additions and 2 deletions

View File

@@ -0,0 +1,17 @@
import { Component } from '../lib/vues6/vues6.js'
import { action_service } from './service/Action.service.js';
const template = `
<div></div>
`
export default class InvokeActionComponent extends Component {
static get selector() { return 'coreid-invoke-action' }
static get template() { return template }
static get props() { return ['action'] }
async vue_on_create() {
console.log('IAC', this)
await action_service.perform(this.action)
}
}

View File

@@ -4,6 +4,7 @@ import MFASetupPage from './auth/MFASetup.component.js'
import MFAChallengePage from './auth/MFAChallenge.component.js'
import MFADisableComponent from './auth/MFADisable.component.js'
import PasswordResetComponent from './auth/PasswordReset.component.js'
import InvokeActionComponent from './InvokeAction.component.js'
const components = {
AuthLoginForm,
@@ -12,6 +13,7 @@ const components = {
MFAChallengePage,
MFADisableComponent,
PasswordResetComponent,
InvokeActionComponent,
}
export { components }

View File

@@ -64,6 +64,7 @@ export default class NavBarComponent extends Component {
async vue_on_create() {
this.can.api_tokens = await session.check_permissions('v1:reflect:tokens:list')
this.$forceUpdate()
}
toggle_sidebar() {

View File

@@ -77,8 +77,9 @@ export default class SideBarComponent extends Component {
},
{
text: 'Settings',
action: 'redirect',
next: '/dash/settings',
action: 'list',
type: 'resource',
resource: 'Setting',
},
]

View File

@@ -0,0 +1,52 @@
import CRUDBase from './CRUDBase.js'
class SettingResource extends CRUDBase {
endpoint = '/api/v1/settings'
required_fields = ['key', 'value']
permission_base = 'v1:settings'
item = 'Setting'
plural = 'Settings'
listing_definition = {
columns: [
{
name: 'Setting Key',
field: 'key',
},
{
name: 'Value',
field: 'value',
renderer: (v) => JSON.stringify(v),
},
],
actions: [
{
type: 'resource',
position: 'row',
action: 'update',
icon: 'fa fa-edit',
color: 'primary',
},
],
}
form_definition = {
fields: [
{
name: 'Setting Key',
field: 'key',
type: 'text',
readonly: true,
},
{
name: 'Value (JSON)',
field: 'value',
type: 'json',
},
],
}
}
const setting = new SettingResource()
export { setting }

View File

@@ -23,6 +23,26 @@ class ActionService {
} else if ( action === 'list' ) {
return location_service.redirect(`/dash/c/listing/${resource}`, 0)
}
} else if ( action === 'post' ) {
const inputs = []
if ( args.params ) {
for (const param in args.params) {
if ( !args.params.hasOwnProperty(param) ) continue
inputs.push(`<input type="hidden" name="${param}" value="${args.params[param]}"/>`)
}
}
const form_attrs = ['method="POST"']
if ( args.destination ) {
form_attrs.push(`action="${args.destination}"`)
}
$(`
<form ${form_attrs.join(' ')}>
${inputs.join('\n')}
</form>
`).appendTo('body').submit()
} else {
throw new TypeError(`Unknown action type: ${action}`)
}