From 56c3671b0f388d88267a599c04f8b92fc0bd86c6 Mon Sep 17 00:00:00 2001 From: KwangSeob Jeong Date: Thu, 29 Mar 2018 15:00:15 +0900 Subject: [PATCH] fixed #143 setting issue security id --- README.md | 5 +- src/Issue/IssueField.php | 19 +++++++ src/Issue/IssueService.php | 47 ++++++++++++++++ src/Issue/SecurityScheme.php | 28 +++++++++ tests/IssueSecuritySechemTest.php | 94 +++++++++++++++++++++++++++++++ 5 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 src/Issue/SecurityScheme.php create mode 100644 tests/IssueSecuritySechemTest.php diff --git a/README.md b/README.md index 267eb738..ded8c8d0 100644 --- a/README.md +++ b/README.md @@ -412,7 +412,10 @@ try { ->setIssueType("Bug") ->setDescription("Full description for issue") ->addVersion(["1.0.1", "1.0.3"]) - ->addComponents(['Component-1', 'Component-2']); + ->addComponents(['Component-1', 'Component-2']) + // set issue security if you need. + ->setSecurity(10001 /* security scheme id */) + ; $issueService = new IssueService(); diff --git a/src/Issue/IssueField.php b/src/Issue/IssueField.php index fcf5ddeb..7c501876 100644 --- a/src/Issue/IssueField.php +++ b/src/Issue/IssueField.php @@ -122,6 +122,9 @@ class IssueField implements \JsonSerializable /** @var array|null */ public $customFields; + /** @var SecurityScheme */ + public $security; + public function __construct($updateIssue = false) { if ($updateIssue != true) { @@ -382,4 +385,20 @@ public function addComponents($component) return $this; } + + /** + * set security level + * + * @param $securityId + * @return $this + */ + public function setSecurity($securityId) + { + if ($this->security == null) { + $this->security = new SecurityScheme(); + } + $this->security->id = $securityId; + + return $this; + } } diff --git a/src/Issue/IssueService.php b/src/Issue/IssueService.php index 9769206b..cf5abd60 100644 --- a/src/Issue/IssueService.php +++ b/src/Issue/IssueService.php @@ -875,4 +875,51 @@ public function createOrUpdateRemoteIssueLink($issueIdOrKey, RemoteIssueLink $ri return $res; } + + /** + * get all issue security schemes + * + * @throws JiraException + * @throws \JsonMapper_Exception + * + * @return SecurityScheme[] array of SecurityScheme class + */ + public function getAllIssueSecuritySchemes() + { + $url = '/issuesecurityschemes'; + + $ret = $this->exec($url); + + $data = json_decode($ret, true); + + // extract schem field + $schemes = json_decode(json_encode($data['issueSecuritySchemes']), false); + + $res = $this->json_mapper->mapArray( + $schemes, new \ArrayObject(), '\JiraRestApi\Issue\SecurityScheme' + ); + + return $res; + } + + /** + * get issue security scheme + * + * @param int $securityId security scheme id + * @return SecurityScheme SecurityScheme + * @throws JiraException + * @throws \JsonMapper_Exception + */ + public function getIssueSecuritySchemes($securityId) + { + $url = '/issuesecurityschemes/' . $id; + + $ret = $this->exec($url); + + $res = $this->json_mapper->map( + json_decode($ret), new SecurityScheme() + ); + + return $res; + } } diff --git a/src/Issue/SecurityScheme.php b/src/Issue/SecurityScheme.php new file mode 100644 index 00000000..98a65daa --- /dev/null +++ b/src/Issue/SecurityScheme.php @@ -0,0 +1,28 @@ +getAllIssueSecuritySchemes(); + + $this->assertGreaterThan(1, count($securitySchemes), 'security scheme must greater than 1'); + $this->assertEquals(true, array_key_exists('id', $securitySchemes[0]), 'security id not found'); + + return $securitySchemes; + } catch (HTTPException $e) { + $this->assertTrue(false, $e->getMessage()); + } + } + + /** + * @depends testGetAllSecuritySchemes + * + * @param $securitySchem + * @throws Exception + * @throws JiraException + * @throws JsonMapper_Exception + */ + public function testGetSecurityScheme($securitySchemes) + { + $securityId = 0; + + try { + $issueService = new IssueService(); + + foreach ($securitySchemes as $s) { + $ss = $issueService->getIssueSecuritySchemes($s->id); + + $this->assertObjectHasAttribute('id', $ss, 'security id not found'); + $this->assertObjectHasAttribute('levels', $ss, 'security level not found'); + + if ($securityId === 0) + $securityId = $ss->id; + } + + return $securityId; + } catch (HTTPException $e) { + $this->assertTrue(false, $e->getMessage()); + } + } + + /** + * @depends testGetSecurityScheme + * + * @param $schemeId + * @return mixed + * @throws Exception + * @throws JsonMapper_Exception + */ + public function testCreateIssueWithSecurityScheme($securityId) + { + try { + $issueField = new IssueField(); + + $issueField->setProjectKey('TEST') + ->setSummary("issue security level test") + ->setAssigneeName('lesstif') + ->setPriorityName('Critical') + ->setIssueType('Bug') + ->setDescription('Full description for issue') + ->addVersion(['1.0.1', '1.0.3']) + ->addComponents(['Component-1', 'Component-2']) + ->setSecurity($securityId) + ; + + $issueService = new IssueService(); + + $ret = $issueService->create($issueField); + + $this->assertInstanceOf(Issue::class, $ret); + + } catch (JiraException $e) { + $this->assertTrue(false, 'Create Failed : '.$e->getMessage()); + } + } +}