Skip to content

Commit dcf1f20

Browse files
committed
Merge pull request #102 from Baldinof/block_user
Add support for block/unblock users
2 parents ea1cd47 + b01d8d6 commit dcf1f20

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

lib/Gitlab/Api/Users.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ public function remove($id)
7676
return $this->delete('users/'.$this->encodePath($id));
7777
}
7878

79+
/**
80+
* @param int $id
81+
* @return mixed
82+
*/
83+
public function block($id)
84+
{
85+
return $this->put('users/'.$this->encodePath($id).'/block');
86+
}
87+
88+
/**
89+
* @param int $id
90+
* @return mixed
91+
*/
92+
public function unblock($id)
93+
{
94+
return $this->put('users/'.$this->encodePath($id).'/unblock');
95+
}
96+
7997
/**
8098
* @param string $emailOrUsername
8199
* @param string $password

lib/Gitlab/Model/User.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ public function remove()
129129
return true;
130130
}
131131

132+
/**
133+
* @return bool
134+
*/
135+
public function block()
136+
{
137+
$this->api('users')->block($this->id);
138+
139+
return true;
140+
}
141+
142+
/**
143+
* @return bool
144+
*/
145+
public function unblock()
146+
{
147+
$this->api('users')->unblock($this->id);
148+
149+
return true;
150+
}
151+
132152
/**
133153
* @return Key[]
134154
*/

test/Gitlab/Tests/Api/UsersTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,40 @@ public function shouldRemoveUser()
206206
$this->assertEquals($expectedBool, $api->remove(1));
207207
}
208208

209+
/**
210+
* @test
211+
*/
212+
public function shouldBlockUser()
213+
{
214+
$expectedBool = true;
215+
216+
$api = $this->getApiMock();
217+
$api->expects($this->once())
218+
->method('put')
219+
->with('users/1/block')
220+
->will($this->returnValue($expectedBool))
221+
;
222+
223+
$this->assertEquals($expectedBool, $api->block(1));
224+
}
225+
226+
/**
227+
* @test
228+
*/
229+
public function shouldUnblockUser()
230+
{
231+
$expectedBool = true;
232+
233+
$api = $this->getApiMock();
234+
$api->expects($this->once())
235+
->method('put')
236+
->with('users/1/unblock')
237+
->will($this->returnValue($expectedBool))
238+
;
239+
240+
$this->assertEquals($expectedBool, $api->unblock(1));
241+
}
242+
209243
/**
210244
* @test
211245
*/

0 commit comments

Comments
 (0)