Skip to content
Snippets Groups Projects
Verified Commit abd63033 authored by Gabriel Zachmann's avatar Gabriel Zachmann
Browse files

improve capability handling

parent b342ab14
No related branches found
No related tags found
No related merge requests found
Showing with 117 additions and 51 deletions
...@@ -18,6 +18,14 @@ ...@@ -18,6 +18,14 @@
- Trusted web applications can skip the consent screen - Trusted web applications can skip the consent screen
### Enhancements
- Reworked and improved several parts of the web interface:
- Consent Screen: On default a more compressed view is shown, where sections can be expanded if needed.
- Capabilities:
- Simplified the checking of capabilities
- Read/Write capabilities are now not split but can be toggled
### Dependencies ### Dependencies
- Bump github.com/valyala/fasthttp from 1.37.0 to 1.38.0 - Bump github.com/valyala/fasthttp from 1.37.0 to 1.38.0
......
...@@ -3,11 +3,6 @@ ...@@ -3,11 +3,6 @@
{{> capability-single-part}} {{> capability-single-part}}
{{/ReadWriteCapability}} {{/ReadWriteCapability}}
<ul class="list-group"> <ul class="list-group">
{{#ReadOnlyCapability}}
<li class="list-group-item capability">
{{> capability-single-part}}
</li>
{{/ReadOnlyCapability}}
{{#Children}} {{#Children}}
{{> capabilities-part}} {{> capabilities-part}}
{{/Children}} {{/Children}}
......
...@@ -6,21 +6,29 @@ ...@@ -6,21 +6,29 @@
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<h6> <h6>
{{Name}} {{Name}}
<span class="pl-1" style="font-size: 1rem;"> <span class="pl-1" style="font-size: 1rem;" data-toggle="tooltip" data-placement="top" title=""
{{^IsReadOnly}} data-original-title="">
<i class="fas fa-pencil-alt" data-toggle="tooltip" data-placement="top" title="" {{#ReadOnlyCapability}}
data-original-title="Allows full access."></i> <input id="cp-{{Name}}-mode" class="rw-cap-mode" type="checkbox" checked data-size="sm"
{{/IsReadOnly}} data-toggle="toggle"
{{#IsReadOnly}} data-onstyle="dark" data-offstyle="dark" data-style="round"
<i class="fas fa-book-open" data-toggle="tooltip" data-placement="top" title="" data-on='<i class="fas fa-pencil-alt"></i>'
data-original-title="Allows only read access."></i> data-off='<i class="fas fa-book-open"></i>'>
{{/IsReadOnly}} {{/ReadOnlyCapability}}
</span> </span>
</h6> </h6>
<i class="fas fa-exclamation-circle {{ColorClass}}" data-toggle="tooltip" <i class="fas fa-exclamation-circle {{ColorClass}} rw-cap-write" data-toggle="tooltip"
data-placement="right" title="" data-original-title="{{CapabilityLevel}}"></i> data-placement="right" title="" data-original-title="{{CapabilityLevel}}"></i>
{{#ReadOnlyCapability}}
<i class="fas fa-exclamation-circle {{ColorClass}} rw-cap-read d-none" data-toggle="tooltip"
data-placement="right" title="" data-original-title="{{CapabilityLevel}}"></i>
{{/ReadOnlyCapability}}
</div> </div>
<small>{{Description}}</small> <small class="rw-cap-write">{{Description}}</small>
{{#ReadOnlyCapability}}
<small class="rw-cap-read d-none">{{Description}}</small>
{{/ReadOnlyCapability}}
{{#IsCreateMT}} {{#IsCreateMT}}
<small><br>A created mytoken can have the following <small><br>A created mytoken can have the following
capabilities:</small> capabilities:</small>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<div> <div>
<span id="restr-editor-wrap" class="{{#collapse}} d-none{{/collapse}}"> <span id="restr-editor-wrap" class="{{#collapse}} d-none{{/collapse}}">
<input id="restr-editor-mode" type="checkbox" checked data-size="sm" data-toggle="toggle" <input id="restr-editor-mode" type="checkbox" checked data-size="sm" data-toggle="toggle"
data-style="restr-editor"
data-onstyle="success" data-offstyle="info" data-on="Easy Editor" data-off="JSON Editor"></span> data-onstyle="success" data-offstyle="info" data-on="Easy Editor" data-off="JSON Editor"></span>
{{#collapse}} {{#collapse}}
<button class="btn btn-info my-expand ml-2" type="button" data-toggle="collapse" data-target="#restr-body" <button class="btn btn-info my-expand ml-2" type="button" data-toggle="collapse" data-target="#restr-body"
......
...@@ -3,11 +3,6 @@ ...@@ -3,11 +3,6 @@
{{> sub-capability-single-part}} {{> sub-capability-single-part}}
{{/ReadWriteCapability}} {{/ReadWriteCapability}}
<ul class="list-group"> <ul class="list-group">
{{#ReadOnlyCapability}}
<li class="list-group-item capability">
{{> sub-capability-single-part}}
</li>
{{/ReadOnlyCapability}}
{{#Children}} {{#Children}}
{{> sub-capabilities-part}} {{> sub-capabilities-part}}
{{/Children}} {{/Children}}
......
...@@ -6,20 +6,27 @@ ...@@ -6,20 +6,27 @@
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<h6> <h6>
{{Name}} {{Name}}
<span class="pl-1" style="font-size: 1rem;"> <span class="pl-1" style="font-size: 1rem;" data-toggle="tooltip" data-placement="top" title=""
{{^IsReadOnly}} data-original-title="">
<i class="fas fa-pencil-alt" data-toggle="tooltip" data-placement="top" title="" {{#ReadOnlyCapability}}
data-original-title="Allows full access."></i> <input id="sub-cp-{{Name}}-mode" class="rw-cap-mode" type="checkbox" checked data-size="sm"
{{/IsReadOnly}} data-toggle="toggle"
{{#IsReadOnly}} data-onstyle="light" data-offstyle="light" data-style="round"
<i class="fas fa-book-open" data-toggle="tooltip" data-placement="top" title="" data-on='<i class="fas fa-pencil-alt"></i>'
data-original-title="Allows only read access. Click to allow full access."></i> data-off='<i class="fas fa-book-open"></i>'>
{{/IsReadOnly}} {{/ReadOnlyCapability}}
</span> </span>
</h6> </h6>
<i class="fas fa-exclamation-circle {{ColorClass}}" data-toggle="tooltip" <i class="fas fa-exclamation-circle {{ColorClass}} rw-cap-write" data-toggle="tooltip"
data-placement="right" title="" data-original-title="{{CapabilityLevel}}"></i> data-placement="right" title="" data-original-title="{{CapabilityLevel}}"></i>
{{#ReadOnlyCapability}}
<i class="fas fa-exclamation-circle {{ColorClass}} rw-cap-read d-none" data-toggle="tooltip"
data-placement="right" title="" data-original-title="{{CapabilityLevel}}"></i>
{{/ReadOnlyCapability}}
</div> </div>
<small>{{Description}}</small> <small class="rw-cap-write">{{Description}}</small>
{{#ReadOnlyCapability}}
<small class="rw-cap-read d-none">{{Description}}</small>
{{/ReadOnlyCapability}}
</div> </div>
</div> </div>
...@@ -42,4 +42,12 @@ ul.list-group li.list-group-item { ...@@ -42,4 +42,12 @@ ul.list-group li.list-group-item {
border-top: 1px solid rgba(0, 0, 0, .15); border-top: 1px solid rgba(0, 0, 0, .15);
border-left: 1px solid rgba(0, 0, 0, .15); border-left: 1px solid rgba(0, 0, 0, .15);
border-right: 1px solid rgba(0, 0, 0, .15); border-right: 1px solid rgba(0, 0, 0, .15);
}
.toggle, .toggle-on, .toggle-off {
border-radius: 0.3rem;
}
.toggle.round, .toggle-on.round, .toggle-off.round {
border-radius: 20rem;
} }
\ No newline at end of file
.table-item{ .table-item {
padding: 0.375rem 0.75rem; padding: 0.375rem 0.75rem;
} }
.toggle{
width: 110px!important; .toggle.restr-editor, .toggle-on.restr-editor, .toggle-off.restr-editor {
width: 110px !important;
} }
.btn-add-list-item{
.btn-add-list-item {
padding: 0; padding: 0;
} }
.btn-delete-list-item{
.btn-delete-list-item {
padding: 0; padding: 0;
} }
...@@ -9,6 +9,9 @@ const $capSummarySettings = $('#cap-summary-settings'); ...@@ -9,6 +9,9 @@ const $capSummarySettings = $('#cap-summary-settings');
const $capSummaryHowManyGreen = $('#cap-summary-count-green'); const $capSummaryHowManyGreen = $('#cap-summary-count-green');
const $capSummaryHowManyYellow = $('#cap-summary-count-yellow'); const $capSummaryHowManyYellow = $('#cap-summary-count-yellow');
const $capSummaryHowManyRed = $('#cap-summary-count-red'); const $capSummaryHowManyRed = $('#cap-summary-count-red');
const $capRWModes = $('.rw-cap-mode');
const rPrefix = "read@";
$capabilityChecks.click(function () { $capabilityChecks.click(function () {
checkThisCapability.call(this); checkThisCapability.call(this);
...@@ -51,22 +54,28 @@ $(document).ready(function () { ...@@ -51,22 +54,28 @@ $(document).ready(function () {
$('#subtokenCapabilities').hideB(); $('#subtokenCapabilities').hideB();
} }
updateCapSummary(); updateCapSummary();
$capRWModes.trigger('update-change');
}) })
function getCheckedCapabilities() { function getCheckedCapabilities() {
return _getCheckedCapabilities($capabilityChecks); return _getCheckedCapabilities($capabilityChecks, 'cp');
} }
function getCheckedSubtokenCapabilities() { function getCheckedSubtokenCapabilities() {
if (!$capabilityCreateMytoken.prop("checked")) { if (!$capabilityCreateMytoken.prop("checked")) {
return []; return [];
} }
return _getCheckedCapabilities($subtokenCapabilityChecks); return _getCheckedCapabilities($subtokenCapabilityChecks, 'sub-cp');
} }
function _getCheckedCapabilities($checks) { function _getCheckedCapabilities($checks, idPrefix) {
let caps = $checks.filter(':checked').map(function (_, el) { let caps = $checks.filter(':checked').map(function (_, el) {
return $(el).val(); let v = $(el).val();
let $rw = $('#' + escapeSelector(idPrefix + '-' + rPrefix + v + '-mode'));
if ($rw.length && !$rw.prop('checked')) {
v = rPrefix + v;
}
return v;
}).get(); }).get();
caps = caps.filter(filterCaps); caps = caps.filter(filterCaps);
return caps; return caps;
...@@ -86,7 +95,6 @@ function filterCaps(c, i, caps) { ...@@ -86,7 +95,6 @@ function filterCaps(c, i, caps) {
} }
function isChildCapability(a, b) { function isChildCapability(a, b) {
const rPrefix = "read@";
let aReadOnly = a.startsWith(rPrefix); let aReadOnly = a.startsWith(rPrefix);
let bReadOnly = b.startsWith(rPrefix); let bReadOnly = b.startsWith(rPrefix);
if (aReadOnly) { if (aReadOnly) {
...@@ -149,7 +157,7 @@ function updateCapSummary() { ...@@ -149,7 +157,7 @@ function updateCapSummary() {
continue; continue;
} }
let name = $(c).val(); let name = $(c).val();
let $icon = $($(c).closest('li.list-group-item').find('i.fa-exclamation-circle')[0]); let $icon = $($(c).closest('li.list-group-item').find('i.fa-exclamation-circle').not('.d-none')[0]);
if ($icon.hasClass('text-success')) { if ($icon.hasClass('text-success')) {
counter['green'][name] = 1; counter['green'][name] = 1;
} }
...@@ -199,4 +207,31 @@ function updateCapSummary() { ...@@ -199,4 +207,31 @@ function updateCapSummary() {
} else { } else {
$capSummarySettings.attr('data-original-title', "This mytoken cannot be used to change settings."); $capSummarySettings.attr('data-original-title', "This mytoken cannot be used to change settings.");
} }
} }
\ No newline at end of file
$capRWModes.on('update-change', function () {
let write = $(this).prop('checked');
if (write) {
$(this).closest('span').attr('data-original-title', `Allows full access. Click to only allow read access.`);
$(this).closest('div.flex-fill').find('.rw-cap-read').hideB();
$(this).closest('div.flex-fill').find('.rw-cap-write').showB();
} else {
$(this).closest('span').attr('data-original-title', `Allows only read access. Click to allow full access.`);
$(this).closest('div.flex-fill').find('.rw-cap-write').hideB();
$(this).closest('div.flex-fill').find('.rw-cap-read').showB();
}
});
$capRWModes.change(function () {
let write = $(this).prop('checked');
$(this).trigger('update-change');
let $modes = $(this).closest('li.list-group-item').find('.rw-cap-mode');
$modes.bootstrapToggle(write ? 'on' : 'off', true);
$modes.trigger('update-change');
if (!write) {
let $p = $(this).parents('li.list-group-item').children('div').find('.rw-cap-mode');
$p.bootstrapToggle('off', true);
$p.trigger('update-change');
}
updateCapSummary();
});
\ No newline at end of file
...@@ -10,10 +10,20 @@ $(function (){ ...@@ -10,10 +10,20 @@ $(function (){
} }
updateRotationIcon(); updateRotationIcon();
checkedCapabilities.forEach(function (value) { checkedCapabilities.forEach(function (value) {
$('#cp-' + escapeSelector(value)).prop("checked", true) let rCap = value.startsWith(rPrefix);
if (rCap) {
value = value.substring(rPrefix.length);
}
$('#cp-' + escapeSelector(value)).prop("checked", true);
$('#cp-' + escapeSelector(rPrefix + value) + '-mode').bootstrapToggle(rCap ? 'off' : 'on');
}) })
checkedSubtokenCapabilities.forEach(function (value) { checkedSubtokenCapabilities.forEach(function (value) {
$('#sub-cp-' + escapeSelector(value)).prop("checked", true) let rCap = value.startsWith(rPrefix);
if (rCap) {
value = value.substring(rPrefix.length);
}
$('#sub-cp-' + escapeSelector(value)).prop("checked", true);
$('#sub-cp-' + escapeSelector(rPrefix + value) + '-mode').bootstrapToggle(rCap ? 'off' : 'on');
}) })
chainFunctions( chainFunctions(
discovery, discovery,
......
...@@ -182,26 +182,22 @@ function polling(code, interval) { ...@@ -182,26 +182,22 @@ function polling(code, interval) {
return; return;
case "access_denied": case "access_denied":
message = "You denied the authorization request."; message = "You denied the authorization request.";
window.clearInterval(intervalID);
break; break;
case "expired_token": case "expired_token":
message = "Code expired. You might want to restart the flow."; message = "Code expired. You might want to restart the flow.";
window.clearInterval(intervalID);
break; break;
case "invalid_grant": case "invalid_grant":
case "invalid_token": case "invalid_token":
message = "Code already used."; message = "Code already used.";
window.clearInterval(intervalID);
break; break;
case "undefined": case "undefined":
message = "No response from server"; message = "No response from server";
window.clearInterval(intervalID);
break; break;
default: default:
message = getErrorMessage(errRes); message = getErrorMessage(errRes);
window.clearInterval(intervalID);
break; break;
} }
window.clearInterval(intervalID);
mtShowError(message) mtShowError(message)
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment