mirror of
https://gitlab.linphone.org/BC/public/flexisip-account-manager.git
synced 2026-01-17 10:08:05 +00:00
Complete the authenticated account contacts tests and fix the related documentation
Cleanup the returned Vcard 4.0 formats
This commit is contained in:
parent
75a98c0949
commit
917ab3d123
7 changed files with 33 additions and 25 deletions
|
|
@ -228,8 +228,7 @@ class Account extends Authenticatable
|
|||
|
||||
public function toVcard4()
|
||||
{
|
||||
$vcard = '
|
||||
BEGIN:VCARD
|
||||
$vcard = 'BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
KIND:individual
|
||||
MEMBER:'.$this->getIdentifierAttribute();
|
||||
|
|
@ -250,7 +249,6 @@ X-LINPHONE-ACCOUNT-ACTION:'.$action->key.';'.$action->code.';'.$action->protocol
|
|||
}
|
||||
|
||||
return $vcard . '
|
||||
END:VCARD
|
||||
';
|
||||
END:VCARD';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ class ContactVcardController extends Controller
|
|||
return response(
|
||||
$request->user()->contacts->map(function ($contact) {
|
||||
return $contact->toVcard4();
|
||||
})->implode('
|
||||
')
|
||||
})->implode("\n")
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,26 +27,14 @@ class AccountContactController extends Controller
|
|||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$contacts = $request->user()->contacts;
|
||||
|
||||
return $request->has('vcard')
|
||||
? response($contacts->map(function ($contact) {
|
||||
return $contact->toVcard4();
|
||||
})->implode('
|
||||
')
|
||||
)
|
||||
: $contacts;
|
||||
return $request->user()->contacts;
|
||||
}
|
||||
|
||||
public function show(Request $request, string $sip)
|
||||
{
|
||||
$contact = $request->user()
|
||||
return $request->user()
|
||||
->contacts()
|
||||
->sip($sip)
|
||||
->firstOrFail();
|
||||
|
||||
return $request->has('vcard')
|
||||
? $contact->toVcard4()
|
||||
: $contact;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,6 +150,14 @@ Return the user registered devices.
|
|||
#### `DELETE /accounts/me/devices/{uuid}`
|
||||
Remove one of the user registered devices.
|
||||
|
||||
### Accounts devices
|
||||
|
||||
#### `GET /accounts/me/contacts`
|
||||
Return the user contacts.
|
||||
|
||||
#### `GET /accounts/me/contacts/{sip}`
|
||||
Return a user contact.
|
||||
|
||||
## Admin endpoints
|
||||
|
||||
Those endpoints are authenticated and requires an admin account.
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ Route::group(['middleware' => ['auth.digest_or_key']], function () {
|
|||
Route::post('accounts/me/email/request', 'Api\EmailController@requestUpdate');
|
||||
Route::post('accounts/me/password', 'Api\PasswordController@update');
|
||||
|
||||
Route::get('accounts/me/contacts', 'Api\AccountContactController@index');
|
||||
Route::get('accounts/me/contacts/{sip}', 'Api\AccountContactController@show');
|
||||
Route::get('accounts/me/contacts', 'Api\AccountContactController@index');
|
||||
|
||||
Route::group(['middleware' => ['auth.admin']], function () {
|
||||
// Accounts
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ class AccountContactTest extends TestCase
|
|||
{
|
||||
$password1 = Password::factory()->create();
|
||||
$password2 = Password::factory()->create();
|
||||
$password3 = Password::factory()->create();
|
||||
|
||||
$typeKey = 'phone';
|
||||
$actionKey = '123';
|
||||
|
|
@ -54,6 +55,12 @@ class AccountContactTest extends TestCase
|
|||
|
||||
$this->assertEquals(1, DB::table('contacts')->count());
|
||||
|
||||
$this->keyAuthenticated($admin->account)
|
||||
->json($this->method, $this->route.'/'.$password1->account->id.'/contacts/'.$password3->account->id)
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertEquals(2, DB::table('contacts')->count());
|
||||
|
||||
// Type
|
||||
$this->keyAuthenticated($admin->account)
|
||||
->json($this->method, '/api/account_types', [
|
||||
|
|
@ -79,7 +86,7 @@ class AccountContactTest extends TestCase
|
|||
$this->keyAuthenticated($admin->account)
|
||||
->json($this->method, $this->route.'/'.$password1->account->id.'/contacts/'.$password2->account->id)
|
||||
->assertStatus(403);
|
||||
$this->assertEquals(1, DB::table('contacts')->count());
|
||||
$this->assertEquals(2, DB::table('contacts')->count());
|
||||
|
||||
$this->keyAuthenticated($admin->account)
|
||||
->get($this->route.'/'.$password1->account->id.'/contacts')
|
||||
|
|
@ -101,6 +108,14 @@ class AccountContactTest extends TestCase
|
|||
'activated' => true
|
||||
]]);
|
||||
|
||||
$this->keyAuthenticated($password1->account)
|
||||
->get($this->route.'/me/contacts/'.$password2->account->identifier)
|
||||
->assertStatus(200)
|
||||
->assertJson([
|
||||
'username' => $password2->account->username,
|
||||
'activated' => true
|
||||
]);
|
||||
|
||||
// Vcard 4.0
|
||||
$this->keyAuthenticated($password1->account)
|
||||
->get('/contacts/vcard')
|
||||
|
|
@ -127,12 +142,12 @@ class AccountContactTest extends TestCase
|
|||
->delete($this->route.'/'.$password1->account->id.'/contacts/'.$password2->account->id)
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertEquals(0, DB::table('contacts')->count());
|
||||
$this->assertEquals(1, DB::table('contacts')->count());
|
||||
|
||||
// Retry
|
||||
$this->keyAuthenticated($admin->account)
|
||||
->delete($this->route.'/'.$password1->account->id.'/contacts/'.$password2->account->id)
|
||||
->assertStatus(403);
|
||||
$this->assertEquals(0, DB::table('contacts')->count());
|
||||
$this->assertEquals(1, DB::table('contacts')->count());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#%define _datadir %{_datarootdir}
|
||||
#%define _docdir %{_datadir}/doc
|
||||
|
||||
%define build_number 108
|
||||
%define build_number 109
|
||||
%define var_dir /var/opt/belledonne-communications
|
||||
%define opt_dir /opt/belledonne-communications/share/flexisip-account-manager
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue