Skip to content

Commit 31d2530

Browse files
committed
feat: Add redirect policy
1 parent cc3262d commit 31d2530

3 files changed

Lines changed: 46 additions & 13 deletions

File tree

app/controllers/index.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,31 @@ export default class IndexController extends Controller {
196196
(rule) => !this.isEventSubmitRule(rule, matches.prefixes)
197197
);
198198
matches.rules.push(`
199-
{
200-
?id ex:event ex:Submit.
201-
} => {
202-
ex:HttpPolicy pol:policy [
203-
a fno:Execution ;
204-
fno:executes ex:httpRequest ;
205-
ex:method "${this.model.policyMethod}" ;
206-
ex:url <${this.model.policyURL}> ;
207-
ex:contentType "${this.model.policyContentType}"
208-
] .
209-
} .
199+
{
200+
?id ex:event ex:Submit.
201+
} => {
202+
ex:HttpPolicy pol:policy [
203+
a fno:Execution ;
204+
fno:executes ex:httpRequest ;
205+
ex:method "${this.model.policyMethod}" ;
206+
ex:url <${this.model.policyURL}> ;
207+
ex:contentType "${this.model.policyContentType}"
208+
] .
209+
} .
210210
`);
211+
if (this.model.policyRedirectUrl) {
212+
matches.rules.push(`
213+
{
214+
?id ex:event ex:Submit.
215+
} => {
216+
ex:RedirectPolicy pol:policy [
217+
a fno:Execution ;
218+
fno:executes ex:redirect ;
219+
ex:url <${this.model.policyRedirectUrl}>
220+
] .
221+
} .
222+
`);
223+
}
211224
matches.prefixes = this.addIfNotIncluded(
212225
matches.prefixes,
213226
'ex',
@@ -584,4 +597,9 @@ export default class IndexController extends Controller {
584597
updatePolicyContentType(event) {
585598
this.model.policyContentType = event.target.value?.trim();
586599
}
600+
601+
@action
602+
updatePolicyRedirectUrl(event) {
603+
this.model.policyRedirectUrl = event.target.value?.trim();
604+
}
587605
}

app/routes/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default class IndexRoute extends Route {
2929
@tracked policyURL = '';
3030
@tracked policyMethod = '';
3131
@tracked policyContentType = '';
32+
@tracked policyRedirectUrl = '';
3233

3334
async model({ form }) {
3435
await this.solidAuth.ensureLogin();
@@ -240,8 +241,8 @@ export default class IndexRoute extends Route {
240241
?id pol:policy ?policy .
241242
?policy a fno:Execution .
242243
?policy fno:executes ?executionTarget .
243-
?policy ex:method ?method .
244244
?policy ex:url ?url .
245+
OPTIONAL { ?policy ex:method ?method } .
245246
OPTIONAL { ?policy ex:contentType ?contentType } .
246247
}
247248
`;
@@ -261,8 +262,8 @@ export default class IndexRoute extends Route {
261262
const policies = bindings.map((row) => {
262263
return {
263264
executionTarget: row.get('executionTarget').value,
264-
method: row.get('method').value,
265265
url: row.get('url').value,
266+
method: row.get('method')?.value,
266267
contentType: row.get('contentType')?.value,
267268
};
268269
});
@@ -273,6 +274,8 @@ export default class IndexRoute extends Route {
273274
this.policyURL = policy.url;
274275
this.policyMethod = policy.method;
275276
this.policyContentType = policy.contentType;
277+
} else if (policy.executionTarget === 'http://example.org/redirect') {
278+
this.policyRedirectUrl = policy.url;
276279
}
277280
}
278281
}

app/templates/index.hbs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@
179179

180180
<hr>
181181

182+
<div class="mb-3 row">
183+
<label for="policy-redirect-url-{{this.model.form.uuid}}" id="label-policy-redirect-url-{{this.model.form.uuid}}"
184+
class="col-sm-3 col-form-label">Policy Redirect URL</label>
185+
<div class="col-sm-9">
186+
<input type="text" class="form-control" id="policy-redirect-url-{{this.model.form.uuid}}" placeholder="https://formgenerator.smessie.com"
187+
value={{this.model.policyRedirectUrl}} {{ on "change" this.updatePolicyRedirectUrl }}
188+
aria-describedby="label-policy-redirect-url-{{this.model.form.uuid}}" />
189+
</div>
190+
</div>
191+
192+
<hr>
193+
182194
<SortableObjects @sortableObjectList={{this.fields}} @enableSort={{true}} @useSwap={{false}}
183195
@inPlace={{false}} @sortingScope={{"formFields"}}>
184196
{{#each this.fields as |field|}}

0 commit comments

Comments
 (0)