Create role action

@param  Request $request
@return Response
357478
public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'name'         => 'required|string|max:255|unique:roles',
            'display_name' => 'string|max:255',
            'description'  => 'max:1000'
        ]);

        if ($validator->fails()) {
            return response()->json(arrayView('phpsoft.users::errors/validation', [
                'errors' => $validator->errors()
            ]), 400);
        }

        $role = Role::create($request->all());

        return response()->json(arrayView('phpsoft.users::role/read', [
            'role' => $role
        ]), 201);
    }
445428
public function createAction(Request $request)
    {
        $parentId = $request->get('id');
        $siterootId = $request->get('siteroot_id');
        $elementtypeId = $request->get('element_type_id');
        $afterId = $request->get('prev_id');
        $sortMode = $request->get('sort', 'title');
        $sortDir = $request->get('sort_dir', 'asc');
        $navigation = $request->get('navigation') ? true : false;
        $restricted = $request->get('restricted') ? true : false;
        $masterLanguage = $request->get('masterlanguage');

        $elementService = $this->get('phlexible_element.element_service');
        $treeManager = $this->get('phlexible_tree.tree_manager');

        $tree = $treeManager->getBySiteRootId($siterootId);
        $parentNode = $tree->get($parentId);
        $afterNode = $tree->get($afterId);

        $userId = $this->getUser()->getId();

        $elementSource = $elementService->findElementSource($elementtypeId);

        $element = $elementService->createElement($elementSource, $masterLanguage, $userId);

        $node = $tree->create(
            $parentNode,
            $afterNode,
            'element-'.$elementSource->getType(),
            $element->getEid(),
            [],
            $this->getUser()->getId(),
            $sortMode,
            $sortDir,
            $navigation,
            $restricted
        );

        return new ResultResponse(
            true,
            'Element EID "'.$element->getEid().' ('.$masterLanguage.')" created.',
            [
                'eid' => $element->getEid(),
                'tid' => $node->getId(),
                'master_language' => $masterLanguage,
                'navigation' => $navigation,
                'restricted' => $restricted,
            ]
        );
    }
150029
public function create(Request $request)
    {
        app('soda.interface')->setHeading('New Role');
        app('soda.interface')->breadcrumbs()->addLink(route('soda.roles.index'), 'Roles');

        try {
            $role = $this->roles->newInstance($request);
            $permissionIds = $this->roles->getPermissions();
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => 'role']));
        }

        return soda_cms_view('data.roles.view', compact('role', 'permissionIds'));
    }
1222678
public function createAction(Request $request)
    {
        $title = $request->get('title', null);

        $siterootManager = $this->get('phlexible_siteroot.siteroot_manager');

        $siteroot = new Siteroot();
        foreach (explode(',', $this->container->getParameter('phlexible_gui.languages.available')) as $language) {
            $siteroot->setTitle($language, $title);
        }
        $siteroot
            ->setCreateUserId($this->getUser()->getId())
            ->setCreatedAt(new \DateTime())
            ->setModifyUserId($siteroot->getCreateUserId())
            ->setModifiedAt($siteroot->getCreatedAt());

        $siterootManager->updateSiteroot($siteroot);

        return new ResultResponse(true, 'New Siteroot created.');
    }
823912
public function createAction(Request $request)
        {
            $oUser = new User();
            $form = $this->createCreateForm($oUser);
            $form->handleRequest($request);

            if ($form->isValid()) {

                $factory  = $this->get('security.encoder_factory');
                $encoder  = $factory->getEncoder($oUser);
                $password = $encoder->encodePassword($oUser->getPassword(), $oUser->getSalt());
                $oUser->setPassword($password);
                $oUser->save();

                return $this->redirect($this->generateUrl('backend_system_user'));
            }

            return $this->render('SlashworksBackendBundle:User:new.html.twig', array(
                'entity' => $oUser,
                'form'   => $form->createView(),
            ));
        }
