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

make capabilities disableable on consent screen

parent 812c5ce1
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ func CheckTransferCode(tx *sqlx.Tx, pollingCode string) (TransferCodeStatus, err
pt := createProxyToken(pollingCode)
var p TransferCodeStatus
err := db.RunWithinTransaction(tx, func(tx *sqlx.Tx) error {
if err := tx.Get(&p, `SELECT 1 as found, CURRENT_TIMESTAMP() > expires_at AS expired, response_type, redirect FROM TransferCodes WHERE id=?`, pt.ID()); err != nil {
if err := tx.Get(&p, `SELECT 1 as found, CURRENT_TIMESTAMP() > expires_at AS expired, response_type FROM TransferCodes WHERE id=?`, pt.ID()); err != nil {
if errors.Is(err, sql.ErrNoRows) {
err = nil // polling code was not found, but this is fine
return err // p.Found is false
......
......@@ -63,7 +63,7 @@ func (tc TransferCode) Store(tx *sqlx.Tx) error {
if err := tc.proxyToken.Store(tx); err != nil {
return err
}
_, err := tx.Exec(`INSERT INTO TransferCodesAttributes (id, expires_in, revoke_ST, response_type) VALUES(?,?,?,?,?)`, tc.id, config.Get().Features.Polling.PollingCodeExpiresAfter, tc.Attributes.NewST, tc.Attributes.ResponseType)
_, err := tx.Exec(`INSERT INTO TransferCodesAttributes (id, expires_in, revoke_ST, response_type) VALUES(?,?,?,?)`, tc.id, config.Get().Features.Polling.PollingCodeExpiresAfter, tc.Attributes.NewST, tc.Attributes.ResponseType)
return err
})
}
......
......@@ -28,6 +28,9 @@ func handleConsent(ctx *fiber.Ctx, r restrictions.Restrictions, c capabilities.C
"capabilities": pkg.WebCapabilities(c),
}
if c.Has(capabilities.CapabilityCreateST) {
if len(sc) == 0 {
sc = c
}
binding["subtoken-capabilities"] = pkg.WebCapabilities(sc)
}
return ctx.Render("sites/consent", binding, "layouts/main")
......
......@@ -8,15 +8,16 @@
<h4 class="text-center">Capabilities</h4>
<table class="table table-hover table-bordered col-md table-secondary">
<tbody>
<script>
let capabilities = [];
let subtoken_capabilities = [];
</script>
{{#capabilities}}
<tr>
<td class="text-center">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input capability-check" value="{{Name}}" checked id="cp-{{Name}}">
<label class="custom-control-label" for="cp-{{Name}}"><span class="sr-only"></span></label>
</div>
</td>
<td>
<div class="d-flex justify-content-between">
<script>capabilities.push("{{Name}}");</script>
<h5>{{Name}}</h5>
<i class="fas fa-exclamation-circle {{ColorClass}}" data-toggle="tooltip" data-placement="right" title="" data-original-title="{{CapabilityLevel}}"></i>
</div>
......@@ -30,14 +31,21 @@
<table class="table table-hover table-grey">
<tbody>
{{#subtoken-capabilities}}
<tr><td>
<tr>
<td class="text-center">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input subtoken-capability-check" value="{{Name}}" checked id="scp-{{Name}}">
<label class="custom-control-label" for="scp-{{Name}}"><span class="sr-only"></span></label>
</div>
</td>
<td>
<div class="d-flex justify-content-between">
<script>subtoken_capabilities.push("{{Name}}");</script>
<h5>{{Name}}</h5>
<i class="fas fa-exclamation-circle {{ColorClass}}" data-toggle="tooltip" data-placement="right" title="" data-original-title="{{CapabilityLevel}}"></i>
</div>
<div>{{Description}}</div>
</td></tr>
</td>
</tr>
{{/subtoken-capabilities}}
</tbody>
</table>
......
......@@ -138,10 +138,15 @@ function updateIcons() {
function approve() {
let data = {
"restrictions": restrictions,
"capabilities": capabilities,
"subtoken_capabilities": subtoken_capabilities
"capabilities": $('.capability-check:checked').map(function(_, el) {
return $(el).val();
}).get(),
"subtoken_capabilities": $('.subtoken-capability-check:checked').map(function(_, el) {
return $(el).val();
}).get()
};
data = JSON.stringify(data);
console.log(data);
$.ajax({
type: "POST",
url: window.location.href,
......@@ -161,4 +166,10 @@ function approve() {
function cancel() {
//TODO POST cancel
window.location.href = "/";
}
\ No newline at end of file
}
$('#cp-create_super_token').click(function() {
let enabled = $(this).prop("checked");
$('.subtoken-capability-check').prop("checked", enabled);
$('.subtoken-capability-check').prop("disabled", !enabled);
});
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