Skip to content

Commit

Permalink
Added: get groups admin api route (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Apr 4, 2024
1 parent fe4cd5a commit 6420ca3
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions libreforms_fastapi/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,53 @@ async def api_admin_get_users(

# Get all groups


@app.get(
"/api/admin/get_groups",
dependencies=[Depends(api_key_auth)],
response_class=JSONResponse,
)
async def api_admin_get_groups(
request: Request,
background_tasks: BackgroundTasks,
session: SessionLocal = Depends(get_db),
key: str = Depends(X_API_KEY)
):

"""
Lists all groups in the system for administrative purposes. Requires site admin permissions.
Logs the action for audit purposes.
"""

# Get the requesting user details
user = session.query(User).filter_by(api_key=key).first()

if not user or not user.site_admin:
raise HTTPException(status_code=404)

groups = [x.to_dict() for x in session.query(Group).all()]

# Write this query to the TransactionLog
if config.COLLECT_USAGE_STATISTICS:

endpoint = request.url.path
remote_addr = request.client.host

background_tasks.add_task(
write_api_call_to_transaction_log,
api_key=key,
endpoint=endpoint,
remote_addr=remote_addr,
query_params={},
)

return JSONResponse(
status_code=200,
content={"status": "success", "groups": groups},
)



# Add new group

# Update group
Expand Down

0 comments on commit 6420ca3

Please sign in to comment.