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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ cli/logs
# deployment files
app.yaml
docs/

#Codex
.codex
2 changes: 1 addition & 1 deletion admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
Starlette Admin package for NMSampleLocations.
Starlette Admin package for OcotilloAPI.

Provides web-based administrative interface for managing database records.
"""
Expand Down
18 changes: 7 additions & 11 deletions admin/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,22 @@
Admin authentication provider integrating with existing Authentik OIDC auth.

This module provides a Starlette Admin AuthProvider that integrates with the
existing Authentik-based authentication system used by the NMSampleLocations API.
existing Authentik-based authentication system used by the OcotilloAPI API.
"""

import base64
import hashlib
import os
import secrets
from typing import Optional
from urllib.parse import urlencode

import hashlib
import base64

from core.permissions import _get_token_payload, verify_token
from dataclasses import dataclass
from typing import List

from starlette.requests import Request
from starlette.responses import RedirectResponse
from starlette_admin.auth import AdminUser, AuthProvider
from starlette_admin.exceptions import LoginFailed

from core.permissions import _get_token_payload, verify_token
from typing import List
from typing import Optional
from urllib.parse import urlencode


@dataclass
Expand Down
5 changes: 2 additions & 3 deletions admin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
"""
Starlette Admin configuration and initialization.

This module creates and configures the admin interface for NMSampleLocations.
This module creates and configures the admin interface for OcotilloAPI.
"""

from starlette_admin.contrib.sqla import Admin