561625
public function createAction(Request $request)
    {
        $title = $request->get('title');

        $filterManager = $this->get('phlexible_message.filter_manager');

        $filter = $filterManager->create();
        $filter
            ->setUserId($this->getUser()->getId())
            ->setTitle($title)
            ->setModifiedAt(new \DateTime())
            ->setCreatedAt(new \DateTime());

        $filterManager->updateFilter($filter);

        return new ResultResponse(true, 'Filter created.');
    }
784719
public function createAction(Request $request)
    {
        $this->denyAccessUnlessGranted('ROLE_ADMIN');

        $locale = new Locale();

        $form = $this->createForm(new LocaleType(), $locale);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($locale);
            $em->flush();

            $this->addFlash('success', 'Locale has been created successfully');

            return $this->redirectToRoute('opifer_cms_locale_edit', ['id' => $locale->getId()]);
        }

        return $this->render('OpiferCmsBundle:Backend/Locale:create.html.twig', [
            'locale' => $locale,
            'form' => $form->createView()
        ]);
    }
525890
protected function form(Request $request, Role $role)
    {
        $abilities = $request->user($this->getGuard())->getManagedAbilities();

        return view('cortex/auth::adminarea.pages.role', compact('role', 'abilities'));
    }
49762
public function addRole(Request $request)
    {
        $user = \App\User::findOrfail($request->user_id);
        $user->assignRole($request->role_name);

        return redirect('scaffold-users/edit/'.$request->user_id);
    }
1328311
public function createAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $entity  = new WPSetup();

        $form = $this->createForm(new WPSetupType($this->container), $entity);
        $form->bind($request);

        if ($form->isValid()) {

            $user = $this->get('security.context')->getToken()->getUser();

            $domain = $form['domain']->getData();
            if(isset($form['user']))
                $domain->setUser($form['user']->getData());

            $em->persist($domain);

            $httpdhost = new HttpdHost();
            $httpdhost->setDomain($domain);

            // Add open_basedir wordpress directory
            $configuration = "
                <Directory '/home/$user/web/$domain/httpdocs'>
                    php_admin_value open_basedir '/home/$user/web/$domain:/srv/httpd/error:/tmp:/var/www/source'
                </Directory>";
            $httpdhost->setConfiguration($configuration);
            $em->persist($httpdhost);

            $validator = $this->get('validator');
            // Add database and user
            $wpdb = new DB();
            $wpdb->setName($user->getUsername().'_wp_'.$httpdhost->getId());
            $em->persist($wpdb);

            $dbuser = new DatabaseUser();
            $dbuser->setUsername($user->getId().'_wp_'.$httpdhost->getId());
            $dbuser->setDb($wpdb);
            $dbuser->setPassword('');
            $em->persist($dbuser);

            $entity->setHttpdHost($httpdhost);
            $entity->setDatabaseUser($dbuser);
            $entity->setEnabled(true);
            $em->persist($entity);

            $em->flush();

            return $this->redirect($this->generateUrl('wpsetup_show', array('id' => $entity->getId())));
        }

        return $this->render('ACSACSPanelWordpressBundle:WPSetup:new.html.twig', array(
            'entity' => $entity,
            'form'   => $form->createView(),
        ));
    }
