Skip to content

Commit 6fd6344

Browse files
[11.10] Add optional expires_at parameter to project members (#713)
Co-authored-by: Philipp Kolmann <[email protected]>
1 parent 91f0ea1 commit 6fd6344

File tree

2 files changed

+68
-12
lines changed

2 files changed

+68
-12
lines changed

src/Api/Projects.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -586,32 +586,44 @@ public function allMember($project_id, int $user_id)
586586
}
587587

588588
/**
589-
* @param int|string $project_id
590-
* @param int $user_id
591-
* @param int $access_level
589+
* @param int|string $project_id
590+
* @param int $user_id
591+
* @param int $access_level
592+
* @param string|null $expires_at
592593
*
593594
* @return mixed
594595
*/
595-
public function addMember($project_id, int $user_id, int $access_level)
596+
public function addMember($project_id, int $user_id, int $access_level, string $expires_at = null)
596597
{
597-
return $this->post($this->getProjectPath($project_id, 'members'), [
598+
$params = [
598599
'user_id' => $user_id,
599600
'access_level' => $access_level,
600-
]);
601+
];
602+
if (null !== $expires_at) {
603+
$params['expires_at'] = $expires_at;
604+
}
605+
606+
return $this->post($this->getProjectPath($project_id, 'members'), $params);
601607
}
602608

603609
/**
604-
* @param int|string $project_id
605-
* @param int $user_id
606-
* @param int $access_level
610+
* @param int|string $project_id
611+
* @param int $user_id
612+
* @param int $access_level
613+
* @param string|null $expires_at
607614
*
608615
* @return mixed
609616
*/
610-
public function saveMember($project_id, int $user_id, int $access_level)
617+
public function saveMember($project_id, int $user_id, int $access_level, string $expires_at = null)
611618
{
612-
return $this->put($this->getProjectPath($project_id, 'members/'.self::encodePath($user_id)), [
619+
$params = [
613620
'access_level' => $access_level,
614-
]);
621+
];
622+
if (null !== $expires_at) {
623+
$params['expires_at'] = $expires_at;
624+
}
625+
626+
return $this->put($this->getProjectPath($project_id, 'members/'.self::encodePath($user_id)), $params);
615627
}
616628

617629
/**

tests/Api/ProjectsTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,28 @@ public function shouldAddMember(): void
11711171
$this->assertEquals($expectedArray, $api->addMember(1, 2, 3));
11721172
}
11731173

1174+
/**
1175+
* @test
1176+
*/
1177+
public function shouldAddMemberWithExpiration(): void
1178+
{
1179+
// tomorrow
1180+
$expiration = \date('Y-m-d', \time() + 86400);
1181+
$expectedArray = [
1182+
'user_id' => 3,
1183+
'access_level' => 3,
1184+
'expires_at' => $expiration,
1185+
];
1186+
1187+
$api = $this->getApiMock();
1188+
$api->expects($this->once())
1189+
->method('post')
1190+
->with('projects/1/members', ['user_id' => 3, 'access_level' => 3, 'expires_at' => $expiration])
1191+
->will($this->returnValue($expectedArray));
1192+
1193+
$this->assertEquals($expectedArray, $api->addMember(1, 3, 3, $expiration));
1194+
}
1195+
11741196
/**
11751197
* @test
11761198
*/
@@ -1187,6 +1209,28 @@ public function shouldSaveMember(): void
11871209
$this->assertEquals($expectedArray, $api->saveMember(1, 2, 4));
11881210
}
11891211

1212+
/**
1213+
* @test
1214+
*/
1215+
public function shouldSaveMemberWithExpiration(): void
1216+
{
1217+
// tomorrow
1218+
$expiration = \date('Y-m-d', \time() + 86400);
1219+
$expectedArray = [
1220+
'user_id' => 3,
1221+
'access_level' => 4,
1222+
'expires_at' => $expiration,
1223+
];
1224+
1225+
$api = $this->getApiMock();
1226+
$api->expects($this->once())
1227+
->method('put')
1228+
->with('projects/1/members/3', ['access_level' => 4, 'expires_at' => $expiration])
1229+
->will($this->returnValue($expectedArray));
1230+
1231+
$this->assertEquals($expectedArray, $api->saveMember(1, 3, 4, $expiration));
1232+
}
1233+
11901234
/**
11911235
* @test
11921236
*/

0 commit comments

Comments
 (0)