from admin.auth import NMSampleLocationsAuthProvider
from admin.views import (
AquiferSystemAdmin,
Expand Down Expand Up @@ -93,6 +91,7 @@
from db.sensor import Sensor
from db.thing import Thing
from db.transducer import TransducerObservation
from starlette_admin.contrib.sqla import Admin


def create_admin(app):
Expand Down
8 changes: 4 additions & 4 deletions admin/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
# limitations under the License.
# ===============================================================================
"""
Admin views package for NMSampleLocations.
Admin views package for OcotilloAPI.

Provides MS Access-like interface for CRUD operations on database models.
"""

from admin.views.asset import AssetAdmin
from admin.views.associated_data import AssociatedDataAdmin
from admin.views.aquifer_system import AquiferSystemAdmin
from admin.views.aquifer_type import AquiferTypeAdmin
from admin.views.asset import AssetAdmin
from admin.views.associated_data import AssociatedDataAdmin
from admin.views.chemistry_sampleinfo import ChemistrySampleInfoAdmin
from admin.views.contact import ContactAdmin
from admin.views.data_provenance import DataProvenanceAdmin
Expand Down Expand Up @@ -55,8 +55,8 @@
from admin.views.waterlevelscontinuous_pressure_daily import (
WaterLevelsContinuousPressureDailyAdmin,
)
from admin.views.weather_photos import WeatherPhotosAdmin
from admin.views.weather_data import WeatherDataAdmin
from admin.views.weather_photos import WeatherPhotosAdmin

__all__ = [
"AssetAdmin",
Expand Down
2 changes: 1 addition & 1 deletion admin/views/aquifer_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
AquiferSystemAdmin view for NMSampleLocations.
AquiferSystemAdmin view for OcotilloAPI.
"""

from admin.fields import WKTField
Expand Down
2 changes: 1 addition & 1 deletion admin/views/aquifer_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
AquiferTypeAdmin view for NMSampleLocations.
AquiferTypeAdmin view for OcotilloAPI.
"""

from admin.views.base import OcotilloModelView
Expand Down
2 changes: 1 addition & 1 deletion admin/views/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
AssetAdmin view for NMSampleLocations.
AssetAdmin view for OcotilloAPI.

Provides MS Access-like interface for CRUD operations on Asset model.
"""
Expand Down
2 changes: 1 addition & 1 deletion admin/views/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
ContactAdmin view for NMSampleLocations.
ContactAdmin view for OcotilloAPI.

Provides MS Access-like interface for CRUD operations on Contact (Owners) model.
"""
Expand Down
2 changes: 1 addition & 1 deletion admin/views/data_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
DataProvenanceAdmin view for NMSampleLocations.
DataProvenanceAdmin view for OcotilloAPI.
"""

from admin.views.base import OcotilloModelView
Expand Down
2 changes: 1 addition & 1 deletion admin/views/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
DeploymentAdmin view for NMSampleLocations.
DeploymentAdmin view for OcotilloAPI.

Provides MS Access-like interface for CRUD operations on Deployment model.
"""
Expand Down
2 changes: 1 addition & 1 deletion admin/views/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
Field admin views for NMSampleLocations.
Field admin views for OcotilloAPI.
"""

from admin.views.base import OcotilloModelView
Expand Down
2 changes: 1 addition & 1 deletion admin/views/geologic_formation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
GeologicFormationAdmin view for NMSampleLocations.
GeologicFormationAdmin view for OcotilloAPI.
"""

from admin.fields import WKTField
Expand Down
2 changes: 1 addition & 1 deletion admin/views/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
GroupAdmin view for NMSampleLocations.
GroupAdmin view for OcotilloAPI.
"""

from admin.fields import WKTField
Expand Down
2 changes: 1 addition & 1 deletion admin/views/lexicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
Lexicon admin views for NMSampleLocations.
Lexicon admin views for OcotilloAPI.
"""

from admin.views.base import OcotilloModelView
Expand Down
2 changes: 1 addition & 1 deletion admin/views/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
LocationAdmin view for NMSampleLocations.
LocationAdmin view for OcotilloAPI.

Provides MS Access-like interface for CRUD operations on Location model.
"""
Expand Down
2 changes: 1 addition & 1 deletion admin/views/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
NotesAdmin view for NMSampleLocations.
NotesAdmin view for OcotilloAPI.
"""

from admin.views.base import OcotilloModelView
Expand Down
2 changes: 1 addition & 1 deletion admin/views/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
ObservationAdmin view for NMSampleLocations.
ObservationAdmin view for OcotilloAPI.

Provides MS Access-like interface for CRUD operations on Observation (Water Levels) model.
"""
Expand Down
2 changes: 1 addition & 1 deletion admin/views/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
ParameterAdmin view for NMSampleLocations.
ParameterAdmin view for OcotilloAPI.
"""

from admin.views.base import OcotilloModelView
Expand Down
2 changes: 1 addition & 1 deletion admin/views/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
SampleAdmin view for NMSampleLocations.
SampleAdmin view for OcotilloAPI.
"""

from admin.views.base import OcotilloModelView
Expand Down
2 changes: 1 addition & 1 deletion admin/views/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
SensorAdmin view for NMSampleLocations.
SensorAdmin view for OcotilloAPI.

Provides MS Access-like interface for CRUD operations on Sensor (Equipment) model.
"""
Expand Down
2 changes: 1 addition & 1 deletion admin/views/surface_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
SurfaceWaterDataAdmin view for NMSampleLocations.
SurfaceWaterDataAdmin view for OcotilloAPI.
"""

from admin.views.base import OcotilloModelView
Expand Down
2 changes: 1 addition & 1 deletion admin/views/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ===============================================================================
"""
ThingAdmin view for NMSampleLocations.
ThingAdmin view for OcotilloAPI.

Provides MS Access-like interface for CRUD operations on Thing (Wells/Springs) model.
"""
Expand Down
2 changes: 2 additions & 0 deletions api/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def get_well_details(
thing_id: int,
session: session_dependency,
request: Request,
field_event_limit: int = Query(default=25, ge=1, le=100),
) -> WellDetailsResponse:
"""
Retrieve the consolidated payload needed to render the well details page.
Expand All @@ -206,6 +207,7 @@ def get_well_details(
session=session,
request=request,
thing_id=thing_id,
field_event_limit=field_event_limit,
)


Expand Down
4 changes: 2 additions & 2 deletions features/admin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Documents Location admin CRUD operations and business rules:
### Run Tests

```bash
# From NMSampleLocations directory
cd /path/to/NMSampleLocations
# From OcotilloAPI directory
cd /path/to/OcotilloAPI

# Run all admin feature tests
behave features/admin/
Expand Down
15 changes: 9 additions & 6 deletions schemas/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,8 @@ class ThingResponse(WellResponse, SpringResponse):
measuring_point_height: float | None


class WellScreenResponse(BaseResponseModel):
"""
Response schema for well screen details.
"""

class WellScreenBaseResponse(BaseResponseModel):
thing_id: int
thing: WellResponse
aquifer_system_id: int | None = None
aquifer_system: str | None = None
aquifer_type: str | None = None
Expand Down Expand Up @@ -387,6 +382,14 @@ def populate_geologic_formation_with_code(cls, geologic_formation):
return None


class WellScreenResponse(WellScreenBaseResponse):
"""
Response schema for well screen details.
"""

thing: WellResponse


class GeoJSONGeometry(BaseModel):
"""
Geometry schema for GeoJSON response.
Expand Down
49 changes: 38 additions & 11 deletions schemas/well_details.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
from pydantic import BaseModel, ConfigDict, Field

from core.enums import ActivityType, SampleMatrix, SampleMethod, SampleQcType
from schemas import BaseResponseModel, UTCAwareDatetime
from schemas.contact import ContactResponse
from schemas.deployment import DeploymentResponse
from schemas.observation import GroundwaterLevelObservationResponse
from schemas.sample import SampleResponse
from schemas.field import FieldEventParticipantResponse
from schemas.observation import ObservationResponse
from schemas.sensor import SensorResponse
from schemas.thing import WellResponse, WellScreenResponse
from schemas.thing import WellResponse, WellScreenBaseResponse


class WellDetailsFieldEventSampleResponse(BaseResponseModel):
contact: ContactResponse | None = None
sample_date: UTCAwareDatetime
sample_name: str
sample_matrix: SampleMatrix
sample_method: SampleMethod
qc_type: SampleQcType
notes: str | None = None
depth_top: float | None = None
depth_bottom: float | None = None
observations: list[ObservationResponse] = Field(default_factory=list)


class WellDetailsFieldActivityResponse(BaseResponseModel):
field_event_id: int
activity_type: ActivityType
notes: str | None = None
Comment thread
jirhiker marked this conversation as resolved.
samples: list[WellDetailsFieldEventSampleResponse] = Field(default_factory=list)


class WellDetailsFieldEventResponse(BaseResponseModel):
thing_id: int
event_date: UTCAwareDatetime
notes: str | None = None
field_event_participants: list[FieldEventParticipantResponse] = Field(
default_factory=list
)
field_activities: list[WellDetailsFieldActivityResponse] = Field(
default_factory=list
)


class WellDetailsResponse(BaseModel):
Expand All @@ -16,11 +49,5 @@ class WellDetailsResponse(BaseModel):
contacts: list[ContactResponse] = Field(default_factory=list)
sensors: list[SensorResponse] = Field(default_factory=list)
deployments: list[DeploymentResponse] = Field(default_factory=list)
well_screens: list[WellScreenResponse] = Field(default_factory=list)
recent_groundwater_level_observations: list[GroundwaterLevelObservationResponse] = (
Field(default_factory=list)
)
latest_field_event_sample: SampleResponse | None = None
field_event_participants: list[FieldEventParticipantResponse] = Field(
default_factory=list
)
well_screens: list[WellScreenBaseResponse] = Field(default_factory=list)
field_events: list[WellDetailsFieldEventResponse] = Field(default_factory=list)
Loading
Loading