Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .github/workflows/bad-name-notifier-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ on:
- "false"
- "true"

permissions:
id-token: write
contents: write

jobs:
namex-bad-name-notifier-cd:
uses: bcgov/bcregistry-sre/.github/workflows/backend-job-cd.yaml@main
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/bad-name-notifier-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ defaults:
shell: bash
working-directory: ./jobs/bad-name-notifier

permissions:
id-token: write
contents: write

jobs:
namex-bad-name-notifier-ci:
uses: bcgov/bcregistry-sre/.github/workflows/backend-ci.yaml@main
with:
app_name: "namex-bad-name-notifier"
working_directory: "./jobs/bad-name-notifier"
codecov_flag: "namexbadnamenotifier"
skip_isort: "true"
skip_black: "true"
codecov_flag: "namex-bad-name-notifier"
4 changes: 1 addition & 3 deletions .github/workflows/sftp-nuans-report-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ jobs:
with:
app_name: "nuans-report"
working_directory: "./jobs/sftp-nuans-report"
codecov_flag: "namexnuansreport"
skip_isort: "true"
skip_black: "true"
codecov_flag: "namexnuansreport"
35 changes: 33 additions & 2 deletions api/namex/resources/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
from namex.utils import queue_util
from namex.utils.auth import cors_preflight
from namex.utils.common import convert_to_ascii, convert_to_utc_max_date_time, convert_to_utc_min_date_time
from namex.utils.nr_query import get_nr_num_from_query
from namex.services.name_request.name_request import get_nrs_like_nr_num, get_nrs_like_names

from .utils import DateUtils

Expand Down Expand Up @@ -111,7 +113,7 @@ class RequestsQueue(Resource):
@jwt.requires_roles([User.APPROVER])
@api.doc(
description='Fetches the next draft name request from the queue and assigns it to the current user. '
'If the user already has an in-progress NR, that one is returned instead.',
'If the user already has an in-progress NR, that one is returned instead.',
params={'priorityQueue': 'Set to true to fetch from the priority queue'},
responses={
200: 'Name request assigned successfully',
Expand Down Expand Up @@ -504,6 +506,7 @@ def get():

try:
results = SolrClient.search_nrs(query, start, rows)
existing_nrs = set(nr['nr_num'] for nr in results['searchResults']['results'])
data.extend(
[
{
Expand All @@ -513,6 +516,33 @@ def get():
for nr in results['searchResults']['results']
]
)
nr_num = get_nr_num_from_query(query)
if nr_num:
nrs = get_nrs_like_nr_num(nr_num)
data.extend(
[
{
'nrNum': nr.nrNum,
'names': [n.name for n in nr.names]
}
for nr in nrs
if nr.nrNum not in existing_nrs
]
)
else:
# above, we returned nothing if query was empty
nrs = get_nrs_like_names(query)
data.extend(
[
{
'nrNum': nr.nrNum,
'names': [n.name for n in nr.names]
}
for nr in nrs
if nr.nrNum not in existing_nrs
]
)

return make_response(jsonify(data), 200)
except Exception:
current_app.logger.error(f'Error when searching for {query}\n{traceback.format_exc()}')
Expand Down Expand Up @@ -835,7 +865,8 @@ def consumeName(nrd, json_input):
return make_response(jsonify(message='Internal server error'), 500)

if 'warnings' in locals() and warnings: # noqa: F821
return make_response(jsonify(message='Request:{} - patched'.format(nr), warnings=warnings), 206) # noqa: F821
return make_response(jsonify(message='Request:{} - patched'.format(nr), warnings=warnings),
206) # noqa: F821

if state in [State.APPROVED, State.CONDITIONAL, State.REJECTED]:
queue_util.publish_email_notification(nrd.nrNum, state)
Expand Down
19 changes: 19 additions & 0 deletions api/namex/services/name_request/name_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,22 @@ def save_request(cls, name_request, on_success=None):

except Exception as err:
raise SaveNameRequestError(err)


def get_nrs_like_nr_num(nr_num) -> list:
db_data = (
Request.query
.filter(Request.nrNum.ilike(f'%{nr_num}%'))
.all()
)

return db_data


def get_nrs_like_names(name_search) -> list:
db_data = (
Request.query
.filter(Request.names.any(Name.name.ilike(f'%{name_search}%')))
)

return db_data
1 change: 1 addition & 0 deletions api/namex/services/solr/solr_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def get_possible_conflicts(cls, name, start=0, rows=100):
}

token = cls._get_bearer_token()

resp = requests.post(
url=f'{cls._get_solr_api_url()}/search/possible-conflict-names',
json=request_json,
Expand Down
17 changes: 17 additions & 0 deletions jobs/bad-name-notifier/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Dockerfile
__pycache__
coverage.xml
.devcontainer
.dockerignore
.pytest_cache
.venv
venv
.env
.env*
.eggs
.history
.vscode
Makefile
requirements
poetry.toml
tests
8 changes: 8 additions & 0 deletions jobs/bad-name-notifier/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 80
extend-ignore = E501
exclude =
.venv,
.git,
migrations,
tests
32 changes: 30 additions & 2 deletions jobs/bad-name-notifier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,33 @@ Bad-Name-Notifier is a Python application designed to identify names with specia

1. Clone the repository:
```bash
git clone https://github.com/your-repo/bad-name-notifier.git
cd bad-name-notifier
git clone https://github.com/your-repo/namex.git
cd jobs/bad-name-notifier

2 ### Install the dependencies
```bash
poetry install
```

3 ### Configure the .env
(see .env.sample)

```bash
eval $(poetry env activate)
```

4 ### Run the job
```bash
python src/bad_name_notifier/app.py
OR: ./run.sh
```

5 ### Run Linting
```bash
poetry run ruff check --fix
```

6 ### Run unit tests
```bash
poetry run pytest
```
Empty file.
Loading