-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1256 from claroline/6.x-dev
6.x dev
- Loading branch information
Showing
58 changed files
with
3,349 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Claroline Connect package. | ||
* | ||
* (c) Claroline Consortium <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Claroline\CoreBundle\Command\Dev; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Claroline\CoreBundle\Library\Workspace\Configuration; | ||
|
||
class ApiTestCommand extends ContainerAwareCommand | ||
{ | ||
protected function configure() | ||
{ | ||
$this->setName('claroline:api:test')->setDescription('Tests the api'); | ||
$this->setDefinition( | ||
array( | ||
new InputArgument('host', InputArgument::REQUIRED, 'The host'), | ||
new InputArgument('url', InputArgument::REQUIRED, 'The url'), | ||
new InputArgument('client_name', InputArgument::REQUIRED, 'The client name') | ||
) | ||
); | ||
} | ||
|
||
protected function interact(InputInterface $input, OutputInterface $output) | ||
{ | ||
$params = array( | ||
'host' => 'The host', | ||
'url' => 'The url', | ||
'client_name' => 'The client name' | ||
); | ||
|
||
foreach ($params as $argument => $argumentName) { | ||
if (!$input->getArgument($argument)) { | ||
$input->setArgument( | ||
$argument, $this->askArgument($output, $argumentName) | ||
); | ||
} | ||
} | ||
} | ||
|
||
protected function askArgument(OutputInterface $output, $argumentName) | ||
{ | ||
$argument = $this->getHelper('dialog')->askAndValidate( | ||
$output, | ||
"Enter the {$argumentName}: ", | ||
function ($argument) { | ||
if (empty($argument)) { | ||
throw new \Exception('This argument is required'); | ||
} | ||
|
||
return $argument; | ||
} | ||
); | ||
|
||
return $argument; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$apiManager = $this->getContainer()->get('claroline.manager.api_manager'); | ||
$host = $input->getArgument('host'); | ||
$url = $input->getArgument('url'); | ||
$clientName = $input->getArgument('client_name'); | ||
$client = $this->getContainer()->get('claroline.manager.oauth_manager')->findClientBy(array('name' => $clientName)); | ||
$response = $apiManager->url($host, $url, $client->getConcatRandomId(), $client->getSecret()); | ||
echo $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Claroline Connect package. | ||
* | ||
* (c) Claroline Consortium <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Claroline\CoreBundle\Controller\API; | ||
|
||
use FOS\RestBundle\Util\Codes; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
class ApiController extends Controller | ||
{ | ||
/** | ||
* @Route("/connected_user") | ||
*/ | ||
public function connectedUserAction() | ||
{ | ||
/** @var \Symfony\Component\Security\Core\SecurityContext $securityContext */ | ||
$tokenStorage = $this->container->get('security.token_storage'); | ||
$securityToken = $tokenStorage->getToken(); | ||
|
||
if (null !== $securityToken) { | ||
/** @var \Claroline\CoreBundle\Entity\User $user */ | ||
$user = $securityToken->getUser(); | ||
|
||
if($user) { | ||
return new JsonResponse(array( | ||
'id' => $user->getId(), | ||
'username' => $user->getUsername(), | ||
'user_id' => $user->getUsername() . $user->getId() | ||
)); | ||
} | ||
} | ||
|
||
return new JsonResponse(array( | ||
'message' => 'User is not identified' | ||
), Codes::HTTP_NOT_FOUND); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Claroline Connect package. | ||
* | ||
* (c) Claroline Consortium <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Claroline\CoreBundle\Controller\API; | ||
|
||
use JMS\DiExtraBundle\Annotation as DI; | ||
use FOS\RestBundle\Controller\FOSRestController; | ||
use Claroline\CoreBundle\Persistence\ObjectManager; | ||
use Claroline\CoreBundle\Manager\GroupManager; | ||
use Claroline\CoreBundle\Manager\RoleManager; | ||
use Symfony\Component\Form\FormFactory; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use FOS\RestBundle\Controller\Annotations\View; | ||
use Claroline\CoreBundle\Form\GroupType; | ||
use Claroline\CoreBundle\Entity\Group; | ||
use Claroline\CoreBundle\Entity\User; | ||
use Claroline\CoreBundle\Entity\Role; | ||
use Nelmio\ApiDocBundle\Annotation\ApiDoc; | ||
|
||
class GroupController extends FOSRestController | ||
{ | ||
/** | ||
* @DI\InjectParams({ | ||
* "formFactory" = @DI\Inject("form.factory"), | ||
* "groupManager" = @DI\Inject("claroline.manager.group_manager"), | ||
* "roleManager" = @DI\Inject("claroline.manager.role_manager"), | ||
* "request" = @DI\Inject("request"), | ||
* "om" = @DI\Inject("claroline.persistence.object_manager") | ||
* }) | ||
*/ | ||
public function __construct( | ||
FormFactory $formFactory, | ||
GroupManager $groupManager, | ||
RoleManager $roleManager, | ||
ObjectManager $om, | ||
Request $request | ||
) | ||
{ | ||
$this->formFactory = $formFactory; | ||
$this->groupManager = $groupManager; | ||
$this->roleManager = $roleManager; | ||
$this->om = $om; | ||
$this->groupRepository = $this->om->getRepository('ClarolineCoreBundle:Group'); | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* @View(serializerGroups={"api"}) | ||
* @ApiDoc( | ||
* description="Returns the groups list", | ||
* views = {"group"} | ||
* ) | ||
*/ | ||
public function getGroupsAction() | ||
{ | ||
return $this->groupRepository->findAll(); | ||
} | ||
|
||
/** | ||
* @View(serializerGroups={"api"}) | ||
* @ApiDoc( | ||
* description="Returns a group", | ||
* views = {"group"} | ||
* ) | ||
*/ | ||
public function getGroupAction(Group $group) | ||
{ | ||
return $group; | ||
} | ||
|
||
/** | ||
* @View(serializerGroups={"api"}) | ||
* @ApiDoc( | ||
* description="Create a group", | ||
* views = {"group"}, | ||
* input="Claroline\CoreBundle\Form\GroupType" | ||
* ) | ||
*/ | ||
public function postGroupAction() | ||
{ | ||
$groupType = new GroupType(); | ||
$groupType->enableApi(); | ||
$form = $this->formFactory->create($groupType, new Group()); | ||
$form->submit($this->request); | ||
//$form->handleRequest($this->request); | ||
|
||
if ($form->isValid()) { | ||
$group = $form->getData(); | ||
$userRole = $this->roleManager->getRoleByName('ROLE_USER'); | ||
$group->setPlatformRole($userRole); | ||
$this->groupManager->insertGroup($group); | ||
|
||
return $group; | ||
} | ||
|
||
return $form; | ||
} | ||
|
||
/** | ||
* @View(serializerGroups={"api"}) | ||
* @ApiDoc( | ||
* description="Update a group", | ||
* views = {"group"}, | ||
* input="Claroline\CoreBundle\Form\GroupType" | ||
* ) | ||
*/ | ||
public function putGroupAction(Group $group) | ||
{ | ||
$groupType = new GroupType(); | ||
$groupType->enableApi(); | ||
$form = $this->formFactory->create($groupType, $group); | ||
$form->submit($this->request); | ||
//$form->handleRequest($this->request); | ||
|
||
if ($form->isValid()) { | ||
$group = $form->getData(); | ||
$userRole = $this->roleManager->getRoleByName('ROLE_USER'); | ||
$this->groupManager->insertGroup($group); | ||
|
||
return $group; | ||
} | ||
|
||
return $form; | ||
} | ||
|
||
/** | ||
* @View() | ||
* @ApiDoc( | ||
* description="Removes a group", | ||
* views = {"group"}, | ||
* ) | ||
*/ | ||
public function deleteGroupAction(Group $group) | ||
{ | ||
$this->groupManager->deleteGroup($user); | ||
|
||
return array('success'); | ||
} | ||
|
||
/** | ||
* @View() | ||
* @ApiDoc( | ||
* description="Add a role to a group", | ||
* views = {"group"} | ||
* ) | ||
*/ | ||
public function addGroupRoleAction(Group $group, Role $role) | ||
{ | ||
$this->roleManager->associateRole($group, $role, false); | ||
|
||
return array('success'); | ||
} | ||
|
||
/** | ||
* @View() | ||
* @ApiDoc( | ||
* description="Remove a role from a group", | ||
* views = {"group"} | ||
* ) | ||
*/ | ||
public function removeGroupRoleAction(Group $group, Role $role) | ||
{ | ||
$this->roleManager->dissociateRole($group, $role); | ||
|
||
return array('success'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Claroline Connect package. | ||
* | ||
* (c) Claroline Consortium <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Claroline\CoreBundle\Controller\API; | ||
|
||
use JMS\DiExtraBundle\Annotation as DI; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use FOS\RestBundle\Controller\FOSRestController; | ||
use FOS\RestBundle\Controller\Annotations\View; | ||
use Claroline\CoreBundle\Library\Configuration\PlatformConfigurationHandler; | ||
use Nelmio\ApiDocBundle\Annotation\ApiDoc; | ||
|
||
class ParametersController extends FOSRestController | ||
{ | ||
private $request; | ||
|
||
/** | ||
* @DI\InjectParams({ | ||
* "request" = @DI\Inject("request"), | ||
* "ch" = @DI\Inject("claroline.config.platform_config_handler") | ||
* }) | ||
*/ | ||
public function __construct(Request $request, PlatformConfigurationHandler $ch) | ||
{ | ||
$this->request = $request; | ||
$this->ch = $ch; | ||
} | ||
|
||
/** | ||
* @View() | ||
* @ApiDoc( | ||
* description="Update/Add a parameters in the platform_options.yml file", | ||
* views = {"parameters"}, | ||
* parameters={ | ||
* {"name"="parameter_name", "dataType"="any", "required"=true ,"description"="The parameter_name is the parameter you want to change"} | ||
* } | ||
* ) | ||
*/ | ||
public function postParametersAction() | ||
{ | ||
$data = $this->request->request; | ||
|
||
foreach ($data as $parameter => $value) { | ||
$this->ch->setParameter($parameter, $value); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
Oops, something went wrong.