mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-05 14:11:41 -04:00
Merge pull request #1934 from alphagov/update-service-name
Update Organisation Name
This commit is contained in:
@@ -329,6 +329,14 @@ class RenameServiceForm(StripWhitespaceForm):
|
||||
])
|
||||
|
||||
|
||||
class RenameOrganisationForm(StripWhitespaceForm):
|
||||
name = StringField(
|
||||
u'Organisation name',
|
||||
validators=[
|
||||
DataRequired(message='Can’t be empty')
|
||||
])
|
||||
|
||||
|
||||
class CreateServiceForm(StripWhitespaceForm):
|
||||
name = StringField(
|
||||
u'What’s your service called?',
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
from flask import flash, redirect, render_template, request, url_for
|
||||
from flask import flash, redirect, render_template, request, session, url_for
|
||||
from flask_login import current_user, login_required
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from werkzeug.exceptions import abort
|
||||
|
||||
from app import org_invite_api_client, organisations_client, user_api_client
|
||||
from app import (
|
||||
current_organisation,
|
||||
org_invite_api_client,
|
||||
organisations_client,
|
||||
user_api_client,
|
||||
)
|
||||
from app.main import main
|
||||
from app.main.forms import (
|
||||
ConfirmPasswordForm,
|
||||
CreateOrUpdateOrganisation,
|
||||
InviteOrgUserForm,
|
||||
RenameOrganisationForm,
|
||||
SearchUsersForm,
|
||||
)
|
||||
from app.utils import user_is_platform_admin
|
||||
@@ -56,31 +63,6 @@ def organisation_dashboard(org_id):
|
||||
)
|
||||
|
||||
|
||||
@main.route("/organisations/<org_id>/edit", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def update_organisation(org_id):
|
||||
org = organisations_client.get_organisation(org_id)
|
||||
|
||||
form = CreateOrUpdateOrganisation()
|
||||
|
||||
if form.validate_on_submit():
|
||||
organisations_client.update_organisation(
|
||||
org_id=org_id,
|
||||
name=form.name.data
|
||||
)
|
||||
|
||||
return redirect(url_for('.organisations'))
|
||||
|
||||
form.name.data = org['name']
|
||||
|
||||
return render_template(
|
||||
'views/organisations/organisation/update-organisation.html',
|
||||
form=form,
|
||||
organisation=org
|
||||
)
|
||||
|
||||
|
||||
@main.route("/organisations/<org_id>/users", methods=['GET'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
@@ -174,3 +156,68 @@ def cancel_invited_org_user(org_id, invited_user_id):
|
||||
org_invite_api_client.cancel_invited_user(org_id=org_id, invited_user_id=invited_user_id)
|
||||
|
||||
return redirect(url_for('main.manage_org_users', org_id=org_id))
|
||||
|
||||
|
||||
@main.route("/organisations/<org_id>/settings/", methods=['GET'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def organisation_settings(org_id):
|
||||
return render_template(
|
||||
'views/organisations/organisation/settings/index.html',
|
||||
)
|
||||
|
||||
|
||||
@main.route("/organisations/<org_id>/settings/edit-name", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def edit_organisation_name(org_id):
|
||||
form = RenameOrganisationForm()
|
||||
|
||||
if request.method == 'GET':
|
||||
form.name.data = current_organisation.get('name')
|
||||
|
||||
if form.validate_on_submit():
|
||||
unique_name = organisations_client.is_organisation_name_unique(org_id, form.name.data)
|
||||
if not unique_name:
|
||||
form.name.errors.append("This organisation name is already in use")
|
||||
return render_template('views/organisations/organisation/settings/edit-name/index.html', form=form)
|
||||
session['organisation_name_change'] = form.name.data
|
||||
return redirect(url_for('.confirm_edit_organisation_name', org_id=org_id))
|
||||
|
||||
return render_template(
|
||||
'views/organisations/organisation/settings/edit-name/index.html',
|
||||
form=form,
|
||||
)
|
||||
|
||||
|
||||
@main.route("/organisations/<org_id>/settings/edit-name/confirm", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def confirm_edit_organisation_name(org_id):
|
||||
# Validate password for form
|
||||
def _check_password(pwd):
|
||||
return user_api_client.verify_password(current_user.id, pwd)
|
||||
|
||||
form = ConfirmPasswordForm(_check_password)
|
||||
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
organisations_client.update_organisation_name(
|
||||
current_organisation['id'],
|
||||
name=session['organisation_name_change'],
|
||||
)
|
||||
except HTTPError as e:
|
||||
error_msg = "Organisation name already exists"
|
||||
if e.status_code == 400 and error_msg in e.message:
|
||||
# Redirect the user back to the change service name screen
|
||||
flash('This organisation name is already in use', 'error')
|
||||
return redirect(url_for('main.edit_organisation_name', org_id=org_id))
|
||||
else:
|
||||
raise e
|
||||
else:
|
||||
session.pop('organisation_name_change')
|
||||
return redirect(url_for('.organisation_settings', org_id=org_id))
|
||||
return render_template(
|
||||
'views/organisations/organisation/settings/edit-name/confirm.html',
|
||||
new_name=session['organisation_name_change'],
|
||||
form=form)
|
||||
|
||||
@@ -18,7 +18,7 @@ class OrganisationsClient(NotifyAdminAPIClient):
|
||||
}
|
||||
return self.post(url="/organisations", data=data)
|
||||
|
||||
def update_organisation(self, org_id, name):
|
||||
def update_organisation_name(self, org_id, name):
|
||||
data = {
|
||||
"name": name
|
||||
}
|
||||
@@ -45,3 +45,9 @@ class OrganisationsClient(NotifyAdminAPIClient):
|
||||
user_id=user_id)
|
||||
data = _attach_current_user({})
|
||||
return self.delete(endpoint, data)
|
||||
|
||||
def is_organisation_name_unique(self, org_id, name):
|
||||
return self.get(
|
||||
url="/organisations/unique",
|
||||
params={"org_id": org_id, "name": name}
|
||||
)["result"]
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
<ul>
|
||||
<li><a href="{{ url_for('.organisation_dashboard', org_id=current_org.id) }}">Dashboard</a></li>
|
||||
<li><a href="{{ url_for('.manage_org_users', org_id=current_org.id) }}">Team members</a></li>
|
||||
<li><a href="{{ url_for('.organisation_settings', org_id=current_org.id) }}">Settings</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
{% extends "org_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
|
||||
{% block org_page_title %}
|
||||
Confirm organisation name change
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
<h1 class="heading-large">Confirm organisation name change</h1>
|
||||
|
||||
<div class="grid-row">
|
||||
<div class="column-three-quarters">
|
||||
|
||||
<form autocomplete="off" method="post">
|
||||
{{ textbox(form.password) }}
|
||||
<p> Your organisation name will be changed from {{ current_org.name }} to {{ new_name }} </p>
|
||||
{{ page_footer(
|
||||
'Confirm',
|
||||
destructive=destructive,
|
||||
back_link=url_for('.organisation_settings', org_id=current_org.id)
|
||||
) }}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,21 @@
|
||||
{% extends "org_template.html" %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
{% from "components/textbox.html" import textbox, colour_textbox %}
|
||||
|
||||
{% block org_page_title %}
|
||||
Change organisation name
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
<h1 class="heading-large">Change organisation name</h1>
|
||||
<form method="post">
|
||||
{{textbox(form.name)}}
|
||||
{{ page_footer(
|
||||
'Save',
|
||||
back_link=url_for('.organisation_settings', org_id=current_org.id),
|
||||
back_link_text='Back to settings',
|
||||
) }}
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,27 @@
|
||||
{% extends "org_template.html" %}
|
||||
{% from "components/table.html" import mapping_table, row, text_field, edit_field with context %}
|
||||
|
||||
{% block org_page_title %}
|
||||
Organisation settings
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
<h1 class="heading-large">Organisation settings</h1>
|
||||
<div class="bottom-gutter-3-2 dashboard-table body-copy-table">
|
||||
{% call mapping_table(
|
||||
caption='General',
|
||||
field_headings=['Label', 'Value', 'Action'],
|
||||
field_headings_visible=False,
|
||||
caption_visible=False
|
||||
) %}
|
||||
{% call row() %}
|
||||
{{ text_field('Organisation name') }}
|
||||
{{ text_field(current_org.name) }}
|
||||
{{ edit_field(
|
||||
'Change',
|
||||
url_for('.edit_organisation_name', org_id=current_org.id)
|
||||
)
|
||||
}}
|
||||
{% endcall %}
|
||||
{% endcall %}
|
||||
{% endblock %}
|
||||
@@ -1,25 +0,0 @@
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
{% from "components/textbox.html" import textbox, colour_textbox %}
|
||||
|
||||
{% block per_page_title %}
|
||||
Update an organisation
|
||||
{% endblock %}
|
||||
|
||||
{% block org_page_title %}
|
||||
Update an organisation
|
||||
{% endblock %}
|
||||
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<h1 class="heading-large">Update an organisation</h1>
|
||||
<form method="post">
|
||||
{{textbox(form.name)}}
|
||||
{{ page_footer(
|
||||
'Save',
|
||||
back_link=url_for('.organisations'),
|
||||
back_link_text='Back to organisations',
|
||||
) }}
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user