def edit_organisation_crown_status(org_id): form = OrganisationCrownStatusForm( crown_status={ True: 'crown', False: 'non-crown', None: 'unknown', }.get(current_organisation.crown) ) if form.validate_on_submit(): organisations_client.update_organisation( current_organisation.id, crown={ 'crown': True, 'non-crown': False, 'unknown': None, }.get(form.crown_status.data), ) return redirect(url_for('.organisation_settings', org_id=org_id)) return render_template( 'views/organisations/organisation/settings/edit-crown-status.html', form=form, )
def edit_organisation_crown_status(org_id): form = OrganisationCrownStatusForm( crown_status={ True: "crown", False: "non-crown", None: "unknown", }.get(current_organisation.crown) ) if form.validate_on_submit(): organisations_client.update_organisation( current_organisation.id, crown={ "crown": True, "non-crown": False, "unknown": None, }.get(form.crown_status.data), ) return redirect(url_for(".organisation_settings", org_id=org_id)) return render_template( "views/organisations/organisation/settings/edit-crown-status.html", form=form, )
def edit_organisation_agreement(org_id): form = OrganisationAgreementSignedForm( agreement_signed={ True: "yes", False: "no", None: "unknown", }.get(current_organisation.agreement_signed) ) if form.validate_on_submit(): organisations_client.update_organisation( current_organisation.id, agreement_signed={ "yes": True, "no": False, "unknown": None, }.get(form.agreement_signed.data), ) return redirect(url_for(".organisation_settings", org_id=org_id)) return render_template( "views/organisations/organisation/settings/edit-agreement.html", form=form, )
def edit_organisation_domains(org_id): form = OrganisationDomainsForm() if form.validate_on_submit(): try: organisations_client.update_organisation( org_id, domains=list( OrderedDict.fromkeys( domain.lower() for domain in filter(None, form.domains.data))), ) except HTTPError as e: error_message = "Domain already exists" if e.status_code == 400 and error_message in e.message: flash("This domain is already in use", "error") return render_template( 'views/organisations/organisation/settings/edit-domains.html', form=form, ) else: raise e return redirect(url_for('.organisation_settings', org_id=org_id)) form.populate(current_organisation.domains) return render_template( 'views/organisations/organisation/settings/edit-domains.html', form=form, )
def edit_organisation_agreement(org_id): form = OrganisationAgreementSignedForm( agreement_signed={ True: 'yes', False: 'no', None: 'unknown', }.get(current_organisation.agreement_signed) ) if form.validate_on_submit(): organisations_client.update_organisation( current_organisation.id, agreement_signed={ 'yes': True, 'no': False, 'unknown': None, }.get(form.agreement_signed.data), ) return redirect(url_for('.organisation_settings', org_id=org_id)) return render_template( 'views/organisations/organisation/settings/edit-agreement.html', form=form, )
def organisation_preview_email_branding(org_id): branding_style = request.args.get('branding_style', None) form = PreviewBranding(branding_style=branding_style) default_branding_is_french = None if form.branding_style.data == FieldWithLanguageOptions.ENGLISH_OPTION_VALUE: default_branding_is_french = False elif form.branding_style.data == FieldWithLanguageOptions.FRENCH_OPTION_VALUE: default_branding_is_french = True if form.validate_on_submit(): if default_branding_is_french is not None: organisations_client.update_organisation( org_id, email_branding_id=None, default_branding_is_french=default_branding_is_french ) else: organisations_client.update_organisation( org_id, email_branding_id=form.branding_style.data ) return redirect(url_for('.organisation_settings', org_id=org_id)) return render_template( 'views/organisations/organisation/settings/preview-email-branding.html', form=form, action=url_for('main.organisation_preview_email_branding', org_id=org_id), )
def test_update_organisation_when_not_updating_org_type(mocker, fake_uuid): mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete') mock_post = mocker.patch( 'app.notify_client.organisations_api_client.OrganisationsClient.post') organisations_client.update_organisation(fake_uuid, foo='bar') mock_post.assert_called_with(url='/organisations/{}'.format(fake_uuid), data={'foo': 'bar'}) assert mock_redis_delete.call_args_list == [ call('organisations'), call('domains') ]
def test_update_organisation_when_not_updating_org_type(mocker, fake_uuid): mock_redis_delete = mocker.patch("app.extensions.RedisClient.delete") mock_post = mocker.patch( "app.notify_client.organisations_api_client.OrganisationsClient.post") organisations_client.update_organisation(fake_uuid, foo="bar") mock_post.assert_called_with(url="/organisations/{}".format(fake_uuid), data={"foo": "bar"}) assert mock_redis_delete.call_args_list == [ call("organisations"), call("domains") ]
def organisation_preview_letter_branding(org_id): branding_style = request.args.get("branding_style") form = PreviewBranding(branding_style=branding_style) if form.validate_on_submit(): organisations_client.update_organisation(org_id, letter_branding_id=form.branding_style.data) return redirect(url_for(".organisation_settings", org_id=org_id)) return render_template( "views/organisations/organisation/settings/preview-letter-branding.html", form=form, action=url_for("main.organisation_preview_letter_branding", org_id=org_id), )
def test_deletes_domain_cache( app_, mock_get_user, mocker, fake_uuid, ): mocker.patch("app.notify_client.current_user", id="1") mock_redis_delete = mocker.patch("app.extensions.RedisClient.delete") mock_request = mocker.patch( "notifications_python_client.base.BaseAPIClient.request") organisations_client.update_organisation(fake_uuid, foo="bar") assert call("domains") in mock_redis_delete.call_args_list assert len(mock_request.call_args_list) == 1
def test_deletes_domain_cache( app_, mock_get_user, mocker, fake_uuid, ): mocker.patch('app.notify_client.current_user', id='1') mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete') mock_request = mocker.patch( 'notifications_python_client.base.BaseAPIClient.request') organisations_client.update_organisation(fake_uuid, foo='bar') assert call('domains') in mock_redis_delete.call_args_list assert len(mock_request.call_args_list) == 1
def edit_organisation_go_live_notes(org_id): form = GoLiveNotesForm() if form.validate_on_submit(): organisations_client.update_organisation(org_id, request_to_go_live_notes=form.request_to_go_live_notes.data) return redirect(url_for(".organisation_settings", org_id=org_id)) org = organisations_client.get_organisation(org_id) form.request_to_go_live_notes.data = org["request_to_go_live_notes"] return render_template( "views/organisations/organisation/settings/edit-go-live-notes.html", form=form, )
def manage_org(logo=None): form = ServiceManageOrg() org = session.get("organisation") logo = logo if logo else org.get('logo') if org else None if form.validate_on_submit(): if form.file.data: upload_filename = upload_logo( form.file.data.filename, form.file.data, current_app.config['AWS_REGION'], user_id=session["user_id"] ) if logo and logo.startswith(TEMP_TAG.format(user_id=session['user_id'])): delete_temp_file(logo) return redirect( url_for('.manage_org', logo=upload_filename)) if logo: logo = persist_logo(logo, session["user_id"]) delete_temp_files_created_by(session["user_id"]) if org: organisations_client.update_organisation( org_id=org['id'], logo=logo, name=form.name.data, colour=form.colour.data) org_id = org['id'] else: resp = organisations_client.create_organisation( logo=logo, name=form.name.data, colour=form.colour.data) org_id = resp['data']['id'] return redirect(url_for('.organisations', organisation_id=org_id)) if org: form.name.data = org['name'] form.colour.data = org['colour'] return render_template( 'views/organisations/manage-org.html', form=form, organisation=org, cdn_url=get_cdn_domain(), logo=logo )
def edit_organisation_type(org_id): form = OrganisationOrganisationTypeForm( organisation_type=current_organisation['organisation_type'] ) if form.validate_on_submit(): organisations_client.update_organisation( current_organisation['id'], organisation_type=form.organisation_type.data, ) return redirect(url_for('.organisation_settings', org_id=org_id)) return render_template( 'views/organisations/organisation/settings/edit-type.html', form=form, )
def organisation_preview_email_branding(org_id): branding_style = request.args.get('branding_style', None) form = PreviewBranding(branding_style=branding_style) if form.validate_on_submit(): organisations_client.update_organisation( org_id, email_branding_id=form.branding_style.data) return redirect(url_for('.organisation_settings', org_id=org_id)) return render_template( 'views/organisations/organisation/settings/preview-email-branding.html', form=form, action=url_for('main.organisation_preview_email_branding', org_id=org_id), )
def edit_organisation_type(org_id): form = OrganisationOrganisationTypeForm(organisation_type=current_organisation.organisation_type) if form.validate_on_submit(): org_service_ids = [service["id"] for service in current_organisation.services] organisations_client.update_organisation( current_organisation.id, cached_service_ids=org_service_ids, organisation_type=form.organisation_type.data, ) return redirect(url_for(".organisation_settings", org_id=org_id)) return render_template( "views/organisations/organisation/settings/edit-type.html", form=form, )
def test_update_organisation_when_updating_org_type_but_org_has_no_services( mocker, fake_uuid): mock_redis_delete = mocker.patch("app.extensions.RedisClient.delete") mock_post = mocker.patch( "app.notify_client.organisations_api_client.OrganisationsClient.post") organisations_client.update_organisation( fake_uuid, cached_service_ids=[], organisation_type="central", ) mock_post.assert_called_with(url="/organisations/{}".format(fake_uuid), data={"organisation_type": "central"}) assert mock_redis_delete.call_args_list == [ call("organisations"), call("domains"), ]
def test_update_organisation_when_updating_org_type_but_org_has_no_services( mocker, fake_uuid): mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete') mock_post = mocker.patch( 'app.notify_client.organisations_api_client.OrganisationsClient.post') organisations_client.update_organisation( fake_uuid, cached_service_ids=[], organisation_type='central', ) mock_post.assert_called_with(url='/organisations/{}'.format(fake_uuid), data={'organisation_type': 'central'}) assert mock_redis_delete.call_args_list == [ call('organisations'), call('domains'), ]
def edit_organisation_domains(org_id): return redirect(url_for(".organisation_settings", org_id=org_id)) form = OrganisationDomainsForm() if form.validate_on_submit(): organisations_client.update_organisation( org_id, domains=list(OrderedDict.fromkeys(domain.lower() for domain in filter(None, form.domains.data))), ) return redirect(url_for(".organisation_settings", org_id=org_id)) form.populate(current_organisation.domains) return render_template( "views/organisations/organisation/settings/edit-domains.html", form=form, )