Skip to content

Commit

Permalink
Merge pull request #1005 from nextcloud/backport/997/stable27
Browse files Browse the repository at this point in the history
[stable27] feat(api): Move from index.php to ocs API
  • Loading branch information
nickvergessen authored Oct 23, 2024
2 parents aea9e9c + f221320 commit 0613301
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 66 deletions.
4 changes: 2 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,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.

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.

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.

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.

2 changes: 1 addition & 1 deletion js/terms_of_service-user.js.map

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 @@ -24,8 +24,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 @@ -35,7 +35,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 @@ -83,9 +83,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 @@ -102,7 +102,7 @@ public function signTerms(int $termId): JSONResponse {
// Mark all notifications as processed …
$this->notificationsManager->markProcessed($notification);

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


Expand All @@ -111,20 +111,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 @@ -147,6 +147,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 @@ -30,16 +30,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 @@ -86,9 +86,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 @@ -102,35 +102,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 @@ -140,11 +140,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 @@ -156,7 +156,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 @@ -172,6 +172,6 @@ public function create(string $countryCode,
$event = $this->createTermsCreatedEvent();
$this->eventDispatcher->dispatchTyped($event);

return new JSONResponse($terms);
return new DataResponse($terms);
}
}
24 changes: 13 additions & 11 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadi
import NcMultiselect from '@nextcloud/vue/dist/Components/NcMultiselect.js'
import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { generateUrl } from '@nextcloud/router'
import { generateOcsUrl } from '@nextcloud/router'

// Styles
import '@nextcloud/dialogs/dist/index.css'
Expand Down Expand Up @@ -155,15 +155,16 @@ export default {
this.saveButtonText = t('terms_of_service', 'Loading …')
this.resetButtonText = t('terms_of_service', 'Reset all signatories')
axios
.get(generateUrl('/apps/terms_of_service/terms/admin'))
.get(generateOcsUrl('/apps/terms_of_service/terms/admin'))
.then(response => {
if (response.data.terms.length !== 0) {
this.terms = response.data.terms
const data = response.data.ocs.data
if (data.terms.length !== 0) {
this.terms = data.terms
}
this.countries = response.data.countries
this.languages = response.data.languages
this.showOnPublicShares = response.data.tos_on_public_shares === '1'
this.showForLoggedInUser = response.data.tos_for_users === '1'
this.countries = data.countries
this.languages = data.languages
this.showOnPublicShares = data.tos_on_public_shares === '1'
this.showForLoggedInUser = data.tos_for_users === '1'
Object.keys(this.countries).forEach((countryCode) => {
this.countryOptions.push({
value: countryCode,
Expand Down Expand Up @@ -194,14 +195,15 @@ export default {
this.saveButtonDisabled = true

axios
.post(generateUrl('/apps/terms_of_service/terms'),
.post(generateOcsUrl('/apps/terms_of_service/terms'),
{
countryCode: this.country.value,
languageCode: this.language.value,
body: this.body,
})
.then(response => {
this.$set(this.terms, response.data.id, response.data)
const data = response.data.ocs.data
this.$set(this.terms, data.id, data)

showSuccess(t('terms_of_service', 'Terms saved successfully!'))
this.saveButtonDisabled = false
Expand All @@ -211,7 +213,7 @@ export default {
this.resetButtonDisabled = true

axios
.delete(generateUrl('/apps/terms_of_service/sign'))
.delete(generateOcsUrl('/apps/terms_of_service/sign'))
.then(() => {
showSuccess(t('terms_of_service', 'All signatories reset!'))
this.resetButtonDisabled = false
Expand Down
10 changes: 5 additions & 5 deletions src/Registration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

<script>
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { generateOcsUrl } from '@nextcloud/router'
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import ModalContent from './components/ModalContent.vue'

Expand Down Expand Up @@ -102,10 +102,10 @@ export default {
methods: {
async loadTerms() {
try {
const response = await axios.get(generateUrl('/apps/terms_of_service/terms'))
const response = await axios.get(generateOcsUrl('/apps/terms_of_service/terms'))

// this.hasSigned = response.data.hasSigned
this.terms = response.data.terms
// this.hasSigned = response.data.ocs.data.hasSigned
this.terms = response.data.ocs.data.terms

const language = OC.getLanguage().split('-')[0]

Expand All @@ -126,7 +126,7 @@ export default {
this.selectedLanguage = index
}

this.languages.push(response.data.languages[this.terms[index].languageCode])
this.languages.push(response.data.ocs.data.languages[this.terms[index].languageCode])
})
}
// this.showTerms()
Expand Down
12 changes: 6 additions & 6 deletions src/UserApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<script>
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { generateOcsUrl } from '@nextcloud/router'
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import ModalContent from './components/ModalContent.vue'

Expand Down Expand Up @@ -82,10 +82,10 @@ export default {
methods: {
loadTerms() {
axios
.get(generateUrl('/apps/terms_of_service/terms'))
.get(generateOcsUrl('/apps/terms_of_service/terms'))
.then(response => {
this.hasSigned = response.data.hasSigned
this.terms = response.data.terms
this.hasSigned = response.data.ocs.data.hasSigned
this.terms = response.data.ocs.data.terms

const language = OC.getLanguage().split('-')[0]

Expand All @@ -106,7 +106,7 @@ export default {
this.selectedLanguage = index
}

this.languages.push(response.data.languages[this.terms[index].languageCode])
this.languages.push(response.data.ocs.data.languages[this.terms[index].languageCode])
})
}

Expand All @@ -133,7 +133,7 @@ export default {
}

axios.post(
generateUrl(url),
generateOcsUrl(url),
{
termId: this.termsId,
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Term.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import axios from '@nextcloud/axios'
import IconDelete from 'vue-material-design-icons/Delete.vue'
import IconPencil from 'vue-material-design-icons/Pencil.vue'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import { generateUrl } from '@nextcloud/router'
import { generateOcsUrl } from '@nextcloud/router'
export default {
name: 'Term',
Expand Down Expand Up @@ -106,7 +106,7 @@ export default {
onDelete() {
this.deleteButtonDisabled = true
axios
.delete(generateUrl('/apps/terms_of_service/terms/' + this.id))
.delete(generateOcsUrl('/apps/terms_of_service/terms/' + this.id))
.then(() => {
this.$delete(this.$parent.$parent.$parent.terms, this.id)
})
Expand Down

0 comments on commit 0613301

Please sign in to comment.