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

feat(api): Move from index.php to ocs API #997

Merged
merged 2 commits into from
Oct 21, 2024
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
4 changes: 2 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

return [
'resources' => [
'ocs-resources' => [
'terms' => [
'url' => '/terms'
],
],
'routes' => [
'ocs' => [
[
'name' => 'Terms#getAdminFormData',
'url' => '/terms/admin',
Expand Down
4 changes: 2 additions & 2 deletions js/terms_of_service-admin.js

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions js/terms_of_service-admin.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
SPDX-License-Identifier: BSD-3-Clause
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: (MPL-2.0 OR Apache-2.0)
SPDX-FileCopyrightText: inherits developers
SPDX-FileCopyrightText: escape-html developers
SPDX-FileCopyrightText: atomiks
SPDX-FileCopyrightText: Varun A P
Expand All @@ -15,12 +16,12 @@ SPDX-FileCopyrightText: Roeland Jago Douma
SPDX-FileCopyrightText: Rob Cresswell <[email protected]>
SPDX-FileCopyrightText: Paul Vorbach <[email protected]> (http://paul.vorba.ch)
SPDX-FileCopyrightText: Paul Vorbach <[email protected]> (http://vorb.de)
SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: Joyent
SPDX-FileCopyrightText: John-David Dalton <[email protected]> (http://allyoucanleet.com/)
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <[email protected]>
SPDX-FileCopyrightText: Joas Schilling <[email protected]>
SPDX-FileCopyrightText: Jeff Sagal <[email protected]>
SPDX-FileCopyrightText: James Halliday
SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
SPDX-FileCopyrightText: Hypercontext
SPDX-FileCopyrightText: Hiroki Osame
Expand Down Expand Up @@ -145,9 +146,6 @@ This file is generated from multiple sources. Included packages:
- node-gettext
- version: 3.0.0
- license: MIT
- path-browserify
- version: 1.0.1
- license: MIT
- process
- version: 0.11.10
- license: MIT
Expand Down Expand Up @@ -187,6 +185,15 @@ This file is generated from multiple sources. Included packages:
- webpack
- version: 5.94.0
- license: MIT
- terms_of_service
- version: 3.0.0-dev.0
- inherits
- version: 2.0.3
- license: ISC
- util
- version: 0.10.4
- license: MIT
- path
- version: 0.12.7
- license: MIT
- nextcloud
- version: 1.0.0
- license: AGPL-3.0-or-later
2 changes: 1 addition & 1 deletion js/terms_of_service-admin.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/terms_of_service-public.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js/terms_of_service-public.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ SPDX-FileCopyrightText: escape-html developers
SPDX-FileCopyrightText: Tobias Koppers @sokra
SPDX-FileCopyrightText: T. Jameson Little <[email protected]>
SPDX-FileCopyrightText: Roman Shtylman <[email protected]>
SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: John-David Dalton <[email protected]> (http://allyoucanleet.com/)
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <[email protected]>
SPDX-FileCopyrightText: Joas Schilling <[email protected]>
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <[email protected]> (https://cure53.de/)
Expand Down Expand Up @@ -65,6 +65,6 @@ This file is generated from multiple sources. Included packages:
- webpack
- version: 5.94.0
- license: MIT
- terms_of_service
- version: 3.0.0-dev.0
- nextcloud
- version: 1.0.0
- license: AGPL-3.0-or-later
2 changes: 1 addition & 1 deletion js/terms_of_service-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/terms_of_service-registration.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js/terms_of_service-registration.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ SPDX-FileCopyrightText: escape-html developers
SPDX-FileCopyrightText: Tobias Koppers @sokra
SPDX-FileCopyrightText: T. Jameson Little <[email protected]>
SPDX-FileCopyrightText: Roman Shtylman <[email protected]>
SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: John-David Dalton <[email protected]> (http://allyoucanleet.com/)
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <[email protected]>
SPDX-FileCopyrightText: Joas Schilling <[email protected]>
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <[email protected]> (https://cure53.de/)
Expand Down Expand Up @@ -69,6 +69,6 @@ This file is generated from multiple sources. Included packages:
- webpack
- version: 5.94.0
- license: MIT
- terms_of_service
- version: 3.0.0-dev.0
- nextcloud
- version: 1.0.0
- license: AGPL-3.0-or-later
2 changes: 1 addition & 1 deletion js/terms_of_service-registration.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/terms_of_service-user.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js/terms_of_service-user.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ SPDX-FileCopyrightText: escape-html developers
SPDX-FileCopyrightText: Tobias Koppers @sokra
SPDX-FileCopyrightText: T. Jameson Little <[email protected]>
SPDX-FileCopyrightText: Roman Shtylman <[email protected]>
SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: John-David Dalton <[email protected]> (http://allyoucanleet.com/)
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <[email protected]>
SPDX-FileCopyrightText: Joas Schilling <[email protected]>
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <[email protected]> (https://cure53.de/)
Expand Down Expand Up @@ -65,6 +65,6 @@ This file is generated from multiple sources. Included packages:
- webpack
- version: 5.94.0
- license: MIT
- terms_of_service
- version: 3.0.0-dev.0
- nextcloud
- version: 1.0.0
- license: AGPL-3.0-or-later
2 changes: 1 addition & 1 deletion js/terms_of_service-user.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SPDX-License-Identifier: (MPL-2.0 OR Apache-2.0)
SPDX-FileCopyrightText: xiaokai <[email protected]>
SPDX-FileCopyrightText: rhysd <[email protected]>
SPDX-FileCopyrightText: inline-style-parser developers
SPDX-FileCopyrightText: inherits developers
SPDX-FileCopyrightText: escape-html developers
SPDX-FileCopyrightText: debounce developers
SPDX-FileCopyrightText: atomiks
Expand All @@ -25,10 +26,10 @@ SPDX-FileCopyrightText: Paul Vorbach <[email protected]> (http://vorb.de)
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: Mark <[email protected]>
SPDX-FileCopyrightText: Mapbox
SPDX-FileCopyrightText: Joyent
SPDX-FileCopyrightText: John-David Dalton <[email protected]> (http://allyoucanleet.com/)
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <[email protected]>
SPDX-FileCopyrightText: Jeff Sagal <[email protected]>
SPDX-FileCopyrightText: James Halliday
SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
SPDX-FileCopyrightText: Hypercontext
SPDX-FileCopyrightText: Hiroki Osame
Expand Down Expand Up @@ -370,9 +371,6 @@ This file is generated from multiple sources. Included packages:
- node-gettext
- version: 3.0.0
- license: MIT
- path-browserify
- version: 1.0.1
- license: MIT
- process
- version: 0.11.10
- license: MIT
Expand Down Expand Up @@ -454,3 +452,12 @@ This file is generated from multiple sources. Included packages:
- zwitch
- version: 2.0.4
- license: MIT
- inherits
- version: 2.0.3
- license: ISC
- util
- version: 0.10.4
- license: MIT
- path
- version: 0.12.7
- license: MIT

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions lib/Controller/SigningController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use OCA\TermsOfService\AppInfo\Application;
use OCA\TermsOfService\Db\Entities\Signatory;
use OCA\TermsOfService\Db\Mapper\SignatoryMapper;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IConfig;
use OCP\IRequest;
use OCP\ISession;
Expand All @@ -20,7 +20,7 @@
use OCA\TermsOfService\Events\SignaturesResetEvent;
use OCP\EventDispatcher\IEventDispatcher;

class SigningController extends Controller {
class SigningController extends OCSController {
/** @var string */
private $userId;
/** @var SignatoryMapper */
Expand Down Expand Up @@ -68,9 +68,9 @@ protected function resetAllSignaturesEvent(): SignaturesResetEvent {
*
* @param int $termId
*
* @return JSONResponse
* @return DataResponse
*/
public function signTerms(int $termId): JSONResponse {
public function signTerms(int $termId): DataResponse {
$signatory = new Signatory();
$signatory->setUserId($this->userId);
$signatory->setTermsId($termId);
Expand All @@ -87,7 +87,7 @@ public function signTerms(int $termId): JSONResponse {
// Mark all notifications as processed …
$this->notificationsManager->markProcessed($notification);

return new JSONResponse();
return new DataResponse();
}


Expand All @@ -96,20 +96,20 @@ public function signTerms(int $termId): JSONResponse {
*
* @param int $termId
* @UseSession
* @return JSONResponse
* @return DataResponse
*/
public function signTermsPublic(int $termId): JSONResponse {
public function signTermsPublic(int $termId): DataResponse {
$uuid = $this->config->getAppValue(Application::APPNAME, 'term_uuid', '');
$this->session->set('term_uuid', $uuid);

return new JSONResponse();
return new DataResponse();
}


/**
* @return JSONResponse
* @return DataResponse
*/
public function resetAllSignatories(): JSONResponse {
public function resetAllSignatories(): DataResponse {
$this->signatoryMapper->deleteAllSignatories();
$this->config->setAppValue(Application::APPNAME, 'term_uuid', uniqid());

Expand All @@ -132,6 +132,6 @@ public function resetAllSignatories(): JSONResponse {
$event = $this->resetAllSignaturesEvent();
$this->eventDispatcher->dispatchTyped($event);

return new JSONResponse();
return new DataResponse();
}
}
32 changes: 16 additions & 16 deletions lib/Controller/TermsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
use OCA\TermsOfService\Db\Mapper\SignatoryMapper;
use OCA\TermsOfService\Db\Mapper\TermsMapper;
use OCA\TermsOfService\Exceptions\TermsNotFoundException;
use OCP\AppFramework\Controller;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IRequest;
use OCP\L10N\IFactory;
use OCA\TermsOfService\Events\TermsCreatedEvent;
use OCP\EventDispatcher\IEventDispatcher;

class TermsController extends Controller {
class TermsController extends OCSController {
/** @var IFactory */
private $factory;
/** @var TermsMapper */
Expand Down Expand Up @@ -71,9 +71,9 @@ public function __construct(string $appName,

/**
* @PublicPage
* @return JSONResponse
* @return DataResponse
*/
public function index(): JSONResponse {
public function index(): DataResponse {
$currentCountry = $this->countryDetector->getCountry();
$countryTerms = $this->termsMapper->getTermsForCountryCode($currentCountry);

Expand All @@ -87,35 +87,35 @@ public function index(): JSONResponse {
'languages' => $this->languageMapper->getLanguages(),
'hasSigned' => $this->checker->currentUserHasSigned(),
];
return new JSONResponse($response);
return new DataResponse($response);
}

/**
* @return JSONResponse
* @return DataResponse
*/
public function getAdminFormData(): JSONResponse {
public function getAdminFormData(): DataResponse {
$response = [
'terms' => $this->termsMapper->getTerms(),
'countries' => $this->countryMapper->getCountries(),
'languages' => $this->languageMapper->getLanguages(),
'tos_on_public_shares' => $this->config->getAppValue(Application::APPNAME, 'tos_on_public_shares', '0'),
'tos_for_users' => $this->config->getAppValue(Application::APPNAME, 'tos_for_users', '1'),
];
return new JSONResponse($response);
return new DataResponse($response);
}

/**
* @param int $id
* @return JSONResponse
* @return DataResponse
*/
public function destroy(int $id): JSONResponse {
public function destroy(int $id): DataResponse {
$terms = new Terms();
$terms->setId($id);

$this->termsMapper->delete($terms);
$this->signatoryMapper->deleteTerm($terms);

return new JSONResponse();
return new DataResponse();
}
protected function createTermsCreatedEvent(): TermsCreatedEvent {
return new TermsCreatedEvent();
Expand All @@ -125,11 +125,11 @@ protected function createTermsCreatedEvent(): TermsCreatedEvent {
* @param string $countryCode
* @param string $languageCode
* @param string $body
* @return JSONResponse
* @return DataResponse
*/
public function create(string $countryCode,
string $languageCode,
string $body): JSONResponse {
string $body): DataResponse {
$update = false;
try {
// Update terms
Expand All @@ -141,7 +141,7 @@ public function create(string $countryCode,
}

if (!$this->countryMapper->isValidCountry($countryCode) || !$this->languageMapper->isValidLanguage($languageCode)) {
return new JSONResponse([], Http::STATUS_EXPECTATION_FAILED);
return new DataResponse([], Http::STATUS_EXPECTATION_FAILED);
}

$terms->setCountryCode($countryCode);
Expand All @@ -157,6 +157,6 @@ public function create(string $countryCode,
$event = $this->createTermsCreatedEvent();
$this->eventDispatcher->dispatchTyped($event);

return new JSONResponse($terms);
return new DataResponse($terms);
}
}
Loading
Loading