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

Internal: Add terms acceptance and revocation - refs BT#21759 #5570

Merged
merged 1 commit into from
Jun 5, 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
5 changes: 5 additions & 0 deletions assets/vue/router/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export default {
name: 'TermsConditionsEdit',
path: 'edit',
component: () => import('../views/terms/TermsEdit.vue')
},
{
name: 'TermsConditionsView',
path: 'view',
component: () => import('../views/terms/Terms.vue')
}
]
}
13 changes: 13 additions & 0 deletions assets/vue/services/socialService.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ export default {
}
},

async revokeAcceptTerm(userId) {
try {
const response = await axios.post(`${API_URL}/delete-legal`, {
userId,
})

return response.data
} catch (error) {
console.error("Error revoking acceptance:", error)
throw error
}
},

async fetchInvitations(userId) {
try {
const response = await axios.get(`${API_URL}/invitations/${userId}`)
Expand Down
88 changes: 88 additions & 0 deletions assets/vue/views/terms/Terms.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<template>
<div class="terms">
<div v-for="(item, index) in term" :key="index">
<h3>{{ item.title }}</h3>
<div v-html="item.content"></div>
</div>
<p class="small mt-4 mb-4">{{ term.date_text }}</p>
<div v-if="!accepted">
<BaseButton
:label="$t('Accept Terms and Conditions')"
type="primary"
icon="pi pi-check"
@click="acceptTerms"
/>
</div>
<div v-else>
<p>{{ t('You accepted these terms on') }} {{ acceptanceDate }}</p>
<BaseButton
:label="$t('Revoke Acceptance')"
type="danger"
icon="pi pi-times"
@click="revokeAcceptance"
/>
</div>
</div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useSecurityStore } from "../../store/securityStore"
import { useI18n } from "vue-i18n"
import BaseButton from "../../components/basecomponents/BaseButton.vue"
import socialService from '../../services/socialService'

const { t } = useI18n()

const term = ref({})
const accepted = ref(false)
const acceptanceDate = ref(null)
const securityStore = useSecurityStore()

const fetchTerms = async () => {
try {
const userId = securityStore.user.id
term.value = await socialService.fetchTermsAndConditions(userId)
} catch (error) {
console.error('Error fetching terms:', error)
}
}

const checkAcceptance = async () => {
try {
const userId = securityStore.user.id
const response = await socialService.fetchLegalStatus(userId)
accepted.value = response.isAccepted
acceptanceDate.value = response.acceptDate
} catch (error) {
console.error('Error checking acceptance:', error)
}
}

const acceptTerms = async () => {
try {
const userId = securityStore.user.id
await socialService.submitAcceptTerm(userId)
accepted.value = true
acceptanceDate.value = new Date().toLocaleDateString()
} catch (error) {
console.error('Error accepting terms:', error)
}
}

const revokeAcceptance = async () => {
try {
const userId = securityStore.user.id
await socialService.revokeAcceptTerm(userId)
accepted.value = false
acceptanceDate.value = null
} catch (error) {
console.error('Error revoking acceptance:', error)
}
}

onMounted(() => {
fetchTerms()
checkAcceptance()
})
</script>
24 changes: 24 additions & 0 deletions src/CoreBundle/Controller/SocialController.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,30 @@ public function sendLegalTerm(
]);
}

#[Route('/delete-legal', name: 'chamilo_core_social_delete_legal')]
public function deleteLegal(Request $request, TranslatorInterface $translator,): JsonResponse
{
$data = json_decode($request->getContent(), true);
$userId = $data['userId'] ?? null;

if (!$userId) {
return $this->json(['error' => $translator->trans('User ID not provided')], Response::HTTP_BAD_REQUEST);
}

$extraFieldValue = new ExtraFieldValue('user');
$value = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'legal_accept');
if ($value && isset($value['id'])) {
$extraFieldValue->delete($value['id']);
}

$value = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'termactivated');
if ($value && isset($value['id'])) {
$extraFieldValue->delete($value['id']);
}

return $this->json(['success' => true, 'message' => $translator->trans('Legal acceptance revoked successfully.')]);
}

#[Route('/handle-privacy-request', name: 'chamilo_core_social_handle_privacy_request')]
public function handlePrivacyRequest(
Request $request,
Expand Down
Loading