Skip to content

Commit afdedad

Browse files
author
Artur Łabudziński
committed
Group Filters for the names (for some reason utf8/unicode group names made 500 from jira server. So im filtering the names to us characters only.
1 parent 457bf43 commit afdedad

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/Account/AccountService.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function addGroupUser($name, $userName)
1515
]);
1616

1717
try {
18-
$ret = $this->exec($this->uri.'/user?groupname=' . $name, $json, 'POST');
18+
$ret = $this->exec($this->uri.'/user?groupname=' . $this->filterName($name).'', $json, 'POST');
1919
} catch (\Jira\Api\Exception $e) {
2020
$code = $e -> getCode();
2121
$err = $e -> getMessage();
@@ -42,7 +42,7 @@ public function removeGroupUser($name, $userName)
4242

4343
try
4444
{
45-
$ret = $this->exec($this->uri.'/user?username='.$userName.'&groupname=' . $name, null , 'DELETE');
45+
$ret = $this->exec($this->uri.'/user?username='.$userName.'&groupname=' . $this->filterName($name).'', null , 'DELETE');
4646
}
4747
catch (\Jira\Api\Exception $e)
4848
{
@@ -65,7 +65,7 @@ public function removeGroupUser($name, $userName)
6565
*/
6666
public function getGroup($name)
6767
{
68-
$ret = $this->exec($this->uri.'?groupname=' . $name);
68+
$ret = $this->exec($this->uri.'?groupname=' . $this->filterName($name, '+') .'');
6969
// $ret = $this->exec($this->uri.'/member?groupname=' . $name);
7070

7171
$group = $this->json_mapper->map(
@@ -88,14 +88,14 @@ public function getGroupMembers($name)
8888
while ($page * $onPage < $max)
8989
{
9090
$json = json_encode([
91-
'groupname' => $name,
91+
'groupname' => $this->filterName($name),
9292
'maxResults' => $max,
9393
'startAt' => $onPage * $page,
9494
]);
95-
$ret = $this->exec($this->uri."?expand=users&maxResults=$max&startAt=".($onPage*$page).'&groupname=' . $name);
95+
$ret = $this->exec($this->uri."?expand=users&maxResults=$max&startAt=".($onPage*$page).'&groupname=' . $this->filterName($name,'+'));
9696
// $ret = $this->exec($this->uri.'?groupname=' . $name);
9797
$ret = json_decode($ret);
98-
print_r($ret);
98+
// print_r($ret);
9999
$max = $ret->users->size;
100100

101101
if ($group === null) {
@@ -120,7 +120,7 @@ public function getGroupMembers($name)
120120
public function createGroup($name)
121121
{
122122
$json = json_encode([
123-
'name' => $name,
123+
'name' => $this->filterName($name),
124124
]);
125125
$ret = $this->exec($this->uri, $json, 'POST');
126126
// $ret = $this->exec($this->uri.'/member?groupname=' . $name);

src/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public function __construct(ConfigurationInterface $configuration = null)
8585
}
8686
static public function getMapper() { return self::$jMapper; }
8787

88+
public function filterName($name, $spaceEncode = false) {
89+
if ($spaceEncode) $name = str_replace(' ', $spaceEncode, $name);
90+
return ( iconv('utf-8', 'us-ascii//TRANSLIT', $name));
91+
}
92+
8893
/**
8994
* Convert log level
9095
*

0 commit comments

Comments
 (0)