mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Merge pull request #206 from dothiv/master
Show authorized roles in key icon tooltip
This commit is contained in:
commit
87328e27f5
@ -115,6 +115,11 @@ class ApiDoc
|
||||
*/
|
||||
private $authentication = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $authenticationRoles = array();
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
@ -200,6 +205,12 @@ class ApiDoc
|
||||
$this->setAuthentication((bool) $data['authentication']);
|
||||
}
|
||||
|
||||
if (isset($data['authenticationRoles'])) {
|
||||
foreach ($data['authenticationRoles'] as $key => $role) {
|
||||
$this->authenticationRoles[] = $role;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['cache'])) {
|
||||
$this->setCache($data['cache']);
|
||||
}
|
||||
@ -436,6 +447,22 @@ class ApiDoc
|
||||
$this->authentication = $authentication;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAuthenticationRoles()
|
||||
{
|
||||
return $this->authenticationRoles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $authenticationRoles
|
||||
*/
|
||||
public function setAuthenticationRoles($authenticationRoles)
|
||||
{
|
||||
$this->authenticationRoles = $authenticationRoles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
@ -542,6 +569,7 @@ class ApiDoc
|
||||
|
||||
$data['https'] = $this->https;
|
||||
$data['authentication'] = $this->authentication;
|
||||
$data['authenticationRoles'] = $this->authenticationRoles;
|
||||
$data['deprecated'] = $this->deprecated;
|
||||
|
||||
return $data;
|
||||
|
@ -22,8 +22,11 @@ class JmsSecurityExtraHandler implements HandlerInterface
|
||||
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
|
||||
{
|
||||
foreach ($annotations as $annot) {
|
||||
if ($annot instanceof Secure || $annot instanceof PreAuthorize) {
|
||||
if ($annot instanceof PreAuthorize) {
|
||||
$annotation->setAuthentication(true);
|
||||
} else if ($annot instanceof Secure) {
|
||||
$annotation->setAuthentication(true);
|
||||
$annotation->setAuthenticationRoles(is_array($annot->roles) ? $annot->roles : explode(',', $annot->roles));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ Also bundle will get information from the other annotations:
|
||||
|
||||
* @FOS\RestBundle\Controller\Annotations\QueryParam - use as `requirements` (when strict parameter is true), `filters` (when strict is false)
|
||||
|
||||
* @JMS\SecurityExtraBundle\Annotation\Secure - set `authentification` to true
|
||||
* @JMS\SecurityExtraBundle\Annotation\Secure - set `authentification` to true, `authenticationRoles` to the given roles
|
||||
|
||||
* @Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache - set `cache`
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
<span class="icon lock" title="HTTPS"></span>
|
||||
{% endif %}
|
||||
{% if data.authentication %}
|
||||
<span class="icon keys" title="Needs authentication"></span>
|
||||
<span class="icon keys" title="Needs {{ data.authenticationRoles|length > 0 ? data.authenticationRoles|join(', ') : 'authentication' }}"></span>
|
||||
{% endif %}
|
||||
|
||||
<span class="path">
|
||||
|
@ -32,6 +32,7 @@ class ApiDocTest extends TestCase
|
||||
$this->assertFalse(isset($array['parameters']));
|
||||
$this->assertNull($annot->getInput());
|
||||
$this->assertFalse($array['authentication']);
|
||||
$this->assertTrue(is_array($array['authenticationRoles']));
|
||||
}
|
||||
|
||||
public function testConstructWithInvalidData()
|
||||
|
@ -186,6 +186,9 @@ class ApiDocExtractorTest extends WebTestCase
|
||||
$this->assertTrue(
|
||||
$annotation->getAuthentication()
|
||||
);
|
||||
$this->assertContains('ROLE_USER', $annotation->getAuthenticationRoles());
|
||||
$this->assertContains('ROLE_FOOBAR', $annotation->getAuthenticationRoles());
|
||||
$this->assertCount(2, $annotation->getAuthenticationRoles());
|
||||
}
|
||||
|
||||
public function testGetWithCache()
|
||||
|
@ -167,7 +167,8 @@ class TestController
|
||||
|
||||
/**
|
||||
* @ApiDoc(
|
||||
* authentication=true
|
||||
* authentication=true,
|
||||
* authenticationRoles={"ROLE_USER","ROLE_FOOBAR"}
|
||||
* )
|
||||
*/
|
||||
public function authenticatedAction()
|
||||
|
@ -60,6 +60,7 @@ class SimpleFormatterTest extends WebTestCase
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
1 =>
|
||||
@ -94,6 +95,7 @@ class SimpleFormatterTest extends WebTestCase
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
2 =>
|
||||
@ -134,6 +136,7 @@ class SimpleFormatterTest extends WebTestCase
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
3 =>
|
||||
@ -174,6 +177,7 @@ class SimpleFormatterTest extends WebTestCase
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
),
|
||||
@ -196,6 +200,7 @@ class SimpleFormatterTest extends WebTestCase
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
1 =>
|
||||
@ -205,6 +210,7 @@ class SimpleFormatterTest extends WebTestCase
|
||||
'description' => 'Action without HTTP verb',
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
2 =>
|
||||
@ -223,6 +229,7 @@ class SimpleFormatterTest extends WebTestCase
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
3 =>
|
||||
@ -231,6 +238,7 @@ class SimpleFormatterTest extends WebTestCase
|
||||
'uri' => '/authenticated',
|
||||
'https' => false,
|
||||
'authentication' => true,
|
||||
'authenticationRoles' => array('ROLE_USER','ROLE_FOOBAR'),
|
||||
'deprecated' => false,
|
||||
),
|
||||
4 =>
|
||||
@ -431,6 +439,7 @@ With multiple lines.',
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
5 =>
|
||||
@ -450,6 +459,7 @@ With multiple lines.',
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
6 =>
|
||||
@ -490,6 +500,7 @@ And, it supports multilines until the first \'@\' char.',
|
||||
'description' => 'This method is useful to test if the getDocComment works.',
|
||||
'documentation' => "This method is useful to test if the getDocComment works.\nAnd, it supports multilines until the first '@' char.",
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
7 =>
|
||||
@ -498,6 +509,7 @@ And, it supports multilines until the first \'@\' char.',
|
||||
'uri' => '/return-nested-output',
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
'response' =>
|
||||
array (
|
||||
@ -706,6 +718,7 @@ With multiple lines.',
|
||||
),
|
||||
'https' => true,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
9 =>
|
||||
@ -723,6 +736,7 @@ With multiple lines.',
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
10 =>
|
||||
@ -731,6 +745,7 @@ With multiple lines.',
|
||||
'uri' => '/z-action-with-deprecated-indicator',
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => true,
|
||||
),
|
||||
11 =>
|
||||
@ -748,6 +763,7 @@ With multiple lines.',
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
12 =>
|
||||
@ -764,6 +780,7 @@ With multiple lines.',
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
13 =>
|
||||
@ -781,6 +798,7 @@ With multiple lines.',
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
14 =>
|
||||
@ -799,6 +817,7 @@ With multiple lines.',
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
),
|
||||
@ -820,6 +839,7 @@ With multiple lines.',
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
),
|
||||
@ -841,6 +861,7 @@ With multiple lines.',
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
),
|
||||
@ -889,7 +910,8 @@ With multiple lines.',
|
||||
),
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'deprecated' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
Loading…
x
Reference in New Issue
Block a user