John Cowen ee0e8bf500
ui: App-ify Lock Sessions (#12482)
This commit moves our in-app LockSessions code into an external 'app', which can theoretically be side-loaded but for now it just makes for good isolation/code hygiene.

Functionally, there is kind of one change here, and that is we only show the 'Lock Session' tab if you have permissions to see them. Currently as our UI authorization endpoint needs to be changed slightly to suit our usecase, you will always have permissions to see Lock Sessions as we hardcode the session:read to true (obvs this is a frontend thing, not a backend thing), so it doesn't really change anything from a user perspective.

Also added very bare docs while I was here.

Small note here, ideally we need to add the each individual tab depending on whether an 'app' is enabled or not instead of just permissions, ideally it would be done totally from The Outside rather than a can based conditional on the inside, just something else to be thinking about for the future.
2022-03-14 16:54:49 +00:00

152 lines
3.7 KiB
Handlebars

<Route
@name={{routeName}}
as |route|>
{{#let
'/'
as |separator|}}
{{#let
(concat (join separator (slice 0 -1 (split route.params.key separator))) separator)
as |parentKey|}}
<DataLoader
@src={{uri '/${partition}/${nspace}/${dc}/kv/${key}'
(hash
partition=route.params.partition
nspace=route.params.nspace
dc=route.params.dc
key=(if (string-ends-with routeName 'create') '' route.params.key)
)
}}
as |loader|>
<BlockSlot @name="error">
<AppError
@error={{loader.error}}
@login={{route.model.app.login.open}}
/>
</BlockSlot>
<BlockSlot @name="loaded">
{{#let
route.params.dc
route.params.partition
route.params.nspace
loader.data
as |dc partition nspace item|}}
<AppView>
<BlockSlot @name="breadcrumbs">
<ol>
<li>
<Action
data-test-back
@href={{href-to 'dc.kv.index'}}
>
Key / Values
</Action>
</li>
{{#if (not-eq parentKey separator)}}
{{#let
(split parentKey separator)
as |parts|}}
{{#each parts as |breadcrumb index|}}
{{#if (gt breadcrumb.length 0)}}
{{! if breadcrumb isn't '' then slice of enough of the parentKey }}
{{! to make the correct href. 'Enough' is the current index plus 1.}}
{{! We push on a '' here so make sure we get a trailing slash/separator }}
<li>
<Action
@href={{href-to 'dc.kv.folder'
(join '/'
(append
(slice 0 (add index 1) parts) ''
)
)
}}
>
{{breadcrumb}}
</Action>
</li>
{{/if}}
{{/each}}
{{/let}}
{{/if}}
</ol>
</BlockSlot>
<BlockSlot @name="header">
<h1 data-test-kv-key={{item.Key}}>
{{#if (and item.Key (not-eq item.Key parentKey))}}
<route.Title @title="Edit Key / Value" @render={{false}} />
{{left-trim item.Key parentKey}}
{{else}}
<route.Title @title="New Key / Value" @render={{true}} />
{{/if}}
</h1>
</BlockSlot>
<BlockSlot @name="content">
{{! if a KV has a session `Session` will always be populated despite any specific session permissions }}
{{#if item.Session}}
<Consul::LockSession::Notifications @type="kv" />
{{/if}}
<Consul::Kv::Form
@item={{item}}
@dc={{route.params.dc}}
@nspace={{route.params.nspace}}
@partition={{route.params.partition}}
@onsubmit={{if (eq parentKey separator) (transition-to 'dc.kv.index') (transition-to 'dc.kv.folder' parentKey)}}
@parent={{parentKey}}
/>
{{! `session` is slightly different to `item.Session` as we only have `session` }}
{{! if you have `session:read perms` whereas you can get the sessions ID from }}
{{! `item.Session` without any session perms }}
{{#if (and item.Session)}}
<DataSource
@src={{uri '/${partition}/${nspace}/${dc}/sessions/for-key/${id}'
(hash
partition=route.params.partition
nspace=route.params.nspace
dc=route.params.dc
id=item.Session
)
}}
@onchange={{action (mut session) value="data"}}
/>
<h2>
<Action
rel="help"
@href={{concat (env 'CONSUL_DOCS_URL') '/internals/sessions.html#session-design'}}
@external={{true}}
>
Lock Session
</Action>
</h2>
{{#if session.ID}}
<Consul::LockSession::Form
@item={{session}}
@ondelete={{loader.invalidate}}
/>
{{/if}}
{{/if}}
</BlockSlot>
</AppView>
{{/let}}
</BlockSlot>
</DataLoader>
{{/let}}
{{/let}}
</Route>