Skip to content

Commit 0835a02

Browse files
Implement GUI roles
1 parent 905e618 commit 0835a02

114 files changed

Lines changed: 7891 additions & 1742 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/pull_request_template.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Resolves #
1212

1313
Please check all the boxes that apply to this pull request using "x":
1414

15-
- [ ] I have tested the changes locally and verified that they work as expected.
16-
- [ ] I have followed the project's coding conventions and style guidelines.
17-
- [ ] I have rebased my branch onto the latest commit of the main branch.
18-
- [ ] I have squashed or reorganized my commits into logical units.
19-
- [ ] I have read, understood and agree to the [Developer Certificate of Origin](../blob/main/DCO.md), which this project utilizes.
15+
- [ ] I have tested the changes locally and verified that they work as expected.
16+
- [ ] I have followed the project's coding conventions and style guidelines.
17+
- [ ] I have rebased my branch onto the latest commit of the main branch.
18+
- [ ] I have squashed or reorganized my commits into logical units.
19+
- [ ] I have read, understood and agree to the [Developer Certificate of Origin](../blob/main/DCO.md), which this project utilizes.

BUILD.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ pip install --upgrade setuptools
121121

122122
For testing, linting and other feature we use several tools. You can look up the documentation on how to use these:
123123

124-
- [pytest](https://docs.pytest.org/en/) `poetry run pytest`
125-
- [ruff](https://docs.astral.sh/ruff/) `poetry run ruff format` or `poetry run ruff check --fix`
126-
- [coverage](https://coverage.readthedocs.io/en/) `poetry run coverage report`
127-
- [pyright](https://microsoft.github.io/pyright/#/) `poetry run pyright`
124+
- [pytest](https://docs.pytest.org/en/) `poetry run pytest`
125+
- [ruff](https://docs.astral.sh/ruff/) `poetry run ruff format` or `poetry run ruff check --fix`
126+
- [coverage](https://coverage.readthedocs.io/en/) `poetry run coverage report`
127+
- [pyright](https://microsoft.github.io/pyright/#/) `poetry run pyright`
128128

129129
## Devcontainers
130130

@@ -145,3 +145,11 @@ Use pre-commit to update all hooks
145145
```shell
146146
pre-commit autoupdate
147147
```
148+
149+
## Local Testing with Docker
150+
151+
```shell
152+
docker compose -f compose.yml -f compose.test.yml build
153+
docker compose down -v --remove-orphans --volumes
154+
docker compose -f compose.yml -f compose.test.yml up -d
155+
```

CODE_OF_CONDUCT.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ appearance, race, religion, or sexual identity and orientation.
1414
Examples of behavior that contributes to a positive environment for our
1515
community include:
1616

17-
- Demonstrating empathy and kindness toward other people
18-
- Being respectful of differing opinions, viewpoints, and experiences
19-
- Giving and gracefully accepting constructive feedback
20-
- Accepting responsibility and apologizing to those affected by our mistakes,
21-
and learning from the experience
22-
- Focusing on what is best not just for us as individuals, but for the
23-
overall community
17+
- Demonstrating empathy and kindness toward other people
18+
- Being respectful of differing opinions, viewpoints, and experiences
19+
- Giving and gracefully accepting constructive feedback
20+
- Accepting responsibility and apologizing to those affected by our mistakes,
21+
and learning from the experience
22+
- Focusing on what is best not just for us as individuals, but for the
23+
overall community
2424

2525
Examples of unacceptable behavior include:
2626

27-
- The use of sexualized language or imagery, and sexual attention or
28-
advances
29-
- Trolling, insulting or derogatory comments, and personal or political attacks
30-
- Public or private harassment
31-
- Publishing others' private information, such as a physical or email
32-
address, without their explicit permission
33-
- Other conduct which could reasonably be considered inappropriate in a
34-
professional setting
27+
- The use of sexualized language or imagery, and sexual attention or
28+
advances
29+
- Trolling, insulting or derogatory comments, and personal or political attacks
30+
- Public or private harassment
31+
- Publishing others' private information, such as a physical or email
32+
address, without their explicit permission
33+
- Other conduct which could reasonably be considered inappropriate in a
34+
professional setting
3535

3636
## Our Responsibilities
3737

CONTRIBUTING.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ community looks forward to your contributions. 🎉
99

1010
## Table of Contents
1111

12-
- [Code of Conduct](#code-of-conduct)
13-
- [I Have a Question](#i-have-a-question)
14-
- [I Want To Contribute](#i-want-to-contribute)
15-
- [Reporting Bugs](#reporting-bugs)
16-
- [Suggesting Enhancements](#suggesting-enhancements)
12+
- [Code of Conduct](#code-of-conduct)
13+
- [I Have a Question](#i-have-a-question)
14+
- [I Want To Contribute](#i-want-to-contribute)
15+
- [Reporting Bugs](#reporting-bugs)
16+
- [Suggesting Enhancements](#suggesting-enhancements)
1717

1818
## Code of Conduct
1919

@@ -29,8 +29,8 @@ in this issue.
2929

3030
If you then still feel the need to ask a question and need clarification, we recommend the following:
3131

32-
- Open an [Issue](../../issues/new).
33-
- Provide as much context as you can about what you're running into.
32+
- Open an [Issue](../../issues/new).
33+
- Provide as much context as you can about what you're running into.
3434

3535
We will then take care of the issue as soon as possible.
3636

@@ -49,11 +49,11 @@ A good bug report shouldn't leave others needing to chase you up for more inform
4949
investigate carefully, collect information and describe the issue in detail in your report. Please complete the
5050
following steps in advance to help us fix any potential bug as fast as possible.
5151

52-
- Make sure that you are using the latest version.
53-
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there
54-
is not already a bug report existing for your bug or error in the [bug tracker](../..//issues?q=label%3Abug).
55-
- Collect information about the bug
56-
- Possibly your input and the output
52+
- Make sure that you are using the latest version.
53+
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there
54+
is not already a bug report existing for your bug or error in the [bug tracker](../..//issues?q=label%3Abug).
55+
- Collect information about the bug
56+
- Possibly your input and the output
5757

5858
#### How Do I Submit a Good Bug Report?
5959

@@ -62,21 +62,21 @@ following steps in advance to help us fix any potential bug as fast as possible.
6262
6363
We use GitHub issues to track bugs and errors. If you run into an issue with the project:
6464

65-
- Open an [Issue](../../issues/new). (Since we can't be sure at this point whether it
66-
is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
67-
- Explain the behavior you would expect and the actual behavior.
68-
- Please provide as much context as possible and describe the _reproduction steps_ that someone else can follow to
69-
recreate the issue on their own. This usually includes your code.
70-
- Provide the information you collected in the previous section.
65+
- Open an [Issue](../../issues/new). (Since we can't be sure at this point whether it
66+
is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
67+
- Explain the behavior you would expect and the actual behavior.
68+
- Please provide as much context as possible and describe the _reproduction steps_ that someone else can follow to
69+
recreate the issue on their own. This usually includes your code.
70+
- Provide the information you collected in the previous section.
7171

7272
Once it's filed:
7373

74-
- The project team will label the issue accordingly.
75-
- A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no
76-
obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs with
77-
the `needs-repro` tag will not be addressed until they are reproduced.
78-
- If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as
79-
`critical`), and the issue will be left to be implemented by someone.
74+
- The project team will label the issue accordingly.
75+
- A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no
76+
obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs with
77+
the `needs-repro` tag will not be addressed until they are reproduced.
78+
- If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as
79+
`critical`), and the issue will be left to be implemented by someone.
8080

8181
### Suggesting Enhancements
8282

@@ -86,22 +86,22 @@ community to understand your suggestion and find related suggestions.
8686

8787
#### Before Submitting an Enhancement
8888

89-
- Make sure that you are using the latest version.
90-
- Perform a [search](../../issues) to see if the enhancement has already been
91-
suggested. If it has, add a comment to the existing issue instead of opening a new one.
92-
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to
93-
convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful
94-
to the majority of our users and not just a small subset.
89+
- Make sure that you are using the latest version.
90+
- Perform a [search](../../issues) to see if the enhancement has already been
91+
suggested. If it has, add a comment to the existing issue instead of opening a new one.
92+
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to
93+
convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful
94+
to the majority of our users and not just a small subset.
9595

9696
#### How Do I Submit a Good Enhancement Suggestion?
9797

9898
Enhancement suggestions are tracked as [GitHub issues](../../issues).
9999

100-
- Use a **clear and descriptive title** for the issue to identify the suggestion.
101-
- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point
102-
you can also tell which alternatives do not work for you.
103-
- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part
104-
which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on MacOS and
105-
Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux.
106-
- **Explain why this enhancement would be useful** for the community. You may also want to point out the
107-
other projects that solved it better and which could serve as inspiration.
100+
- Use a **clear and descriptive title** for the issue to identify the suggestion.
101+
- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point
102+
you can also tell which alternatives do not work for you.
103+
- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part
104+
which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on MacOS and
105+
Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux.
106+
- **Explain why this enhancement would be useful** for the community. You may also want to point out the
107+
other projects that solved it better and which could serve as inspiration.

SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ CVSS (Common Vulnerability Scoring System) v4.0 Rating:
1414

1515
Please report (suspected) security vulnerabilities to NCSC:
1616

17-
- Nederlands: **[NCSC Kwetsbaarheid melden](https://www.ncsc.nl/contact/kwetsbaarheid-melden)**
18-
- English: **[NCSC report vulnerability](https://english.ncsc.nl/contact/reporting-a-vulnerability-cvd)**
17+
- Nederlands: **[NCSC Kwetsbaarheid melden](https://www.ncsc.nl/contact/kwetsbaarheid-melden)**
18+
- English: **[NCSC report vulnerability](https://english.ncsc.nl/contact/reporting-a-vulnerability-cvd)**

USAGE.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ on [github](https://github.com/MinBZK/amt/pkgs/container/amt).
99

1010
You can deploy AMT to kubernetes or run the container locally using docker compose.
1111

12-
- Example [kubernetes](https://github.com/MinBZK/ai-validation-infra/tree/main/apps/amt)
13-
- Example [docker compose](./compose.yml)
12+
- Example [kubernetes](https://github.com/MinBZK/ai-validation-infra/tree/main/apps/amt)
13+
- Example [docker compose](./compose.yml)
1414

1515
To run amt locally create a compose.yml file and
1616
install [docker desktop](https://www.docker.com/products/docker-desktop/). Once you have install docker you can run the
@@ -66,11 +66,11 @@ volumes:
6666
6767
it is possible to run AMT with the following databases:
6868
69-
- SQLite (tested)
70-
- Postgresql (tested)
71-
- MySQL
72-
- MariaDB
73-
- Oracle
69+
- SQLite (tested)
70+
- Postgresql (tested)
71+
- MySQL
72+
- MariaDB
73+
- Oracle
7474
7575
We recommend using postgresql for production grade deployments because that one is tested in our CI/CD. By default AMT
7676
will use SQLite which will create a local database within the AMT container.

amt/api/decorators.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import ChainMap
12
from collections.abc import Callable
23
from functools import wraps
34
from typing import Any
@@ -6,18 +7,36 @@
67

78
from amt.api.utils import SafeDict
89
from amt.core.exceptions import AMTPermissionDenied
10+
from amt.services.organizations import OrganizationsService
11+
from amt.services.services_provider import ServicesProvider
912

1013

11-
def permission(permissions: dict[str, list[str]]) -> Callable[[Callable[..., Any]], Callable[..., Any]]:
12-
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
14+
def permission(permissions: dict[str, list[str]]) -> Callable[[Callable[..., Any]], Callable[..., Any]]: # noqa C901
15+
def decorator(func: Callable[..., Any]) -> Callable[..., Any]: # noqa C901
1316
@wraps(func)
14-
async def wrapper(*args: Any, **kwargs: Any) -> Any: # noqa: ANN401
17+
async def wrapper(*args: Any, **kwargs: Any) -> Any: # noqa: ANN401 C901
1518
request = kwargs.get("request")
1619
if not isinstance(request, Request): # todo: change exception to custom exception
1720
raise HTTPException(status_code=400, detail="Request object is missing")
1821

22+
organization_slug_resolved = False
23+
extra_arguments: dict[str, Any] = {}
1924
for permission, verbs in permissions.items():
20-
permission = permission.format_map(SafeDict(kwargs))
25+
# convert organization_slug to id if required
26+
if "organization_slug" in kwargs and "organization_slug" in permission:
27+
if "organization_id" in kwargs:
28+
permission = permission.replace("organization_slug", "organization_id")
29+
else:
30+
if not organization_slug_resolved:
31+
service_provider = ServicesProvider()
32+
async with service_provider.session_scope():
33+
organization_service = await service_provider.get(OrganizationsService)
34+
organization = await organization_service.find_by_slug(kwargs["organization_slug"])
35+
extra_arguments["organization_id"] = organization.id
36+
organization_slug_resolved = True
37+
permission = permission.replace("organization_slug", "organization_id")
38+
39+
permission = permission.format_map(SafeDict(ChainMap(kwargs, extra_arguments)))
2140
request_permissions: dict[str, list[str]] = (
2241
request.state.permissions if hasattr(request.state, "permissions") else {}
2342
)

amt/api/deps.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import logging
2+
import re
3+
import uuid
24
from enum import Enum
35
from typing import TypeVar
46

57
from jinja2 import StrictUndefined, Undefined
68
from starlette.requests import Request
79

10+
from amt.api.editable_resolve_util import resolve_editable_from_path
811
from amt.api.editable_util import (
912
is_editable_resource,
1013
is_parent_editable,
@@ -35,7 +38,7 @@
3538
time_ago,
3639
)
3740
from amt.schema.shared import IterMixin
38-
from amt.schema.webform import WebFormFieldType
41+
from amt.schema.webform_classes import WebFormFieldType, WebFormOption
3942

4043
T = TypeVar("T", bound=Enum | LocalizableEnum)
4144

@@ -84,6 +87,8 @@ def instance(obj: object, type_str: str) -> bool:
8487
return isinstance(obj, IterMixin)
8588
case "dict":
8689
return isinstance(obj, dict)
90+
case "WebFormOption":
91+
return isinstance(obj, WebFormOption)
8792
case _:
8893
raise TypeError("Unsupported type: " + type_str)
8994

@@ -112,6 +117,24 @@ def equal_or_includes(my_value: str, check_against_value: str | list[str] | tupl
112117
return False
113118

114119

120+
def get_random_number() -> str:
121+
return "".join(char for char in str(uuid.uuid4()) if char.isdigit())
122+
123+
124+
def sanitize_html_id(input_string: str) -> str:
125+
pattern = r"[^a-zA-Z0-9\-_.:]"
126+
127+
sanitized_id = re.sub(pattern, "-", input_string)
128+
129+
if sanitized_id and sanitized_id[0].isdigit():
130+
sanitized_id = f"id-{sanitized_id}"
131+
132+
if not sanitized_id:
133+
sanitized_id = "empty-id"
134+
135+
return sanitized_id
136+
137+
115138
templates = LocaleJinja2Templates(
116139
directory="amt/site/templates/", context_processors=[custom_context_processor], undefined=get_undefined_behaviour()
117140
)
@@ -138,6 +161,9 @@ def equal_or_includes(my_value: str, check_against_value: str | list[str] | tupl
138161
"is_parent_editable": is_parent_editable,
139162
"resolve_resource_list_path": resolve_resource_list_path,
140163
"get_localized_value": get_localized_value,
164+
"get_random_number": get_random_number,
165+
"sanitize_html_id": sanitize_html_id,
166+
"resolve_editable_from_path": resolve_editable_from_path,
141167
}
142168
)
143169
# env tests allows for usage in templates like: if value is test_name(other_value)

0 commit comments

Comments
 (0)