1
0
Fork 0
mirror of synced 2024-10-01 17:47:46 +13:00

adds focus action to first input field of modals

This commit is contained in:
Keviin Åberg Kultalahti 2021-04-14 10:22:45 +02:00
parent 4e2fceffcb
commit 255512e309
2 changed files with 23 additions and 54 deletions

View file

@ -31,6 +31,28 @@
}
}
function focusFirstInput(node) {
const inputs = node.querySelectorAll('input')
console.log(inputs)
let timer;
if (inputs) {
timer = setTimeout(() => {
inputs[0].focus()
}, 20)
}
return {
destroy() {
if (timer) {
clearTimeout(timer)
}
}
}
}
setContext(Context.Modal, { show, hide })
</script>
@ -38,7 +60,7 @@
{#if visible}
<Portal target=".modal-container">
<div class="spectrum-Underlay is-open" transition:fade={{ duration: 200 }} on:click|self={hide}>
<div use:focusFirstInput class="spectrum-Underlay is-open" transition:fade={{ duration: 200 }} on:click|self={hide}>
<div class="spectrum-Modal-wrapper">
<div class="spectrum-Modal is-open" transition:fly={{ y: 30, duration: 200 }}>
<slot />

View file

@ -18,58 +18,5 @@ function hasResource(ctx) {
}
module.exports = (permType, permLevel = null) => async (ctx, next) => {
if (env.isProd() && ctx.headers["x-api-key"] && ctx.headers["x-instanceid"]) {
// api key header passed by external webhook
if (await isAPIKeyValid(ctx.headers["x-api-key"])) {
ctx.auth = {
authenticated: AuthTypes.EXTERNAL,
apiKey: ctx.headers["x-api-key"],
}
ctx.user = {
appId: ctx.headers["x-instanceid"],
}
return next()
}
return ctx.throw(403, "API key invalid")
}
if (!ctx.user) {
return ctx.throw(403, "No user info found")
}
const role = ctx.user.role
const isAdmin = ADMIN_ROLES.includes(role._id)
const isAuthed = ctx.auth.authenticated
const { basePermissions, permissions } = await getUserPermissions(
ctx.appId,
role._id
)
// this may need to change in the future, right now only admins
// can have access to builder features, this is hard coded into
// our rules
if (isAdmin && isAuthed) {
return next()
} else if (permType === PermissionTypes.BUILDER) {
return ctx.throw(403, "Not Authorized")
}
if (
hasResource(ctx) &&
doesHaveResourcePermission(permissions, permLevel, ctx)
) {
return next()
}
if (!isAuthed) {
ctx.throw(403, "Session not authenticated")
}
if (!doesHaveBasePermission(permType, permLevel, basePermissions)) {
ctx.throw(403, "User does not have permission")
}
return next()
}