def archive_service(service_id):
    if request.method == 'POST':
        service_api_client.archive_service(service_id)
        return redirect(url_for('.service_settings', service_id=service_id))
    else:
        flash('There\'s no way to reverse this! Are you sure you want to archive this service?', 'delete')
        return service_settings(service_id)
def test_deletes_cached_users_when_archiving_service(mocker):
    mock_redis_delete = mocker.patch('app.notify_client.service_api_client.redis_client.delete')
    mocker.patch('notifications_python_client.base.BaseAPIClient.request')

    service_api_client.archive_service(SERVICE_ONE_ID, ["my-user-id1", "my-user-id2"])

    assert call('user-my-user-id1', 'user-my-user-id2') in mock_redis_delete.call_args_list
def test_deletes_cached_users_when_archiving_service(mocker, mock_get_service_templates):
    mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete')
    mock_redis_delete_by_pattern = mocker.patch('app.extensions.RedisClient.delete_cache_keys_by_pattern')

    mocker.patch('notifications_python_client.base.BaseAPIClient.request', return_value={'data': ""})

    service_api_client.archive_service(SERVICE_ONE_ID, ["my-user-id1", "my-user-id2"])

    assert call('user-my-user-id1', 'user-my-user-id2') in mock_redis_delete.call_args_list
    assert call(f'service-{SERVICE_ONE_ID}-template-*') in mock_redis_delete_by_pattern.call_args_list
示例#4
0
def archive_service(service_id):
    if not current_service.active and (current_service.trial_mode
                                       or current_user.platform_admin):
        abort(403)
    if request.method == 'POST':
        service_api_client.archive_service(service_id)
        flash(
            '‘{}’ was deleted'.format(current_service.name),
            'default_with_tick',
        )
        return redirect(url_for('.choose_account'))
    else:
        flash(
            'Are you sure you want to delete ‘{}’? There’s no way to undo this.'
            .format(current_service.name),
            'delete',
        )
        return service_settings(service_id)
示例#5
0
def archive_service(service_id):
    if not current_service.active and (current_service.trial_mode
                                       or current_user.platform_admin):
        abort(403)
    if request.method == 'POST':
        service_api_client.archive_service(service_id)
        session.pop('service_id', None)
        flash(
            _("‘%(service_name)s’ was deleted",
              service_name=current_service.name),
            'default_with_tick',
        )
        return redirect(url_for('.choose_account'))
    else:
        flash(
            '{} ‘{}’? {}'.format(_("Are you sure you want to delete"),
                                 current_service.name,
                                 _("There’s no way to undo this.")),
            'delete',
        )
        return service_settings(service_id)
示例#6
0
def archive_service(service_id):
    if not current_service.active and (
        current_service.trial_mode or current_user.platform_admin
    ):
        abort(403)
    if request.method == 'POST':
        # We need to purge the cache for the services users as otherwise, although they will have had their permissions
        # removed in the DB, they would still have permissions in the cache to view/edit/manage this service
        cached_service_user_ids = [user.id for user in current_service.active_users]

        service_api_client.archive_service(service_id, cached_service_user_ids)
        flash(
            '‘{}’ was deleted'.format(current_service.name),
            'default_with_tick',
        )
        return redirect(url_for('.choose_account'))
    else:
        flash(
            'Are you sure you want to delete ‘{}’? There’s no way to undo this.'.format(current_service.name),
            'delete',
        )
        return service_settings(service_id)