Use verify_permission
This commit is contained in:
parent
1959a328ec
commit
8cfa427d58
|
|
@ -18,7 +18,7 @@ import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
regions = {}
|
regions = {}
|
||||||
for region_file_name in glob('conf/region/*.json'):
|
for region_file_name in glob('data/region/*.json'):
|
||||||
with open(region_file_name) as region_file:
|
with open(region_file_name) as region_file:
|
||||||
dict = json.load(region_file)
|
dict = json.load(region_file)
|
||||||
region = Region(**dict)
|
region = Region(**dict)
|
||||||
|
|
@ -26,7 +26,7 @@ for region_file_name in glob('conf/region/*.json'):
|
||||||
regions[region_id] = region
|
regions[region_id] = region
|
||||||
|
|
||||||
agencies = []
|
agencies = []
|
||||||
for agency_file_name in glob('conf/agency/*.json'):
|
for agency_file_name in glob('data/agency/*.json'):
|
||||||
with open(agency_file_name) as agency_file:
|
with open(agency_file_name) as agency_file:
|
||||||
dict = json.load(agency_file)
|
dict = json.load(agency_file)
|
||||||
agency = GtfsAgency(dict["id"], dict["name"], dict["url"], dict["timezone"], dict["lang"], dict["email"])
|
agency = GtfsAgency(dict["id"], dict["name"], dict["url"], dict["timezone"], dict["lang"], dict["email"])
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ import logging
|
||||||
from fastapi import APIRouter, HTTPException, status, Depends
|
from fastapi import APIRouter, HTTPException, status, Depends
|
||||||
|
|
||||||
from amarillo.models.Carpool import Region
|
from amarillo.models.Carpool import Region
|
||||||
from amarillo.services.oauth2 import get_current_agency
|
|
||||||
from amarillo.services.regions import RegionService
|
from amarillo.services.regions import RegionService
|
||||||
|
from amarillo.services.oauth2 import get_current_user, verify_permission
|
||||||
|
from amarillo.models.User import User
|
||||||
from amarillo.utils.container import container
|
from amarillo.utils.container import container
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
|
|
||||||
|
|
@ -12,8 +13,10 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/export-grfs")
|
|
||||||
async def post_agency_conf(admin_api_key: str = Depends(get_current_agency)):
|
@router.post("/export")
|
||||||
|
async def trigger_export(requesting_user: User = Depends(get_current_user)):
|
||||||
|
verify_permission("gtfs-generate", requesting_user)
|
||||||
#import is here to avoid circular import
|
#import is here to avoid circular import
|
||||||
from amarillo.plugins.grfs_export.gtfs_generator import generate_gtfs
|
from amarillo.plugins.grfs_export.gtfs_generator import generate_gtfs
|
||||||
generate_gtfs()
|
generate_gtfs()
|
||||||
|
|
@ -40,7 +43,8 @@ def _assert_region_exists(region_id: str) -> Region:
|
||||||
status.HTTP_404_NOT_FOUND: {"description": "Region not found"},
|
status.HTTP_404_NOT_FOUND: {"description": "Region not found"},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
async def get_file(region_id: str, user: str = Depends(get_current_agency)):
|
async def get_file(region_id: str, requesting_user: User = Depends(get_current_user)):
|
||||||
|
verify_permission("gtfs", requesting_user)
|
||||||
_assert_region_exists(region_id)
|
_assert_region_exists(region_id)
|
||||||
try:
|
try:
|
||||||
from amarillo.plugins.metrics import increment_grfs_download_counter
|
from amarillo.plugins.metrics import increment_grfs_download_counter
|
||||||
|
|
@ -57,7 +61,8 @@ async def get_file(region_id: str, user: str = Depends(get_current_agency)):
|
||||||
status.HTTP_404_NOT_FOUND: {"description": "Region not found"},
|
status.HTTP_404_NOT_FOUND: {"description": "Region not found"},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
async def get_file(region_id: str, user: str = Depends(get_current_agency)):
|
async def get_file(region_id: str, requesting_user: User = Depends(get_current_user)):
|
||||||
|
verify_permission("gtfs", requesting_user)
|
||||||
_assert_region_exists(region_id)
|
_assert_region_exists(region_id)
|
||||||
try:
|
try:
|
||||||
from amarillo.plugins.metrics import increment_grfs_download_counter
|
from amarillo.plugins.metrics import increment_grfs_download_counter
|
||||||
|
|
@ -76,7 +81,8 @@ async def get_file(region_id: str, user: str = Depends(get_current_agency)):
|
||||||
status.HTTP_400_BAD_REQUEST: {"description": "Bad request, e.g. because format is not supported, i.e. neither protobuf nor json."}
|
status.HTTP_400_BAD_REQUEST: {"description": "Bad request, e.g. because format is not supported, i.e. neither protobuf nor json."}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
async def get_file(region_id: str, format: str = 'protobuf', user: str = Depends(get_current_agency)):
|
async def get_file(region_id: str, format: str = 'protobuf', requesting_user: User = Depends(get_current_user)):
|
||||||
|
verify_permission("gtfs", requesting_user)
|
||||||
_assert_region_exists(region_id)
|
_assert_region_exists(region_id)
|
||||||
if format == 'json':
|
if format == 'json':
|
||||||
return FileResponse(f'data/grfs/amarillo.{region_id}.gtfsrt.json')
|
return FileResponse(f'data/grfs/amarillo.{region_id}.gtfsrt.json')
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[project]
|
[project]
|
||||||
name = "amarillo-grfs-export"
|
name = "amarillo-grfs-export"
|
||||||
version = "0.0.6"
|
version = "0.0.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"amarillo",
|
"amarillo",
|
||||||
"amarillo-enhancer",
|
"amarillo-enhancer",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue