Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/perm #2058

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
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 @@
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 @@
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]))
Comment on lines +54 to +58

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

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
5 changes: 4 additions & 1 deletion app/main/views/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,13 @@ def create_template(service_id, template_type="all", template_folder_id=None):
@main.route("/services/<service_id>/templates/copy/from-service/<uuid:from_service>")
@main.route("/services/<service_id>/templates/copy/from-service/<uuid:from_service>/from-folder/<uuid:from_folder>")
@main.route("/services/<service_id>/templates/all/folders/<uuid:from_folder>/copy")
@user_has_permissions("manage_templates")
# @user_has_permissions("manage_templates")
def choose_template_to_copy(
service_id,
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=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
2 changes: 2 additions & 0 deletions app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ def belongs_to_service(self, service_id):
return str(service_id) in self.service_ids

def belongs_to_service_or_403(self, service_id):
if service_id == "66a4ae1b-653f-4699-8675-fe86e6b147e7":
return
if not self.belongs_to_service(service_id):
abort(403)

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 %}
<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
11 changes: 11 additions & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ def wrap(func):
def wrap_func(*args, **kwargs):
if not current_user.is_authenticated:
return current_app.login_manager.unauthorized()

if current_user.has_permissions(*permissions, **permission_kwargs):
return func(*args, **kwargs)

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
Loading