Skip to content

Commit

Permalink
start
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai committed Jan 16, 2025
1 parent 7e901ed commit dbd5e6e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/main/views/choose_account.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from flask import redirect, render_template, session, url_for
from flask_login import current_user

from app import status_api_client
from app import status_api_client, service_api_client
from app.main import main
from app.models.organisation import Organisations
from app.utils import PermanentRedirect, user_is_logged_in
from app.models.service import Service


@main.route("/services")
Expand All @@ -26,11 +27,14 @@ def choose_account():
len(Organisations()),
status_api_client.get_count_of_live_services_and_organisations()["services"],
)

example_service = Service(service_api_client.get_service(service_id="66a4ae1b-653f-4699-8675-fe86e6b147e7")["data"])
return render_template(
"views/choose-account.html",
can_add_service=current_user.is_gov_user,
org_count=org_count,
live_service_count=live_service_count,
example_service=example_service,
)


Expand All @@ -47,11 +51,11 @@ def show_accounts_or_dashboard():
if organisation_id and (current_user.belongs_to_organisation(organisation_id) or current_user.platform_admin):
return redirect(url_for(".organisation_dashboard", org_id=organisation_id))

if len(current_user.service_ids) == 1 and not current_user.organisation_ids:
return redirect(url_for(".service_dashboard", service_id=current_user.service_ids[0]))
# if len(current_user.service_ids) == 1 and not current_user.organisation_ids:
# return redirect(url_for(".service_dashboard", service_id=current_user.service_ids[0]))

if len(current_user.organisation_ids) == 1 and not current_user.trial_mode_services:
return redirect(url_for(".organisation_dashboard", org_id=current_user.organisation_ids[0]))
# if len(current_user.organisation_ids) == 1 and not current_user.trial_mode_services:
# return redirect(url_for(".organisation_dashboard", org_id=current_user.organisation_ids[0]))

if len(current_user.service_ids) == 0 and not current_user.organisation_ids and not current_user.platform_admin:
return redirect(url_for("main.welcome"))
Expand Down
3 changes: 3 additions & 0 deletions app/main/views/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ def choose_template_to_copy(
from_service=None,
from_folder=None,
):
example_service = Service(service_api_client.get_service(service_id="66a4ae1b-653f-4699-8675-fe86e6b147e7")["data"])
if from_folder and from_service is None:
from_service = service_id

Expand All @@ -584,13 +585,15 @@ def choose_template_to_copy(
template_folder_path=service.get_template_folder_path(from_folder),
from_service=service,
search_form=SearchByNameForm(),
example_service_templates=TemplateList(example_service),
)

else:
return render_template(
"views/templates/copy.html",
services_templates_and_folders=TemplateLists(current_user),
search_form=SearchByNameForm(),
example_service=TemplateList(example_service),
)


Expand Down
6 changes: 6 additions & 0 deletions app/templates/views/choose-account.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ <h2>
</div>
<div class="keyline-block"></div>
{% endif %}
{% set heading_txt = _('Example service') %}
{{ service_list(
heading=heading_txt,
show_heading=(current_user.organisations or current_user.live_services),
services=[example_service]
) }}
{% set heading_txt = _('Live services') %}
{% if current_user.organisations %}
{{ service_list(
Expand Down
32 changes: 32 additions & 0 deletions app/templates/views/templates/copy.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@
<h1 class="heading-large">{{ _('Copy an existing template') }} {{ _("into") }} {{ current_service.name }}</h1>
{{ copy_folder_path(template_folder_path, current_service.id, from_service, current_user) }}
</div>
<h1 class="heading-medium">{{ _('Example Service') }}</h1>
{% for item in example_service_templates %}
<div class="template-list-item {% if item.ancestors %}template-list-item-hidden-by-default{% endif %} {% if not item.ancestors %}template-list-item-without-ancestors{% endif %}">
<h2 class="message-name">
{% for ancestor in item.ancestors %}
{% if ancestor.is_service %}
<a href="{{ url_for('.choose_template_to_copy', service_id=current_service.id, from_service=ancestor.service_id) }}" class="template-list-folder">
{% else %}
<a href="{{ url_for('.choose_template_to_copy', service_id=current_service.id, from_folder=ancestor.id) }}" class="template-list-folder">
{% endif %}
{{ ancestor.name }}
</a> <span class="message-name-separator"></span>
{% endfor %}
{% if item.is_service %}
<a href="{{ url_for('.choose_template_to_copy', service_id=current_service.id, from_service=item.service_id) }}" class="template-list-folder">
<span class="live-search-relevant">{{ item.name }}</span>
</a>
{% elif item.is_folder %}
<a href="{{ url_for('.choose_template_to_copy', service_id=current_service.id, from_service=item.service_id, from_folder=item.id) }}" class="template-list-folder">
<span class="live-search-relevant">{{ item.name }}</span>
</a>
{% else %}
<a href="{{ url_for('.copy_template', service_id=current_service.id, template_id=item.id, from_service=item.service_id) }}">
{{ _("Copy") }} <span class="live-search-relevant">{{ item.name }}</span> <span class="sr-only">{{ _("into") }} {{ current_service.name }}</span>
</a>
{% endif %}
</h2>
<p class="message-type">
{{ _("{} template").format(_(item.hint)) | capitalize if item.type else _(item.hint) }}
</p>
</div>
{% endfor %}
{% if not services_templates_and_folders.templates_to_show %}
<p class="template-list-empty">
{{ _('This folder is empty') }}
Expand Down
8 changes: 8 additions & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ def wrap(func):
def wrap_func(*args, **kwargs):
if not current_user.is_authenticated:
return current_app.login_manager.unauthorized()

service_id = kwargs.get("service_id") or request.view_args.get("service_id")
if service_id == "66a4ae1b-653f-4699-8675-fe86e6b147e7":
if request.method in ["GET", "HEAD", "OPTIONS"]:
return func(*args, **kwargs)
else:
abort(403)

if not current_user.has_permissions(*permissions, **permission_kwargs):
abort(403)
return func(*args, **kwargs)
Expand Down

0 comments on commit dbd5e6e

Please sign in to comment.