Skip to content

Commit 56e9437

Browse files
Merge pull request #201 from stuartcampbell/maintenance
Maintenance tasks before release
2 parents f63bef8 + 18df3b7 commit 56e9437

11 files changed

Lines changed: 74 additions & 146 deletions

File tree

scripts/migrate_satellite_locations.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/nsls2api/api/v1/admin_api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
ProposalsToChangeList,
1212
SingleProposal,
1313
)
14-
from nsls2api.api.v1.proposal_api import router
1514
from nsls2api.infrastructure import config
1615
from nsls2api.infrastructure.security import (
1716
generate_api_key,
@@ -25,7 +24,6 @@
2524
)
2625
from nsls2api.services import beamline_service, facility_service, proposal_service
2726

28-
# router = fastapi.APIRouter()
2927
router = fastapi.APIRouter(
3028
dependencies=[Depends(validate_admin_role)], include_in_schema=True, tags=["admin"]
3129
)

src/nsls2api/api/v1/proposal_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
)
3030
from nsls2api.services.slack_service import get_conversation_details
3131

32-
3332
router = fastapi.APIRouter(dependencies=[Depends(get_current_user)])
3433

3534

src/nsls2api/infrastructure/security.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ async def generate_api_key(username: str, usertype=ApiUserType.user):
6262
user=user,
6363
username=username,
6464
first_eight=secret_key[prefix_length : prefix_length + 8],
65-
secret_key=secret_key, # TODO: After development - we will not be storing this one in the database
6665
hashed_key=to_hash,
6766
expires_after=None,
6867
)
@@ -74,11 +73,11 @@ async def generate_api_key(username: str, usertype=ApiUserType.user):
7473
# Now that we have saved a new key for this user, we should invalidate any other keys
7574
for old_key in old_keys:
7675
if old_key.valid:
77-
logger.info(f"Invalidating old key: {old_key.secret_key}")
76+
logger.info(f"Invalidating old key: {old_key}")
7877
old_key.valid = False
7978
await old_key.save(link_rule=WriteRules.WRITE)
8079

81-
return {"key:": secret_key}
80+
return {"key": secret_key}
8281

8382
except Exception as e:
8483
logger.exception(e)

src/nsls2api/models/apikeys.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ class ApiKey(beanie.Document):
6969
user: Link[ApiUser]
7070
username: str
7171
first_eight: pydantic.constr(min_length=8, max_length=8)
72-
secret_key: (
73-
str # TODO: After development - we will not be storing this one in the database
74-
)
7572
hashed_key: str
7673
note: Optional[str] = ""
7774
# scopes: Optional[list[str]] = pydantic.Field(..., example=["inherit"])

src/nsls2api/services/bnlpeople_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def get_username_by_id(lifenumber: str) -> Optional[str]:
4242
message = f"BNL People API query failed for lifenumber {lifenumber}"
4343
logger.exception(message)
4444
return None
45-
logger.debug(person)
45+
# logger.debug(person)
4646
if len(person) == 0 or len(person) > 1:
4747
logger.warning(
4848
f"BNL People could not find a person with an employee/life number of '{lifenumber}'"

src/nsls2api/services/proposal_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from nsls2api.api.models.facility_model import FacilityName
1212
from nsls2api.api.models.proposal_model import (
1313
CommissioningProposalsList,
14-
ProposalDiagnostics,
15-
ProposalFullDetails,
1614
LockedProposalsList,
1715
ProposalChangeResultsList,
16+
ProposalDiagnostics,
17+
ProposalFullDetails,
1818
ProposalsToChangeList,
1919
)
2020
from nsls2api.infrastructure.logging import logger

src/nsls2api/services/sync_service.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ async def worker_synchronize_dataadmins(skip_beamlines=False) -> None:
8181
f"Beamline Data Admin permissions synchronized in {time_taken.total_seconds():,.2f} seconds"
8282
)
8383

84+
8485
async def worker_synchronize_cycles_from_pass(
8586
facility_name: FacilityName = FacilityName.nsls2,
8687
) -> None:
@@ -148,15 +149,15 @@ async def worker_synchronize_cycles_from_pass(
148149
today = datetime.datetime.now()
149150
found_cycle = await facility_service.facility_cycle_by_date(facility_name, today)
150151
if not found_cycle:
151-
logger.warning(
152-
f"No cycle found for today's date in facility {facility_name}"
153-
)
152+
logger.warning(f"No cycle found for today's date in facility {facility_name}")
154153
else:
155154
logger.info(
156155
f"Found cycle {found_cycle.name} for today's date in facility {facility_name}"
157156
)
158157
# Set the current operating cycle for the facility
159-
await facility_service.set_current_operating_cycle(facility_name, found_cycle.name)
158+
await facility_service.set_current_operating_cycle(
159+
facility_name, found_cycle.name
160+
)
160161
logger.info(
161162
f"Set current operating cycle for {facility_name} to {found_cycle.name}"
162163
)
@@ -221,6 +222,18 @@ async def worker_synchronize_proposal_types_from_pass(
221222
async def synchronize_proposal_from_pass(
222223
proposal_id: str, facility_name: FacilityName = FacilityName.nsls2
223224
) -> None:
225+
"""
226+
Synchronize a proposal from PASS into the local database.
227+
228+
This function fetches proposal details, associated SAFs, beamlines, and users from PASS,
229+
and updates or inserts the corresponding Proposal document in the database.
230+
231+
:param proposal_id: The PASS proposal ID to synchronize.
232+
:type proposal_id: str
233+
:param facility_name: The facility name (FacilityName) to use for synchronization.
234+
:type facility_name: FacilityName
235+
:return: None
236+
"""
224237
beamline_list = []
225238
user_list = []
226239
saf_list = []
@@ -348,10 +361,13 @@ async def update_proposals_with_cycle(
348361
cycle_name: str, facility_name: FacilityName = FacilityName.nsls2
349362
) -> None:
350363
"""
351-
Update the cycle <-> proposals mapping for the given cycle.
364+
Update the mapping between cycles and proposals for the specified cycle.
352365
353366
:param cycle_name: The name of the cycle to process proposals for.
354367
:type cycle_name: str
368+
:param facility_name: The facility name (FacilityName) to use for synchronization.
369+
:type facility_name: FacilityName
370+
:return: None
355371
"""
356372

357373
proposal_list = await proposal_service.fetch_proposals_for_cycle(
@@ -364,7 +380,6 @@ async def update_proposals_with_cycle(
364380

365381
for proposal_id in proposal_list:
366382
# Add the cycle to the Proposal object
367-
368383
try:
369384
proposal = await proposal_service.proposal_by_id(proposal_id)
370385
if proposal is not None:

0 commit comments

Comments
 (0)