Skip to content

Commit

Permalink
continue the rename of "incident report" to "field report"
Browse files Browse the repository at this point in the history
this takes us most of the way down to the persistence layer

#1469
  • Loading branch information
srabraham committed Dec 21, 2024
1 parent 1fd9c22 commit 3dc0fc0
Show file tree
Hide file tree
Showing 19 changed files with 415 additions and 431 deletions.
20 changes: 10 additions & 10 deletions src/ims/application/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,14 @@ async def listFieldReportsResource(
user: IMSUser = request.user # type: ignore[attr-defined]
fieldReports = (
fieldReport
for fieldReport in await store.incidentReports(
for fieldReport in await store.fieldReports(
event_id, excludeSystemEntries=excludeSystemEntries
)
if user.shortNames[0]
in (entry.author for entry in fieldReport.reportEntries)
)
elif incidentNumberText is None:
fieldReports = await store.incidentReports(
fieldReports = await store.fieldReports(
event_id, excludeSystemEntries=excludeSystemEntries
)
else:
Expand All @@ -724,7 +724,7 @@ async def listFieldReportsResource(
except ValueError:
return invalidQueryResponse(request, "incident", incidentNumberText)

fieldReports = await store.incidentReportsAttachedToIncident(
fieldReports = await store.fieldReportsAttachedToIncident(
eventID=event_id, incidentNumber=incidentNumber
)

Expand Down Expand Up @@ -822,7 +822,7 @@ async def newFieldReportResource(

# Store the field report

fieldReport = await self.config.store.createIncidentReport(fieldReport, author)
fieldReport = await self.config.store.createFieldReport(fieldReport, author)

self._log.info(
"User {author} created new field report #{fieldReport.number} via JSON",
Expand Down Expand Up @@ -858,11 +858,11 @@ async def readFieldReportResource(
return notFoundResponse(request)
del field_report_number

fieldReport = await self.config.store.incidentReportWithNumber(
fieldReport = await self.config.store.fieldReportWithNumber(
event_id, fieldReportNumber
)

await self.config.authProvider.authorizeRequestForIncidentReport(
await self.config.authProvider.authorizeRequestForFieldReport(
request, fieldReport
)

Expand Down Expand Up @@ -909,11 +909,11 @@ async def editFieldReportResource(
return invalidQueryResponse(request, "incident", incidentNumberText)

if action == "attach":
await store.attachIncidentReportToIncident(
await store.attachFieldReportToIncident(
fieldReportNumber, event_id, incidentNumber, author
)
elif action == "detach":
await store.detachIncidentReportFromIncident(
await store.detachFieldReportFromIncident(
fieldReportNumber, event_id, incidentNumber, author
)
else:
Expand Down Expand Up @@ -967,7 +967,7 @@ def _cast(obj: Any) -> Any:
await applyEdit(
edits,
IncidentReportJSONKey.summary,
store.setIncidentReport_summary,
store.setFieldReport_summary,
)

jsonEntries = edits.get(IncidentReportJSONKey.reportEntries.value, UNSET)
Expand All @@ -984,7 +984,7 @@ def _cast(obj: Any) -> Any:
for jsonEntry in jsonEntries
)

await store.addReportEntriesToIncidentReport(
await store.addReportEntriesToFieldReport(
event_id, fieldReportNumber, entries, author
)

Expand Down
20 changes: 10 additions & 10 deletions src/ims/application/_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from ims.element.root import RootPage
from ims.ext.klein import static
from ims.model import Event
from ims.store import NoSuchIncidentReportError
from ims.store import NoSuchFieldReportError

from ._klein import Router, notFoundResponse, redirect

Expand Down Expand Up @@ -243,37 +243,37 @@ async def viewFieldReportPage(
"""
Endpoint for the field report page.
"""
incidentReportNumber: int | None
fieldReportNumber: int | None
config = self.config
if number == "new":
await config.authProvider.authorizeRequest(
request, event_id, Authorization.writeFieldReports
)
incidentReportNumber = None
fieldReportNumber = None
del number
else:
try:
incidentReportNumber = int(number)
fieldReportNumber = int(number)
except ValueError:
return notFoundResponse(request)
del number

try:
incidentReport = await config.store.incidentReportWithNumber(
event_id, incidentReportNumber
fieldReport = await config.store.fieldReportWithNumber(
event_id, fieldReportNumber
)
except NoSuchIncidentReportError:
except NoSuchFieldReportError:
await config.authProvider.authorizeRequest(
request, event_id, Authorization.readIncidents
)
return notFoundResponse(request)

await config.authProvider.authorizeRequestForIncidentReport(
request, incidentReport
await config.authProvider.authorizeRequestForFieldReport(
request, fieldReport
)

event = Event(id=event_id)
return FieldReportPage(config=config, event=event, number=incidentReportNumber)
return FieldReportPage(config=config, event=event, number=fieldReportNumber)

@router.route(_unprefix(URLs.viewFieldReportTemplate), methods=("HEAD", "GET"))
@static
Expand Down
14 changes: 7 additions & 7 deletions src/ims/auth/_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,20 +441,20 @@ async def authorizeRequest(
)
raise NotAuthorizedError("User not authorized")

async def authorizeRequestForIncidentReport(
self, request: IRequest, incidentReport: IncidentReport
async def authorizeRequestForFieldReport(
self, request: IRequest, fieldReport: IncidentReport
) -> None:
"""
Determine whether the user attached to a request has the required
authorizations to access the incident report with the given number.
authorizations to access the field report with the given number.
"""
# An author of the incident report should be allowed to read and write
# to it, provided they have writeFieldReports on the event.
userIsAuthor = False
user: IMSUser = request.user # type: ignore[attr-defined]
if user is not None and incidentReport.reportEntries:
if user is not None and fieldReport.reportEntries:
rangerHandle = user.shortNames[0]
for reportEntry in incidentReport.reportEntries:
for reportEntry in fieldReport.reportEntries:
if reportEntry.author == rangerHandle:
userIsAuthor = True
break
Expand All @@ -465,7 +465,7 @@ async def authorizeRequestForIncidentReport(
try:
await self.authorizeRequest(
request,
incidentReport.eventID,
fieldReport.eventID,
Authorization.writeFieldReports,
)
except NotAuthorizedError:
Expand All @@ -478,5 +478,5 @@ async def authorizeRequestForIncidentReport(

# Authorize the user if they have readIncidents permission
await self.authorizeRequest(
request, incidentReport.eventID, Authorization.readIncidents
request, fieldReport.eventID, Authorization.readIncidents
)
24 changes: 12 additions & 12 deletions src/ims/auth/test/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,9 @@ def test_authorizeReqForIncidentReport(self) -> None:
# Stage 1: user doesn't have writeFieldReports, so no incident
# report can be read.
self.failureResultOf(
provider.authorizeRequestForIncidentReport(
provider.authorizeRequestForFieldReport(
request=request,
incidentReport=reportByUser,
fieldReport=reportByUser,
),
NotAuthorizedError,
)
Expand All @@ -811,16 +811,16 @@ def test_authorizeReqForIncidentReport(self) -> None:
# Stage 2: user is a reporter
self.successResultOf(store.setReporters(event, (personUser,)))
self.successResultOf(
provider.authorizeRequestForIncidentReport(
provider.authorizeRequestForFieldReport(
request=request,
incidentReport=reportByUser,
fieldReport=reportByUser,
),
)
self.assertEqual(request.authorizations, Authorization.writeFieldReports)
self.failureResultOf(
provider.authorizeRequestForIncidentReport(
provider.authorizeRequestForFieldReport(
request=request,
incidentReport=reportNotByUser,
fieldReport=reportNotByUser,
),
NotAuthorizedError,
)
Expand All @@ -830,15 +830,15 @@ def test_authorizeReqForIncidentReport(self) -> None:
self.successResultOf(store.setReporters(event, ()))
self.successResultOf(store.setReaders(event, (personUser,)))
self.successResultOf(
provider.authorizeRequestForIncidentReport(
provider.authorizeRequestForFieldReport(
request=request,
incidentReport=reportByUser,
fieldReport=reportByUser,
),
)
self.successResultOf(
provider.authorizeRequestForIncidentReport(
provider.authorizeRequestForFieldReport(
request=request,
incidentReport=reportNotByUser,
fieldReport=reportNotByUser,
),
)
self.assertEqual(
Expand All @@ -850,9 +850,9 @@ def test_authorizeReqForIncidentReport(self) -> None:
self.successResultOf(store.setReaders(event, ()))
self.successResultOf(store.setWriters(event, (personUser,)))
self.successResultOf(
provider.authorizeRequestForIncidentReport(
provider.authorizeRequestForFieldReport(
request=request,
incidentReport=reportNotByUser,
fieldReport=reportNotByUser,
),
)
self.assertEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@mutable(kw_only=True)
class FieldReportTemplatePage(Page):
"""
Incident report template page.
Field report template page.
"""

name: str = title
4 changes: 2 additions & 2 deletions src/ims/store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

from ._abc import IMSDataStore
from ._exceptions import (
NoSuchFieldReportError,
NoSuchIncidentError,
NoSuchIncidentReportError,
StorageError,
)


__all__ = (
"IMSDataStore",
"NoSuchFieldReportError",
"NoSuchIncidentError",
"NoSuchIncidentReportError",
"StorageError",
)
Loading

0 comments on commit 3dc0fc0

Please sign in to comment.