Skip to content

Commit

Permalink
Added: UI route for form invitations (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Oct 20, 2024
1 parent 4185c5b commit 9a7981c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
35 changes: 35 additions & 0 deletions libreforms_fastapi/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6947,6 +6947,41 @@ async def ui_form_request_unregistered(form_name:str, request: Request, config =
)


# Added in https://github.com/signebedi/libreforms-fastapi/issues/365
@app.get("/ui/form/invite_submission/{form_name}", response_class=HTMLResponse, include_in_schema=False)
@requires(['authenticated'], status_code=404)
async def ui_form_invite_submission(form_name:str, request: Request, config = Depends(get_config_depends), doc_db = Depends(get_doc_db), session: SessionLocal = Depends(get_db)):
if not config.UI_ENABLED:
raise HTTPException(status_code=404)

if not config.SMTP_ENABLED:
raise HTTPException(status_code=404)

# Since this is an authenticated-only route, we don't worry
# about abuse of expensive processes too much
FormModel = get_form_model(
form_name=form_name,
config_path=config.FORM_CONFIG_PATH,
session=session,
User=User,
Group=Group,
doc_db=doc_db,
)

if not FormModel.invitations_enabled:
raise HTTPException(status_code=404)


return templates.TemplateResponse(
request=request,
name="request_unregistered.html.jinja",
context={
'form_name': form_name,
**build_ui_context(),
}
)



# Create form unregistered user, see https://github.com/signebedi/libreforms-fastapi/issues/357
@app.get("/ui/form/create_unregistered/{form_name}/{api_key}", response_class=HTMLResponse, include_in_schema=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ $(document).ready(function() {
console.log('Request submitted successfully', response);
// Stash a flashed success message and redirect
setFlashMessage("Request submitted successfully, please check your email", "success");
setFlashMessage("Request submitted successfully", "success");
window.location.href = '/ui/home';
},
error: function(xhr) {
Expand Down
8 changes: 4 additions & 4 deletions libreforms_fastapi/utils/jinja_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ def __str__(self):
<html>
<body>
<p>Hello {{ user.username }},</p>
<p>You have requested access to submit a {{form_name}} form at <a href="{{ config.DOMAIN }}">{{ config.DOMAIN }}</a>. If you didn't previously have an account, a new account has been created for you. Please use the following link to submit a {{form_name}} form:</p>
<p>You are invited to submit a {{form_name}} form at <a href="{{ config.DOMAIN }}">{{ config.DOMAIN }}</a>. If you didn't previously have an account, a new account has been created for you. Please use the following link to submit a {{form_name}} form:</p>
<p><a href="{{ config.DOMAIN }}/ui/form/create_unregistered/{{form_name}}/{{api_key}}">{{ config.DOMAIN }}/ui/form/create_unregistered/{{form_name}}/{{api_key}}</a></p>
<p>If you did not submit this request, please contact your system administrator {{ "at " + config.HELP_EMAIL if config.HELP_EMAIL else "" }}.</p>
<p>If you believe this request was submitted by mistake, please contact your system administrator {{ "at " + config.HELP_EMAIL if config.HELP_EMAIL else "" }}.</p>
</body>
</html>
Expand All @@ -196,9 +196,9 @@ def __str__(self):
<html>
<body>
<p>Hello,</p>
<p>You have requested access to submit a {{form_name}} form at <a href="{{ config.DOMAIN }}">{{ config.DOMAIN }}</a>. Please use the following link to submit a {{form_name}} form:</p>
<p>You are invited to submit a {{form_name}} form at <a href="{{ config.DOMAIN }}">{{ config.DOMAIN }}</a>. Please use the following link to submit a {{form_name}} form:</p>
<p><a href="{{ config.DOMAIN }}/ui/form/create_unregistered/{{form_name}}/{{api_key}}">{{ config.DOMAIN }}/ui/form/create_unregistered/{{form_name}}/{{api_key}}</a></p>
<p>This key will expire in 4 hours. If you did not submit this request, please contact your system administrator {{ "at " + config.HELP_EMAIL if config.HELP_EMAIL else "" }}.</p>
<p>This key will expire in 4 hours. If you believe this request was submitted by mistake, please contact your system administrator {{ "at " + config.HELP_EMAIL if config.HELP_EMAIL else "" }}.</p>
</body>
</html>
'''
Expand Down

0 comments on commit 9a7981c

Please sign in to comment.