Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4] webservices consistency #34093

Merged
merged 10 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function languageAssociations($model)
foreach ($model->associations as $association)
{
$resources[] = (new Resource($association, $serializer))
->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/content/article/' . $association->id));
->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/content/articles/' . $association->id));
}

$collection = new Collection($resources, $serializer);
Expand Down
24 changes: 12 additions & 12 deletions plugins/webservices/contact/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function onBeforeApiRoute(&$router)
{
$route = new Route(
['POST'],
'v1/contact/form/:id',
'v1/contacts/form/:id',
'contact.submitForm',
['id' => '(\d+)'],
['component' => 'com_contact']
Expand All @@ -50,13 +50,13 @@ public function onBeforeApiRoute(&$router)
$router->addRoute($route);

$router->createCRUDRoutes(
'v1/contact',
'v1/contacts',
'contact',
['component' => 'com_contact']
);

$router->createCRUDRoutes(
'v1/contact/categories',
'v1/contacts/categories',
'categories',
['component' => 'com_categories', 'extension' => 'com_contact']
);
Expand All @@ -78,37 +78,37 @@ public function onBeforeApiRoute(&$router)
private function createFieldsRoutes(&$router)
{
$router->createCRUDRoutes(
'v1/fields/contact/contact',
'v1/fields/contacts/contact',
'fields',
['component' => 'com_fields', 'context' => 'com_contact.contact']
);

$router->createCRUDRoutes(
'v1/fields/contact/mail',
'v1/fields/contacts/mail',
'fields',
['component' => 'com_fields', 'context' => 'com_contact.mail']
);

$router->createCRUDRoutes(
'v1/fields/contact/categories',
'v1/fields/contacts/categories',
'fields',
['component' => 'com_fields', 'context' => 'com_contact.categories']
);

$router->createCRUDRoutes(
'v1/fields/groups/contact/contact',
'v1/fields/groups/contacts/contact',
'groups',
['component' => 'com_fields', 'context' => 'com_contact.contact']
);

$router->createCRUDRoutes(
'v1/fields/groups/contact/mail',
'v1/fields/groups/contacts/mail',
'groups',
['component' => 'com_fields', 'context' => 'com_contact.mail']
);

$router->createCRUDRoutes(
'v1/fields/groups/contact/categories',
'v1/fields/groups/contacts/categories',
'groups',
['component' => 'com_fields', 'context' => 'com_contact.categories']
);
Expand All @@ -133,9 +133,9 @@ private function createContentHistoryRoutes(&$router)
$getDefaults = array_merge(['public' => false], $defaults);

$routes = [
new Route(['GET'], 'v1/contact/contenthistory/:id', 'history.displayList', ['id' => '(\d+)'], $getDefaults),
new Route(['PATCH'], 'v1/contact/contenthistory/keep/:id', 'history.keep', ['id' => '(\d+)'], $defaults),
new Route(['DELETE'], 'v1/contact/contenthistory/:id', 'history.delete', ['id' => '(\d+)'], $defaults),
new Route(['GET'], 'v1/contacts/contenthistory/:id', 'history.displayList', ['id' => '(\d+)'], $getDefaults),
new Route(['PATCH'], 'v1/contacts/contenthistory/keep/:id', 'history.keep', ['id' => '(\d+)'], $defaults),
new Route(['DELETE'], 'v1/contacts/contenthistory/:id', 'history.delete', ['id' => '(\d+)'], $defaults),
];

$router->addRoutes($routes);
Expand Down
8 changes: 4 additions & 4 deletions plugins/webservices/content/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PlgWebservicesContent extends CMSPlugin
public function onBeforeApiRoute(&$router)
{
$router->createCRUDRoutes(
'v1/content/article',
'v1/content/articles',
'articles',
['component' => 'com_content']
);
Expand Down Expand Up @@ -111,9 +111,9 @@ private function createContentHistoryRoutes(&$router)
$getDefaults = array_merge(['public' => false], $defaults);

$routes = [
new Route(['GET'], 'v1/content/article/contenthistory/:id', 'history.displayList', ['id' => '(\d+)'], $getDefaults),
new Route(['PATCH'], 'v1/content/article/contenthistory/keep/:id', 'history.keep', ['id' => '(\d+)'], $defaults),
new Route(['DELETE'], 'v1/content/article/contenthistory/:id', 'history.delete', ['id' => '(\d+)'], $defaults),
new Route(['GET'], 'v1/content/articles/contenthistory/:id', 'history.displayList', ['id' => '(\d+)'], $getDefaults),
new Route(['PATCH'], 'v1/content/articles/contenthistory/keep/:id', 'history.keep', ['id' => '(\d+)'], $defaults),
new Route(['DELETE'], 'v1/content/articles/contenthistory/:id', 'history.delete', ['id' => '(\d+)'], $defaults),
];

$router->addRoutes($routes);
Expand Down
14 changes: 7 additions & 7 deletions plugins/webservices/privacy/privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ public function onBeforeApiRoute(&$router)
$getDefaults = array_merge(['public' => false], $defaults);

$routes = [
new Route(['GET'], 'v1/privacy/request', 'requests.displayList', [], $getDefaults),
new Route(['GET'], 'v1/privacy/request/:id', 'requests.displayItem', ['id' => '(\d+)'], $getDefaults),
new Route(['GET'], 'v1/privacy/request/export/:id', 'requests.export', ['id' => '(\d+)'], $getDefaults),
new Route(['POST'], 'v1/privacy/request', 'requests.add', [], $defaults),
new Route(['GET'], 'v1/privacy/requests', 'requests.displayList', [], $getDefaults),
new Route(['GET'], 'v1/privacy/requests/:id', 'requests.displayItem', ['id' => '(\d+)'], $getDefaults),
new Route(['GET'], 'v1/privacy/requests/export/:id', 'requests.export', ['id' => '(\d+)'], $getDefaults),
new Route(['POST'], 'v1/privacy/requests', 'requests.add', [], $defaults),
];

$router->addRoutes($routes);

$routes = [
new Route(['GET'], 'v1/privacy/consent', 'consents.displayList', [], $getDefaults),
new Route(['GET'], 'v1/privacy/consent/:id', 'consents.displayItem', ['id' => '(\d+)'], $getDefaults),
new Route(['DELETE'], 'v1/privacy/consent/:id', 'consents.delete', ['id' => '(\d+)'], $defaults),
new Route(['GET'], 'v1/privacy/consents', 'consents.displayList', [], $getDefaults),
new Route(['GET'], 'v1/privacy/consents/:id', 'consents.displayItem', ['id' => '(\d+)'], $getDefaults),
new Route(['DELETE'], 'v1/privacy/consents/:id', 'consents.delete', ['id' => '(\d+)'], $defaults),
];

$router->addRoutes($routes);
Expand Down
2 changes: 1 addition & 1 deletion plugins/webservices/redirect/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PlgWebservicesRedirect extends CMSPlugin
public function onBeforeApiRoute(&$router)
{
$router->createCRUDRoutes(
'v1/redirect',
'v1/redirects',
'redirect',
['component' => 'com_redirect']
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Codeception/api/BasicCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testWrongCredentials(ApiTester $I)
{
$I->amBearerAuthenticated('BADTOKEN');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendGET('/content/article/1');
$I->sendGET('/content/articles/1');
$I->seeResponseCodeIs(Codeception\Util\HttpCode::UNAUTHORIZED);
}

Expand All @@ -80,7 +80,7 @@ public function testContentNegotiation(ApiTester $I)
{
$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'text/xml');
$I->sendGET('/content/article/1');
$I->sendGET('/content/articles/1');
$I->seeResponseCodeIs(Codeception\Util\HttpCode::NOT_ACCEPTABLE);
}

Expand Down
16 changes: 8 additions & 8 deletions tests/Codeception/api/com_contact/ContactCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,26 @@ public function testCrudOnContact(ApiTester $I)
'name' => 'Francine Blogs'
];

$I->sendPOST('/contact', $testarticle);
$I->sendPOST('/contacts', $testarticle);

$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendGET('/contact/1');
$I->sendGET('/contacts/1');
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');

// Category is a required field for this patch request for now TODO: Remove this dependency
$I->sendPATCH('/contact/1', ['name' => 'Frankie Blogs', 'catid' => 4, 'published' => -2]);
$I->sendPATCH('/contacts/1', ['name' => 'Frankie Blogs', 'catid' => 4, 'published' => -2]);
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendDELETE('/contact/1');
$I->sendDELETE('/contacts/1');
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
}

Expand Down Expand Up @@ -124,25 +124,25 @@ public function testCrudOnCategory(ApiTester $I)
]
];

$I->sendPOST('/contact/categories', $testContact);
$I->sendPOST('/contacts/categories', $testContact);

$I->seeResponseCodeIs(HttpCode::OK);
$categoryId = $I->grabDataFromResponseByJsonPath('$.data.id')[0];

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendGET('/contact/categories/' . $categoryId);
$I->sendGET('/contacts/categories/' . $categoryId);
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendPATCH('/contact/categories/' . $categoryId, ['title' => 'Another Title', 'published' => -2]);
$I->sendPATCH('/contacts/categories/' . $categoryId, ['title' => 'Another Title', 'published' => -2]);
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendDELETE('/contact/categories/' . $categoryId);
$I->sendDELETE('/contacts/categories/' . $categoryId);
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
}
}
8 changes: 4 additions & 4 deletions tests/Codeception/api/com_content/ContentCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ public function testCrudOnArticle(ApiTester $I)
'alias' => 'tobias'
];

$I->sendPOST('/content/article', $testarticle);
$I->sendPOST('/content/articles', $testarticle);

$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendGET('/content/article/1');
$I->sendGET('/content/articles/1');
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendPATCH('/content/article/1', ['title' => 'Another Title', 'state' => -2, 'catid' => 2]);
$I->sendPATCH('/content/articles/1', ['title' => 'Another Title', 'state' => -2, 'catid' => 2]);
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendDELETE('/content/article/1');
$I->sendDELETE('/content/articles/1');
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
}

Expand Down