Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dp 3047 present additional metadata items #91

Merged
merged 62 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
e78b725
update form with updated fields
mitchdawson1982 Feb 19, 2024
0ec2c6d
update form with updated fields
mitchdawson1982 Feb 19, 2024
7fc7684
implement custom property search
mitchdawson1982 Feb 20, 2024
95f65b5
update pre-commit
tom-webber Feb 21, 2024
ccdebcb
linting
tom-webber Feb 21, 2024
a1fb168
linting and formatting for readability
tom-webber Feb 21, 2024
1079046
revert domains (plural) -> domain (singular) changes (may be implemen…
tom-webber Feb 21, 2024
2e78f6d
add descriptions and code annotations for added helper functions
tom-webber Feb 21, 2024
c8d5d6f
keep original indent for domain filters
tom-webber Feb 21, 2024
9f35250
linting
tom-webber Feb 21, 2024
8a181a9
add pre-commit instructions/details to readme
tom-webber Feb 22, 2024
a46b1c6
Changed value for selection option an empty string and updated where_…
mitchdawson1982 Feb 22, 2024
389a609
Make domain a single choice field
mitchdawson1982 Feb 22, 2024
4de3eb3
Removed admin.py as not required
mitchdawson1982 Feb 24, 2024
90c4368
Moved filter code to new partial template
mitchdawson1982 Feb 24, 2024
c3ccd25
refactor domain and subdomain choices to get the urn value
mitchdawson1982 Feb 24, 2024
001becb
build filter strings method to create filter search strings
mitchdawson1982 Feb 24, 2024
298b8c1
refactor classifications and where to access string generation, remov…
mitchdawson1982 Feb 24, 2024
64ff26f
refactor where to access href creation
mitchdawson1982 Feb 24, 2024
78fa710
add get_keys and format_label template filter functions
mitchdawson1982 Feb 24, 2024
d76b377
Update broken tests
mitchdawson1982 Feb 24, 2024
9858ab8
add selected filters partial
mitchdawson1982 Feb 24, 2024
cafc012
update packages
mitchdawson1982 Feb 24, 2024
39fc25a
refactor encode_without_filter function
mitchdawson1982 Feb 24, 2024
93679f4
remove redundant code
mitchdawson1982 Feb 26, 2024
a98d658
update tests with singular domain, classifications and where_to_access
mitchdawson1982 Feb 26, 2024
e827a3e
Update dingular domain and add linting fixes
mitchdawson1982 Feb 26, 2024
82d41f9
Merge branch 'main' into dp-3047-present-additional-metadata-items
mitchdawson1982 Feb 26, 2024
c78026b
linter updates
mitchdawson1982 Feb 26, 2024
f4a8785
add service for dataproductdetails
LavMatt Feb 21, 2024
35eb1cf
update templates - data product details and search
LavMatt Feb 21, 2024
c920a04
url for search link and details redirect in views
LavMatt Feb 21, 2024
b6fda81
add tests for data product details and view
LavMatt Feb 21, 2024
d5b5ec2
add selenium test for data product detail page
LavMatt Feb 21, 2024
17f284a
update poetry
LavMatt Feb 21, 2024
4adb315
fix selenium tests that sometimes hit a dead end
LavMatt Feb 23, 2024
875b88b
actually make the tests work for data product details
LavMatt Feb 23, 2024
779a7af
this template will always be data product and align case
LavMatt Feb 23, 2024
cc74fd6
rename view, service and add blank dataset template
LavMatt Feb 23, 2024
b987082
markdown and trim for table descriptions in data product detail page
LavMatt Feb 23, 2024
36ba9e5
remove self.data_product_name from dataproductservice
LavMatt Feb 23, 2024
2a37387
try reinstalling deps for selenium tests
LavMatt Feb 26, 2024
f853f7a
revert workflow change
LavMatt Feb 26, 2024
5b24a2c
Add javascript for domain filter widget
MatMoore Feb 20, 2024
54cb4bd
Revert template - will add backend later
MatMoore Feb 22, 2024
2b1fd7d
Add test
MatMoore Feb 26, 2024
369f453
Install a compatable version of chrome/chromedriver
MatMoore Feb 26, 2024
83e7508
update form with updated fields
mitchdawson1982 Feb 19, 2024
517f266
update form with updated fields
mitchdawson1982 Feb 19, 2024
b4abaed
implement custom property search
mitchdawson1982 Feb 20, 2024
5441f57
revert domains (plural) -> domain (singular) changes (may be implemen…
tom-webber Feb 21, 2024
6660d5b
Make domain a single choice field
mitchdawson1982 Feb 22, 2024
5348c64
refactor classifications and where to access string generation, remov…
mitchdawson1982 Feb 24, 2024
962aefd
refactor where to access href creation
mitchdawson1982 Feb 24, 2024
e34a241
update packages
mitchdawson1982 Feb 24, 2024
35075f8
linter updates
mitchdawson1982 Feb 26, 2024
c259e99
remove duplicated function
mitchdawson1982 Feb 26, 2024
14e602f
update search result ui fields
mitchdawson1982 Feb 26, 2024
e94bb03
Merge branch 'main' into dp-3047-present-additional-metadata-items
mitchdawson1982 Feb 26, 2024
52ec70f
fix result type in conftest
mitchdawson1982 Feb 26, 2024
260e14f
remove official-sensitive classification
mitchdawson1982 Feb 26, 2024
84fb52e
add Custom Properties match display and rename 'list' to value_list
mitchdawson1982 Feb 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,30 @@ repos:
exclude: tf$|j2$

- repo: https://github.com/psf/black
rev: 23.11.0
rev: 23.12.1
hooks:
- id: black
name: black formatting
# args: [--config=./pyproject.toml]

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
name: flake8 lint
args: [
mitchdawson1982 marked this conversation as resolved.
Show resolved Hide resolved
'--ignore=E203,E266,W503,F403',
'--exclude=".git, .mypy_cache, .pytest_cache, build, dist"',
'--max-line-length=89',
'--max-complexity=18',
'--select="B,C,E,F,W,T4,B9"'
]
additional_dependencies:
- flake8-broken-line
- flake8-bugbear
- flake8-comprehensions
- flake8-debugger
- flake8-string-format

- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
Expand All @@ -31,7 +44,14 @@ repos:
exclude: package.lock.json

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
additional_dependencies: ["toml"]

- repo: https://github.com/floatingpurr/sync_with_poetry
rev: "1.1.0"
hooks:
- id: sync_with_poetry
args: []
122 changes: 122 additions & 0 deletions .secrets.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"version": "1.4.0",
"plugins_used": [
{
"name": "ArtifactoryDetector"
},
{
"name": "AWSKeyDetector"
},
{
"name": "AzureStorageKeyDetector"
},
{
"name": "Base64HighEntropyString",
"limit": 4.5
},
{
"name": "BasicAuthDetector"
},
{
"name": "CloudantDetector"
},
{
"name": "DiscordBotTokenDetector"
},
{
"name": "GitHubTokenDetector"
},
{
"name": "HexHighEntropyString",
"limit": 3.0
},
{
"name": "IbmCloudIamDetector"
},
{
"name": "IbmCosHmacDetector"
},
{
"name": "JwtTokenDetector"
},
{
"name": "KeywordDetector",
"keyword_exclude": ""
},
{
"name": "MailchimpDetector"
},
{
"name": "NpmDetector"
},
{
"name": "PrivateKeyDetector"
},
{
"name": "SendGridDetector"
},
{
"name": "SlackDetector"
},
{
"name": "SoftlayerDetector"
},
{
"name": "SquareOAuthDetector"
},
{
"name": "StripeDetector"
},
{
"name": "TwilioKeyDetector"
}
],
"filters_used": [
{
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
},
{
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
"min_level": 2
},
{
"path": "detect_secrets.filters.heuristic.is_indirect_reference"
},
{
"path": "detect_secrets.filters.heuristic.is_likely_id_string"
},
{
"path": "detect_secrets.filters.heuristic.is_lock_file"
},
{
"path": "detect_secrets.filters.heuristic.is_not_alphanumeric_string"
},
{
"path": "detect_secrets.filters.heuristic.is_potential_uuid"
},
{
"path": "detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign"
},
{
"path": "detect_secrets.filters.heuristic.is_sequential_string"
},
{
"path": "detect_secrets.filters.heuristic.is_swagger_file"
},
{
"path": "detect_secrets.filters.heuristic.is_templated_secret"
}
],
"results": {
"templates/base/base.html": [
{
"type": "Base64 High Entropy String",
"filename": "templates/base/base.html",
"hashed_secret": "f6538b22f89b1e2b05570de751f2932c6bca9969",
"is_verified": false,
"line_number": 40
}
]
},
"generated_at": "2024-02-21T10:23:47Z"
}
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ You will need npm (for javascript dependencies) and poetry (for python dependenc

1. Run `poetry install` to install python dependencies
2. Copy `.env.example` to `.env`.
3. You wil need to obtain an access token from Datahub catalogue and populate the `CATALOGUE_TOKEN` var in .env to be able to retrieve search data.
https://datahub.apps-tools.development.data-platform.service.justice.gov.uk/settings/tokens
3. You wil need to obtain an access token from Datahub catalogue and populate the
`CATALOGUE_TOKEN` var in .env to be able to retrieve search data.
4. Run `poetry run python manage.py runserver`

Run `npm install` and then `npm run sass` to compile the stylesheets.
Expand All @@ -16,6 +16,16 @@ Run `npm install` and then `npm run sass` to compile the stylesheets.

![Screenshot of the service showing the search page](image.png)

## Contributing

Run `pre-commit install` from inside the poetry environment to set up pre commit hooks.

- Linting and formatting handled by `black`, `flake8`, `pre-commit`, and `isort`
- `isort` is configured in `pyproject.toml`
- `detect-secrets` is used to prevent leakage of secrets
- `sync_with_poetry` ensures the versions of the modules in the pre-commit specification
are kept in line with those in the `pyproject.toml` config.

## Testing

- Python unit tests: `pytest -m 'not slow'`
Expand Down
2 changes: 1 addition & 1 deletion core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
from .settings import *
from .settings import * # noqa: F401
11 changes: 4 additions & 7 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa: E501
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
Expand All @@ -86,10 +86,8 @@

LANGUAGE_CODE = "en-gb"

TIME_ZONE = "UTC"

USE_I18N = True

TIME_ZONE = "Europe/London"
USE_I18N = False
USE_TZ = True


Expand All @@ -113,8 +111,7 @@
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
)

SAMPLE_SEARCH_RESULTS_FILENAME = BASE_DIR / \
"sample_data/sample_search_page.yaml"
SAMPLE_SEARCH_RESULTS_FILENAME = BASE_DIR / "sample_data/sample_search_page.yaml"

with open(SAMPLE_SEARCH_RESULTS_FILENAME) as f:
SAMPLE_SEARCH_RESULTS = yaml.safe_load(f)
Expand Down
1 change: 1 addition & 0 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import include, path

Expand Down
3 changes: 0 additions & 3 deletions home/admin.py

This file was deleted.

47 changes: 39 additions & 8 deletions home/forms/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
from django import forms


def get_domain_choices():
def get_domain_choices() -> list[tuple[str, str]]:
"""Make API call to obtain domain choices"""
# TODO: pull in the domains from the catalogue client
# facets = client.search_facets()
# domain_list = facets.options("domains")
return [
("", "All Domains"),
("urn:li:domain:HMCTS", "HMCTS"),
("urn:li:domain:HMPPS", "HMPPS"),
("urn:li:domain:HQ", "HQ"),
Expand Down Expand Up @@ -69,6 +70,18 @@ def get_sort_choices():
]


def get_classification_choices():
return [
("OFFICIAL", "Official"),
("SECRET", "Secret"),
("TOP-SECRET", "Top-Secret"),
]


def get_where_to_access_choices():
return [("analytical_platform", "Analytical Platform")]


class SearchForm(forms.Form):
"""Django form to represent data product search page inputs"""

Expand All @@ -78,9 +91,27 @@ class SearchForm(forms.Form):
required=False,
widget=forms.TextInput(attrs={"class": "govuk-input search-input"}),
)
domains = forms.MultipleChoiceField(
domain = forms.ChoiceField(
choices=get_domain_choices,
required=False,
widget=forms.Select(
attrs={
"form": "searchform",
"class": "govuk-select",
"aria-label": "domain",
}
),
)
classifications = forms.MultipleChoiceField(
choices=get_classification_choices,
required=False,
widget=forms.CheckboxSelectMultiple(
attrs={"class": "govuk-checkboxes__input", "form": "searchform"}
),
)
where_to_access = forms.MultipleChoiceField(
choices=get_where_to_access_choices,
required=False,
widget=forms.CheckboxSelectMultiple(
attrs={"class": "govuk-checkboxes__input", "form": "searchform"}
),
Expand All @@ -103,13 +134,13 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.initial["sort"] = "relevance"

def encode_without_filter(self, filter_to_remove):
def encode_without_filter(self, filter_name: str, filter_value: str):
"""Preformat hrefs to drop individual filters"""
# Deepcopy the cleaned data dict to avoid modifying it inplace
query_params = deepcopy(self.cleaned_data)

query_params["domains"].remove(filter_to_remove)
if len(query_params["domains"]) == 0:
query_params.pop("domains")

value = query_params.get(filter_name)
if isinstance(value, list) and filter_value in value:
value.remove(filter_value)
elif isinstance(value, str) and filter_value == value:
query_params.pop(filter_name)
return f"?{urlencode(query_params, doseq=True)}"
2 changes: 1 addition & 1 deletion home/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ def filter_seleted_domains(domain_list, domains):

def get_domain_list(client):
facets = client.search_facets()
domain_list = facets.options("domains")
domain_list = facets.options("domain")
return domain_list
Loading
Loading