Skip to content

Commit

Permalink
Merge ce151ae into e35dcc1
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Mar 6, 2020
2 parents e35dcc1 + ce151ae commit 09c3d3d
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 204 deletions.
8 changes: 4 additions & 4 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ return [
'DOCUSIGN_INTEGRATION_KEY' => 'your-personal-integration-key',
'DOCUSIGN_USER_GUID' => 'your-personal-user-guid',
'DOCUSIGN_ACCOUNT_ID' => your-personal-account-id,
'APP_ENV' => 'embedded',
'APP_ENV' => 'test',
'APP_DEBUG' => true,
];
```
Expand All @@ -139,9 +139,9 @@ Then go to http://localhost:8000.

The [WebProfilerBundle](https://symfony.com/web-profiler-bundle) is available at http://localhost:8000/_profiler/.

## List of embedded documents
## List of documents

To access the list of embedded documents, you'll need to login as `admin:4dm1n`: http://localhost:8000/embedded.
To access the list of documents, you'll need to login as `admin:4dm1n` on http://localhost:8000/.

## Running tests

Expand All @@ -159,7 +159,7 @@ Create the `phpunit.xml` file as following:
>
<php>
<ini name="error_reporting" value="-1" />
<env name="APP_ENV" value="embedded" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="true" />
<env name="KERNEL_DIR" value="features/" />
<env name="KERNEL_CLASS" value="Kernel" />
Expand Down
2 changes: 1 addition & 1 deletion features/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DOCUSIGN_INTEGRATION_KEY=c3b2d475-2cbd-47f5-a903-9b3aa0fefe5b
DOCUSIGN_USER_GUID=4003ab5e-c21f-4738-9469-e7d736e10b90
DOCUSIGN_ACCOUNT_ID=1234567
APP_ENV=embedded
APP_ENV=test
APP_DEBUG=true
73 changes: 46 additions & 27 deletions features/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,18 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
'users' => [
'admin' => [
'password' => '4dm1n',
'roles' => 'ROLE_EMBEDDED',
],
'john_doe' => [
'password' => 'j0hnd0E',
'roles' => 'ROLE_USER',
],
],
],
],
],
'role_hierarchy' => [
'ROLE_EMBEDDED' => 'ROLE_USER',
],
'firewalls' => [
'dev' => [
'pattern' => '^/(_(profiler|wdt|error)|css|images|js)/',
'security' => false,
],
'embedded' => [
'test' => [
'pattern' => '^/',
'form_login' => [
'login_path' => 'login',
Expand All @@ -137,33 +130,59 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
],
],
'access_control' => [
['path' => '/embedded', 'roles' => 'ROLE_EMBEDDED'],
['path' => '/embedded', 'roles' => 'IS_AUTHENTICATED_FULLY'],
['path' => '/remote', 'roles' => 'IS_AUTHENTICATED_FULLY'],
['path' => '/', 'roles' => 'IS_AUTHENTICATED_ANONYMOUSLY'],
],
]);

$c->loadFromExtension('docusign', [
'demo' => true,
'mode' => 'embedded',
'auth_jwt' => [
'private_key' => '%kernel.project_dir%/var/jwt/docusign.pem',
'integration_key' => $_SERVER['DOCUSIGN_INTEGRATION_KEY'],
'user_guid' => $_SERVER['DOCUSIGN_USER_GUID'],
'grant_type' => 'authorization_code',
'default' => [
'demo' => true,
'mode' => 'embedded',
'auth_jwt' => [
'private_key' => '%kernel.project_dir%/var/jwt/docusign.pem',
'integration_key' => $_SERVER['DOCUSIGN_INTEGRATION_KEY'],
'user_guid' => $_SERVER['DOCUSIGN_USER_GUID'],
'grant_type' => 'authorization_code',
],
'sign_path' => '/embedded/sign',
'callback' => 'embedded_callback',
'account_id' => (int) $_SERVER['DOCUSIGN_ACCOUNT_ID'],
'default_signer_name' => 'Grégoire Hébert',
'default_signer_email' => 'gregoire@les-tilleuls.coop',
'signatures' => [
[
'page' => 1,
'x_position' => 200,
'y_position' => 400,
],
],
'storage' => 'docusign.storage',
],
'sign_path' => '/docusign/sign',
'callback' => 'embedded_callback',
'account_id' => (int) $_SERVER['DOCUSIGN_ACCOUNT_ID'],
'default_signer_name' => 'Grégoire Hébert',
'default_signer_email' => 'gregoire@les-tilleuls.coop',
'signatures' => [
[
'page' => 1,
'x_position' => 200,
'y_position' => 400,
'remote' => [
'demo' => true,
'mode' => 'remote',
'auth_jwt' => [
'private_key' => '%kernel.project_dir%/var/jwt/docusign.pem',
'integration_key' => $_SERVER['DOCUSIGN_INTEGRATION_KEY'],
'user_guid' => $_SERVER['DOCUSIGN_USER_GUID'],
'grant_type' => 'authorization_code',
],
'sign_path' => '/remote/sign',
'callback' => 'remote_callback',
'account_id' => (int) $_SERVER['DOCUSIGN_ACCOUNT_ID'],
'default_signer_name' => 'Grégoire Hébert',
'default_signer_email' => 'gregoire@les-tilleuls.coop',
'signatures' => [
[
'page' => 1,
'x_position' => 200,
'y_position' => 400,
],
],
'storage' => 'docusign.storage',
],
'storage' => 'docusign.storage',
]);

if (class_exists(FlysystemBundle::class)) {
Expand Down
35 changes: 0 additions & 35 deletions features/TestBundle/Controller/CallbackController.php

This file was deleted.

81 changes: 81 additions & 0 deletions features/TestBundle/Controller/DocumentsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/*
* This file is part of the DocusignBundle.
*
* (c) Grégoire Hébert <gregoire@les-tilleuls.coop>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace DocusignBundle\E2e\TestBundle\Controller;

use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;

/**
* @author Vincent Chalamon <vincentchalamon@gmail.com>
*/
final class DocumentsController
{
private $kernelProjectDir;

public function __construct(string $kernelProjectDir)
{
$this->kernelProjectDir = $kernelProjectDir;
}

/**
* @Route("/embedded", name="embedded", methods={"GET"}, defaults={"mode"="embedded", "route_name"="docusign_sign_default"})
* @Route("/remote", name="remote", methods={"GET"}, defaults={"mode"="remote", "route_name"="docusign_sign_remote"})
*/
public function __invoke(Request $request, Environment $twig): Response
{
return new Response($twig->render('list.html.twig', [
'documents' => $this->getDocuments("$this->kernelProjectDir/var/storage"),
'route_name' => $request->attributes->get('route_name'),
'mode' => $request->attributes->get('mode'),
]));
}

/**
* @Route("/embedded/callback", name="embedded_callback", methods={"GET"})
*/
public function embeddedCallbackAction(RouterInterface $router, Session $session): RedirectResponse
{
$session->getFlashBag()->add('success', 'The document has been successfully signed!');

return new RedirectResponse($router->generate('embedded'));
}

/**
* @Route("/remote/callback", name="remote_callback", methods={"GET"})
*/
public function remoteCallbackAction(RouterInterface $router, Session $session): RedirectResponse
{
$session->getFlashBag()->add('success', 'The document has been successfully sent to the signer!');

return new RedirectResponse($router->generate('remote'));
}

private function getDocuments($path): array
{
$documents = [];
/** @var \SplFileInfo[] $files */
$files = Finder::create()->files()->in($path);
foreach ($files as $file) {
$documents[$file->getFilename()] = substr($file->getRealPath(), \strlen($path));
}

return $documents;
}
}
54 changes: 0 additions & 54 deletions features/TestBundle/Controller/EmbeddedController.php

This file was deleted.

7 changes: 2 additions & 5 deletions features/TestBundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ services:
autowire: true
autoconfigure: true
public: false
bind:
$kernelProjectDir: '%kernel.project_dir%'

DocusignBundle\E2e\TestBundle\:
resource: '../../*'
Expand All @@ -11,8 +13,3 @@ services:
DocusignBundle\E2e\TestBundle\Controller\:
resource: '../../Controller/*'
tags: ['controller.service_arguments']

DocusignBundle\E2e\TestBundle\Controller\EmbeddedController:
tags: ['controller.service_arguments']
arguments:
$kernelProjectDir: '%kernel.project_dir%'
3 changes: 2 additions & 1 deletion features/TestBundle/Resources/views/homepage.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

{% block content %}
<ul>
<li>Click <a href="{{ path('embedded') }}">here</a> to access the embedded documents list (require auth.)</li>
<li><a href="{{ path('embedded') }}">Embedded mode</a></li>
<li><a href="{{ path('remote') }}">Remote mode</a></li>
</ul>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% extends 'base.html.twig' %}

{% block title %}Embedded documents{% endblock %}
{% block title %}Documents list ({{ mode }} mode){% endblock %}

{% block content %}
<ul>
{% for name, path in documents %}
<li><a href="{{ path('docusign_sign_default', {'path': path}) }}">{{ name }}</a></li>
<li><a href="{{ path(route_name, {'path': path}) }}">{{ name }}</a></li>
{% endfor %}
</ul>
{% endblock %}
Expand Down
4 changes: 2 additions & 2 deletions features/TestBundle/Resources/views/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
{% endif %}

<form action="{{ path('login') }}" method="post">
<input placeholder="Username" type="text" id="username" name="_username" value="{{ last_username }}"/>
<input placeholder="Password" type="password" id="password" name="_password"/>
<input placeholder="Username (admin)" type="text" id="username" name="_username" value="{{ last_username }}"/>
<input placeholder="Password (4dm1n)" type="password" id="password" name="_password"/>

<button type="submit">Login</button>
</form>
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
>
<php>
<ini name="error_reporting" value="-1" />
<env name="APP_ENV" value="embedded" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="false" />
<env name="KERNEL_DIR" value="features/" />
<env name="KERNEL_CLASS" value="Kernel" />
Expand Down

0 comments on commit 09c3d3d

Please sign in to comment.