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

continue the rename of "incident report" to "field report" #1472

Merged
merged 1 commit into from
Dec 21, 2024
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
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 @@
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(

Check warning on line 718 in src/ims/application/_api.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_api.py#L718

Added line #L718 was not covered by tests
event_id, excludeSystemEntries=excludeSystemEntries
)
else:
Expand All @@ -724,7 +724,7 @@
except ValueError:
return invalidQueryResponse(request, "incident", incidentNumberText)

fieldReports = await store.incidentReportsAttachedToIncident(
fieldReports = await store.fieldReportsAttachedToIncident(

Check warning on line 727 in src/ims/application/_api.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_api.py#L727

Added line #L727 was not covered by tests
eventID=event_id, incidentNumber=incidentNumber
)

Expand Down Expand Up @@ -822,7 +822,7 @@

# Store the field report

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

Check warning on line 825 in src/ims/application/_api.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_api.py#L825

Added line #L825 was not covered by tests

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

fieldReport = await self.config.store.incidentReportWithNumber(
fieldReport = await self.config.store.fieldReportWithNumber(

Check warning on line 861 in src/ims/application/_api.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_api.py#L861

Added line #L861 was not covered by tests
event_id, fieldReportNumber
)

await self.config.authProvider.authorizeRequestForIncidentReport(
await self.config.authProvider.authorizeRequestForFieldReport(

Check warning on line 865 in src/ims/application/_api.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_api.py#L865

Added line #L865 was not covered by tests
request, fieldReport
)

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

if action == "attach":
await store.attachIncidentReportToIncident(
await store.attachFieldReportToIncident(

Check warning on line 912 in src/ims/application/_api.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_api.py#L912

Added line #L912 was not covered by tests
fieldReportNumber, event_id, incidentNumber, author
)
elif action == "detach":
await store.detachIncidentReportFromIncident(
await store.detachFieldReportFromIncident(

Check warning on line 916 in src/ims/application/_api.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_api.py#L916

Added line #L916 was not covered by tests
fieldReportNumber, event_id, incidentNumber, author
)
else:
Expand Down Expand Up @@ -967,7 +967,7 @@
await applyEdit(
edits,
IncidentReportJSONKey.summary,
store.setIncidentReport_summary,
store.setFieldReport_summary,
)

jsonEntries = edits.get(IncidentReportJSONKey.reportEntries.value, UNSET)
Expand All @@ -984,7 +984,7 @@
for jsonEntry in jsonEntries
)

await store.addReportEntriesToIncidentReport(
await store.addReportEntriesToFieldReport(

Check warning on line 987 in src/ims/application/_api.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_api.py#L987

Added line #L987 was not covered by tests
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

Check warning on line 46 in src/ims/application/_web.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_web.py#L46

Added line #L46 was not covered by tests

from ._klein import Router, notFoundResponse, redirect

Expand Down Expand Up @@ -243,37 +243,37 @@
"""
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

Check warning on line 252 in src/ims/application/_web.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_web.py#L252

Added line #L252 was not covered by tests
del number
else:
try:
incidentReportNumber = int(number)
fieldReportNumber = int(number)

Check warning on line 256 in src/ims/application/_web.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_web.py#L256

Added line #L256 was not covered by tests
except ValueError:
return notFoundResponse(request)
del number

try:
incidentReport = await config.store.incidentReportWithNumber(
event_id, incidentReportNumber
fieldReport = await config.store.fieldReportWithNumber(

Check warning on line 262 in src/ims/application/_web.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_web.py#L262

Added line #L262 was not covered by tests
event_id, fieldReportNumber
)
except NoSuchIncidentReportError:
except NoSuchFieldReportError:

Check warning on line 265 in src/ims/application/_web.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_web.py#L265

Added line #L265 was not covered by tests
await config.authProvider.authorizeRequest(
request, event_id, Authorization.readIncidents
)
return notFoundResponse(request)

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

Check warning on line 271 in src/ims/application/_web.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_web.py#L271

Added line #L271 was not covered by tests
request, fieldReport
)

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

Check warning on line 276 in src/ims/application/_web.py

View check run for this annotation

Codecov / codecov/patch

src/ims/application/_web.py#L276

Added line #L276 was not covered by tests

@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
Loading