Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Oct 3, 2024
1 parent eb14d0f commit 3fbb198
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 37 deletions.
40 changes: 14 additions & 26 deletions src/plugin/cursus/Controller/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,18 @@ public function listArchivedAction(Request $request): JsonResponse
/**
* @Route("/list/existing", name="list_existing", methods={"GET"})
*/
public function listExistingAction(Request $request): JsonResponse
public function listNoWorkspaceAction(Request $request): JsonResponse
{
$this->checkPermission('IS_AUTHENTICATED_FULLY', null, [], true);

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

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

$list['data'] = array_filter($list['data'], function (array $course) {
return is_null($course['workspace']);
});

sort($list['data']);

return new JsonResponse($list);
}

Expand Down Expand Up @@ -267,12 +263,12 @@ public function copyAction(Request $request): JsonResponse
}

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

$this->om->startFlushSuite();

$data = $this->decodeRequest($request);
Expand All @@ -281,26 +277,18 @@ public function bindCourseToWorkspaceAction(Request $request): JsonResponse
$workspace = null;

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

/** @var Course[] $courses */
$courses = $this->om->getRepository(Course::class)->findBy([
'uuid' => $data['ids'],
]);

foreach ($courses as $course) {
if ($this->authorization->isGranted('ADMINISTRATE', $course)) {
$course->setWorkspace($workspace);
$processed[] = $course;
}
if ($this->authorization->isGranted('ADMINISTRATE', $course)) {
$course->setWorkspace($workspace);
} else {
throw new AccessDeniedException();
}

$this->om->endFlushSuite();

return new JsonResponse(array_map(function (Course $course) {
return $this->serializer->serialize($course);
}, $processed));
return new JsonResponse($this->serializer->serialize($course));
}

/**
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 @@ -41,7 +41,7 @@ const EmptyCourse = (props) =>
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
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,14 @@ const CreationType = (props) => {
type: MODAL_BUTTON,
modal: [MODAL_TRAINING_COURSES, {
url: ['apiv2_cursus_course_list_existing'],
selectAction: (selected) => ({
selectAction: (selectedCourses) => ({
type: ASYNC_BUTTON,
label: trans('bind', {}, 'actions'),
request: {
url: url(['apiv2_cursus_course_bind_workspace']),
url: url(['apiv2_cursus_course_bind_workspace', {id: (selectedCourses && selectedCourses.length > 0) ? selectedCourses[0].id : null}]),
request: {
method: 'PATCH',
body: JSON.stringify({
ids: selected.map(course => course.id),
workspace: props.contextId
})
},
Expand All @@ -151,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
6 changes: 3 additions & 3 deletions src/plugin/cursus/Serializer/CourseSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ public function serialize(Course $course, array $options = []): array
'users' => $course->getMaxUsers(),
],
'tags' => $this->serializeTags($course),
'workspace' => $course->getWorkspace() ?
$this->workspaceSerializer->serialize($course->getWorkspace(), [SerializerInterface::SERIALIZE_MINIMAL]) :
null,
];

if (!in_array(SerializerInterface::SERIALIZE_TRANSFER, $options)) {
Expand Down Expand Up @@ -173,6 +170,9 @@ public function serialize(Course $course, array $options = []): array
'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

0 comments on commit 3fbb198

Please sign in to comment.