336868
public function createRowAction(Request $request)
    {
        $container = $this->findContainer(intval($request->attributes->get('containerId')));

        $target = is_null($container->getCopy()) ? $container : $container->getCopy();

        try {
            $row = $this->getEditor()->createDefaultRow([], $target);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

        $this->validate($target);
        $this->persist($target);

        $viewBuilder = $this->getViewBuilder();

        $data = [
            'created'    => $viewBuilder->buildRow($row)->getAttributes()->getId(),
            'containers' => [$viewBuilder->buildContainer($container)],
        ];

        return $this->buildResponse($data, self::SERIALIZE_FULL);
    }
387871
public function rootAction(Request $request)
    {
        $ret = [
            'granted' => $this->reportService->getGranted()
        ];

        $result = Result::create($request, $ret);

        return $result->createResponse();
    }
1215383
public function createWithLimitationAction(Request $request, Role $role, string $policyModule, string $policyFunction): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'update'));
        $form = $this->formFactory->createPolicyWithLimitation(
            (new PolicyCreateData())->setPolicy([
                'module' => $policyModule,
                'function' => $policyFunction,
            ])
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (PolicyCreateData $data) use ($role) {
                $policyCreateStruct = $this->policyCreateMapper->reverseMap($data);
                $roleDraft = $this->roleService->createRoleDraft($role);
                $roleDraft = $this->roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
                $this->roleService->publishRoleDraft($roleDraft);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("New policies in role '%role%' created.") */
                        'policy.add.success',
                        ['%role%' => $role->identifier],
                        'role'
                    )
                );

                return new RedirectResponse($this->generateUrl('ezplatform.role.view', [
                    'roleId' => $role->id,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->render('@ezdesign/admin/policy/create_with_limitation.html.twig', [
            'role' => $role,
            'form' => $form->createView(),
        ]);
    }
1191412
public function createBlockAction(Request $request)
    {
        $row = $this->findRowByRequest($request);
        $type = $request->request->get('type', null);

        try {
            $block = $this->getEditor()->createDefaultBlock($type, [], $row);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

        $this->validate($row);
        $this->persist($row);

        $viewBuilder = $this->getViewBuilder();

        $data = [
            'created' => $viewBuilder->buildBlock($block)->getAttributes()->getId(),
            'rows'    => [$viewBuilder->buildRow($row)],
        ];

        return $this->buildResponse($data, self::SERIALIZE_FULL);
    }
1360567
public function newAction(Request $request)
    {
        $actorClass = $this->container->get('core_manager')->getActorClass();
        $actor = new $actorClass();
        $form = $this->createForm($this->get('core_manager')->getActorBundleName().'\Form\ActorType', $actor);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();

            //crypt password
            $factory = $this->get('security.encoder_factory');
            $encoder = $factory->getEncoder(new BaseActor());
            $encodePassword = $encoder->encodePassword($actor->getPassword(), $actor->getSalt());
            $actor->setPassword($encodePassword);
            $role = $em->getRepository('CoreBundle:Role')->findOneByRole(Role::USER);
            $actor->addRole($role);
            $em->persist($actor);
            $em->flush();

            $filesData = $request->files->get('actor');
            if (isset($filesData['image']['file']) && $filesData['image']['file'] instanceof UploadedFile) {            
                $this->get('core_manager')->uploadProfileImage($actor);
            }
            
            $this->get('session')->getFlashBag()->add('success', 'actor.created');
            
            return $this->redirectToRoute('core_actor_show', array('id' => $actor->getId()));
        }

        return array(
            'entity' => $actor,
            'form' => $form->createView(),
        );
    }
650803
public function bulkDeleteAction(Request $request): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'delete'));
        $form = $this->formFactory->deleteRoles(
            new RolesDeleteData()
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (RolesDeleteData $data) {
                foreach ($data->getRoles() as $roleId => $selected) {
                    $role = $this->roleService->loadRole($roleId);
                    $this->roleService->deleteRole($role);

                    $this->notificationHandler->success(
                        $this->translator->trans(
                            /** @Desc("Role '%role%' removed.") */
                            'role.delete.success',
                            ['%role%' => $role->identifier],
                            'role'
                        )
                    );
                }

                return new RedirectResponse($this->generateUrl('ezplatform.role.list'));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return new RedirectResponse($this->generateUrl('ezplatform.role.list'));
    }
1213824
public function store(Request $request)
    {
        $this->validate($request, ['name' => 'required']);

        $role = Role::create($request->all());
        $role->permissions()->detach();

        if ($request->has('permissions')) {
            foreach ($request->permissions as $permission_name) {
                $permission = Permission::whereName($permission_name)->first();
                $role->givePermissionTo($permission);
            }
        }

        return redirect('admin/roles')->with('flash_message', 'Role added!');
    }