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

[Cursus] Bind existing training to a workspace #2862

Merged
merged 2 commits into from
Oct 3, 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
47 changes: 47 additions & 0 deletions src/plugin/cursus/Controller/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ public function listArchivedAction(Request $request): JsonResponse
));
}

/**
* @Route("/list/existing", name="list_existing", methods={"GET"})
*/
public function listNoWorkspaceAction(Request $request): JsonResponse
{
$this->checkPermission('IS_AUTHENTICATED_FULLY', null, [], true);

$filters = array_merge($request->query->all(), [
'hiddenFilters' => array_merge($this->getDefaultHiddenFilters(), [
'workspace' => null,
]),
]);

$list = $this->crud->list(Course::class, $filters, $this->getOptions()['list']);

return new JsonResponse($list);
}

/**
* @Route("/archive", name="archive", methods={"POST"})
*/
Expand Down Expand Up @@ -244,6 +262,35 @@ public function copyAction(Request $request): JsonResponse
}, $processed));
}

/**
* @Route("/{id}/bind", name="bind_workspace", methods={"PATCH"})
*
* @EXT\ParamConverter("course", class="Claroline\CursusBundle\Entity\Course", options={"mapping": {"id": "uuid"}})
*/
public function bindCourseToWorkspaceAction(Course $course, Request $request): JsonResponse
{
$this->om->startFlushSuite();

$data = $this->decodeRequest($request);

$workspaceData = $data['workspace'] ?? null;
$workspace = null;

if ($workspaceData) {
$workspace = $this->om->getRepository(Workspace::class)->findOneBy(['uuid' => $workspaceData['id']]);
}

if ($this->authorization->isGranted('ADMINISTRATE', $course)) {
$course->setWorkspace($workspace);
} else {
throw new AccessDeniedException();
}

$this->om->endFlushSuite();

return new JsonResponse($this->serializer->serialize($course));
}

/**
* @Route("/{slug}/open", name="open", methods={"GET"})
*
Expand Down
9 changes: 9 additions & 0 deletions src/plugin/cursus/Finder/CourseFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public function configureQueryBuilder(QueryBuilder $qb, array $searches = [], ar
$qb->setParameter($filterName, $filterValue);
break;

case 'workspace':
if (is_null($filterValue)) {
$qb->andWhere('obj.workspace IS NULL');
} else {
$qb->andWhere('obj.workspace = :workspace');
$qb->setParameter('workspace', $filterValue);
}
break;

default:
$this->setDefaults($qb, $filterName, $filterValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ const EmptyCourse = (props) =>
</p>
<CreationType {...props} />
</ContentSizing>

</ToolPage>

EmptyCourse.propTypes = {
path: T.string.isRequired,
canEdit: T.bool.isRequired,
contextId: T.string.isRequired
contextId: T.string
}

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ Course.propTypes = {
SessionTypes.propTypes
)),
registrations: T.shape({
users: T.array.isRequired,
groups: T.array.isRequired,
pending: T.array.isRequired
users: T.array,
groups: T.array,
pending: T.array
}),
participantsView: T.string.isRequired,
switchParticipantsView: T.func.isRequired,
Expand Down
22 changes: 19 additions & 3 deletions src/plugin/cursus/Resources/modules/course/components/type.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,24 @@ const CreationType = (props) => {
description: trans('create_mode_existing_desc', {}, 'cursus'),
displayed: props.contextType === 'workspace',
action: {
type: CALLBACK_BUTTON,
callback: () => true
type: MODAL_BUTTON,
modal: [MODAL_TRAINING_COURSES, {
url: ['apiv2_cursus_course_list_existing'],
selectAction: (selectedCourses) => ({
type: ASYNC_BUTTON,
label: trans('bind', {}, 'actions'),
request: {
url: url(['apiv2_cursus_course_bind_workspace', {id: (selectedCourses && selectedCourses.length > 0) ? selectedCourses[0].id : null}]),
request: {
method: 'PATCH',
body: JSON.stringify({
workspace: props.contextId
})
},
success: () => history.push(props.path)
}
})
}]
},
group: trans('create_mode_group_existing', {}, 'cursus')
}
Expand All @@ -134,7 +150,7 @@ CreationType.propTypes = {
openForm: T.func,
reset: T.func,
contextType: T.string,
contextId: T.object,
contextId: T.string,
modal: T.bool,
fadeModal: T.func
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/cursus/Resources/translations/actions.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"archive_training_confirm_title": "{1} Archive a training | [2,Inf[ Archive multiple trainings",
"archive_training_confirm_message": "{1} Are you sure you want to archive this training? | [2,Inf[ Are you sure you want to archive these %count% trainings?",

"bind": "Bind",

"restore_training": "Restore training",
"restore_training_help": "Restore the training in the list of active trainings.",

Expand Down
2 changes: 2 additions & 0 deletions src/plugin/cursus/Resources/translations/actions.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"archive_training_confirm_title": "{1} Archivage d'une formation | [2,Inf[ Archivage de plusieurs formations",
"archive_training_confirm_message": "{1} Êtes-vous sûr de vouloir archiver cette formation ? | [2,Inf[ Êtes-vous sûr de vouloir archiver ces %count% formations ?",

"bind": "Associer",

"restore_training": "Restaurer la formation",
"restore_training_help": "Permet de restaurer la formation dans la liste des formations actives.",

Expand Down
6 changes: 3 additions & 3 deletions src/plugin/cursus/Serializer/CourseSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ public function serialize(Course $course, array $options = []): array
return $this->panelFacetSerializer->serialize($panelFacet);
}, $course->getPanelFacets()->toArray()),
],
'workspace' => $course->getWorkspace() ?
$this->workspaceSerializer->serialize($course->getWorkspace(), [SerializerInterface::SERIALIZE_MINIMAL]) :
null,
'organizations' => array_map(function (Organization $organization) {
return $this->orgaSerializer->serialize($organization, [SerializerInterface::SERIALIZE_MINIMAL]);
}, $course->getOrganizations()->toArray()),
'children' => array_map(function (Course $child) {
return $this->serialize($child, [SerializerInterface::SERIALIZE_MINIMAL]);
}, $course->getChildren()->toArray()),
'workspace' => $course->getWorkspace() ?
$this->workspaceSerializer->serialize($course->getWorkspace(), [SerializerInterface::SERIALIZE_MINIMAL]) :
null,
]);
}

Expand Down
Loading