Skip to content

Commit

Permalink
Move process documentation and add serveraction docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tjololo committed Jan 3, 2024
1 parent 0cdae55 commit 73e25e8
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 2 deletions.
111 changes: 111 additions & 0 deletions content/app/development/logic/serveraction/_index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
title: Server Action
linktitle: Server Action
description: How to write custom server side actions that can be triggered by a API-client or a generic button
toc: true
---

{{% panel theme="warning" %}}
⚠️ Server actions require version 8.0.0 or newer of app-libs

If you want to define a generic button version 4.0.0 or newer of app-frontend is required.
{{% /panel %}}

## Overview

Server actions is a way to write custom backend code that end users can trigger either by pressing a button or making an api request.

They are almost identical to process actions, the only difference is that they do not automatically change the process state when triggered.

A server action is tied to one or more process tasks and needs explisit autorization rules to grant end users execution rights.

## Create and configure server action

### Configure available server action for a process task

To register what server acitons are available for a process task we need to add it to the tasks config in the process.bpmn file

Example of a process task with a server action called `myServerAction`

```xml
<!-- Beginning of process definition omitted for brevity -->
<bpmn:task id="Task_1" name="Utfylling">
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_2</bpmn:outgoing>
<bpmn:extensionElements>
<altinn:taskExtension>
<altinn:taskType>data</altinn:taskType>
<altinn:actions>
<altinn:action type="serverAction">myServerAction</altinn:action>
</altinn:actions>
</altinn:taskExtension>
</bpmn:extensionElements>
</bpmn:task>
<!-- End of process definition omitted for brevity -->
```

### Add access polic

To allow users to trigger the server action we need to add authorization policies to the policy.xml file.

Example of access policy rule granting users with `DAGL` role access to trigger the server action `myServerAction` when the process is in `Task_1`

```xml
<!-- Beginning of policy.xml definition omitted for brevity -->
<xacml:Rule RuleId="urn:altinn:example:ruleid:2" Effect="Permit">
<xacml:Description>Rule that defines that user with role DAGL can execute myServerAction for
[ORG]/[APP] when it is in Task_1
</xacml:Description>
<xacml:Target>
<xacml:AnyOf>
<xacml:AllOf>
<xacml:Match MatchId="urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case">
<xacml:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">DAGL</xacml:AttributeValue>
<xacml:AttributeDesignator AttributeId="urn:altinn:rolecode"
Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
DataType="http://www.w3.org/2001/XMLSchema#string"
MustBePresent="false"/>
</xacml:Match>
</xacml:AllOf>
</xacml:AnyOf>
<xacml:AnyOf>
<xacml:AllOf>
<xacml:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<xacml:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">[ORG]</xacml:AttributeValue>
<xacml:AttributeDesignator AttributeId="urn:altinn:org"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
DataType="http://www.w3.org/2001/XMLSchema#string"
MustBePresent="false"/>
</xacml:Match>
<xacml:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<xacml:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">[APP]</xacml:AttributeValue>
<xacml:AttributeDesignator AttributeId="urn:altinn:app"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
DataType="http://www.w3.org/2001/XMLSchema#string"
MustBePresent="false"/>
</xacml:Match>
<xacml:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<xacml:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Task_1</xacml:AttributeValue>
<xacml:AttributeDesignator AttributeId="urn:altinn:task"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
DataType="http://www.w3.org/2001/XMLSchema#string"
MustBePresent="false"/>
</xacml:Match>
</xacml:AllOf>
</xacml:AnyOf>
<xacml:AnyOf>
<xacml:AllOf>
<xacml:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<xacml:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">myServerAction</xacml:AttributeValue>
<xacml:AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
DataType="http://www.w3.org/2001/XMLSchema#string"
MustBePresent="false"/>
</xacml:Match>
</xacml:AllOf>
</xacml:AnyOf>
</xacml:Target>
</xacml:Rule>
<!-- End of policy.xml definition omitted for brevity -->
```

8 changes: 8 additions & 0 deletions content/app/development/logic/serveraction/_index.nb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Server Action
linktitle: Server Action
description: Hvordan skrive custom server side handlinger som kan bli exekvert enten av en API-bruker eller via en Generic button
toc: true
---

## Todo add docs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
title: Process handling
description: The Application template supports defining a business process for the digital service.
tags: [altinn-apps, process, bpmn]
weight: 2
weight: 60
aliases:
- /app-template/processhandling
---

The template follows the [BPMN 2.0 standard.](https://www.bpmn.org/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Prosess handling
description: Applikasjons templaten støtter å definere en foretnings prosess for digitale tjenester
tags: [altinn-apps, process, bpmn]
weight: 2
weight: 60
---

Malen følger [BPMN 2.0-standarden](https://www.bpmn.org/).
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 73e25e8

Please sign in to comment.