/*
assign role
@param  int  $id
@param  Request $request
@return json
179543
public function assignRole($id, Request $request)
    {
        $user = AppUser::find($id);

        if (!$user) {
            return response()->json(null, 404);
        }

        $roleIdOrName = $request->roleIdOrName;
        $field = is_numeric($roleIdOrName) ? 'id' : 'name';
        $role = Role::where($field, $roleIdOrName)->first();

        if (!$role) {
            return response()->json(arrayView('phpsoft.users::errors/validation', [
                'errors' => ['Role does not exist.']
            ]), 400);
        }

        $hasRole = $user->hasRole($role->name);

        if ($hasRole) {
            return response()->json(null, 204);
        }

        $user->attachRole($role);

        return response()->json(null, 204);
    }
938279
public function destroy(Request $request, $id)
    {
        // Fetch the role object
        // $id = $this->decode($hash);
        $role = $this->roleRepository->findById($id);

        // Prevent the deletion of roles have the current user as a member
        if (Sentinel::inRole($role)) {
            if ($request->expectsJson()) {
                return response()->json("You must leave this group before it can be removed.", 422);
            }
            session()->flash('error', "You must leave this group before it can be removed.");
            return redirect()->back()->withInput();
        }

        // Remove the role
        $role->delete();

        // All done
        $message = "Role '{$role->name}' has been removed.";
        if ($request->expectsJson()) {
            return response()->json([$message], 200);
        }

        session()->flash('success', $message);
        return redirect()->route('roles.index');
    }
411484
public function putAction(Request $request, $roleId, $key)
    {
        /** @var EntityManagerInterface $entityManager */
        $entityManager = $this->get('doctrine.orm.entity_manager');
        /** @var RoleSettingRepository $repository */
        $repository = $this->get('sulu.repository.role_setting');

        $setting = $repository->findSetting($roleId, $key);
        if (!$setting) {
            $setting = $repository->createNew();
        }

        $setting->setKey($key);
        $setting->setValue($request->get('value', []));
        $setting->setRole($entityManager->getReference(Role::class, $roleId));

        $entityManager->persist($setting);
        $entityManager->flush();

        return $this->handleView($this->view($setting->getValue()));
    }
551331
public function activate(ActivateRequest $request, $id)
    {
        $record    = $this->modelRepository->findOrFail($id);
        $success   = false;
        $result    = null;
        $activated = $request->get('activate');

        if ($this->getModelInformation()->list->activatable) {
            $success = true;
            $result  = $this->changeModelActiveState($record, $activated);
        }

        if ($activated) {
            event( new Events\ModelActivatedInCms($record) );
        } else {
            event( new Events\ModelDeactivatedInCms($record) );
        }

        if (request()->ajax()) {
            return response()->json([ 'success' => $success, 'active' => $result ]);
        }

        if ($success && config('cms-models.notifications.flash.activate')) {
            cms_flash(
                cms_trans(
                    'models.store.success-message-' . ($result ? 'activate' : 'deactivate'),
                    [ 'record' => $this->getSimpleRecordReference($id, $record) ]
                ),
                FlashLevel::SUCCESS
            );
        }

        return redirect()->back();
    }
1277891
public function update($id, RoleRequest $request)
    {
        // Update the role
        $role = Role::findOrFail($id);
        $role->update($request->all());

        // Sync permissions
        $permission_ids = $request->get('permission_id', []);
        $role->permissions()->sync($permission_ids);

        return redirect()->action('\Aginev\Acl\Http\Controllers\RoleController@index')
                         ->with('success', trans('acl::role.edit.updated'));
    }
858354
public function update(Request $request, $id)
    {
        $this->validate($request, ['name' => 'required']);

        $permission = Permission::findOrFail($id);
        $permission->update($request->all());

        return redirect('admin/permissions')->with('flash_message', 'Permission updated!');
    }
507428
public function update(Request $request, $id)
	{
		$entity = UUID::findOrFail($id)->entity;
		return ResourceController::resolveController($entity)->update($entity);
	}
696407
public function update($id, Request $request)
    {
        $entity = $this->getEntityById($id);

        if (!$entity) {
            return $this->response(null, Response::HTTP_NOT_FOUND);
        }

        $params = $request->only($this->fillable);

        $result = $this->manager->update($entity, $params);

        if (!$result->ok()) {
            return $this->response(['errors' => $result->getSimpleErrors()], Response::HTTP_BAD_REQUEST);
        }

        return $this->response($this->serialize($result->getResource(), $request), Response::HTTP_OK);
    }
467207
public function deleteAction(Request $request, $id)
    {
        $locale = $this->getLocale($request);

        $delete = function ($id) use ($locale){
            $this->getManager()->delete($id, $this->getUser()->getId());
        };
        $view = $this->responseDelete($id, $delete);

        return $this->handleView($view);
    }
1134711
public function update(Request $request, $id)
    {
        $this->validate(
            $request,
            [
                'name' => 'required',
                'email' => 'required|string|max:255|email|unique:users,email,' . $id,
                'roles' => 'required'
            ]
        );

        $data = $request->except('password');
        if ($request->has('password')) {
            $data['password'] = bcrypt($request->password);
        }

        $user = User::findOrFail($id);
        $user->update($data);

        $user->roles()->detach();
        foreach ($request->roles as $role) {
            $user->assignRole($role);
        }

        return redirect('admin/users')->with('flash_message', 'User updated!');
    }
475995
public function store(Request $request, $role_id)
    {
    	$role = Role::findOrFail($role_id);
		if (isset($request->permission_id) && count($request->permission_id))
		{
			$role->permissions()->sync($request->permission_id);
		}
		else
		{
			$role->permissions()->sync(array());
		}
		$role->save();
		
		return redirect(url("/role/$role_id/permission"))->with('dp_announce', trans('deeppermission.alert.role_permission.updated'));
    }
986243
public function addAction(Request $request, $id)
    {
        $this->init($request);
        /* @var Node $parentNode */
        $parentNode = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);

        // Check with Acl
        $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $parentNode);

        $parentNodeTranslation = $parentNode->getNodeTranslation($this->locale, true);
        $parentNodeVersion = $parentNodeTranslation->getPublicNodeVersion();
        $parentPage = $parentNodeVersion->getRef($this->em);

        $type = $this->validatePageType($request);
        $newPage = $this->createNewPage($request, $type);
        $newPage->setParent($parentPage);

        /* @var Node $nodeNewPage */
        $nodeNewPage = $this->em->getRepository('KunstmaanNodeBundle:Node')
            ->createNodeFor($newPage, $this->locale, $this->user);
        $nodeTranslation = $nodeNewPage->getNodeTranslation(
            $this->locale,
            true
        );
        $weight = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')
                ->getMaxChildrenWeight($parentNode, $this->locale) + 1;
        $nodeTranslation->setWeight($weight);

        if ($newPage->isStructureNode()) {
            $nodeTranslation->setSlug('');
        }

        $this->em->persist($nodeTranslation);
        $this->em->flush();

        $this->aclManager->updateNodeAcl($parentNode, $nodeNewPage);

        $nodeVersion = $nodeTranslation->getPublicNodeVersion();

        $this->get('event_dispatcher')->dispatch(
            Events::ADD_NODE,
            new NodeEvent(
                $nodeNewPage, $nodeTranslation, $nodeVersion, $newPage
            )
        );

        return $this->redirect(
            $this->generateUrl(
                'KunstmaanNodeBundle_nodes_edit',
                array('id' => $nodeNewPage->getId())
            )
        );
    }
865480
public function rename($id, Request $request)
    {
        $this->authorize('renameCategories');
        $this->validate($request, ['title' => ['required']]);

        $category = $this->model()->find($id);

        return $this->updateModel($category, $request->only(['title', 'description']));
    }
1311468
public function update(UserRequest $request, $id)
    {
        $user = User::findOrFail($id);

        $user->update($request->all());

        if (is_numeric($roles = $request->roleids)) {
            $roles = [$roles];
        }

        if (is_array($roles)) {
            $user->setRolesById($roles);
        }

        return 200;
    }
590932
public function show($id, ShowRequest $request)
    {
        $role = $this->repository->findWithoutFail($id);
        $role->load($request->getWith());

        if (empty($role)) {
            return $this->sendError('Role not found');
        }

        return $this->sendResponse($role, '');
    }
932746
public function update(Request $request, $id)
    {
        try {
            $this->permissionRepositoryInterface->update($request->all(), $id);
        } catch (FormValidationException $e) {
            Flash::error($e->getMessage());

            return redirect()
              ->route('permissions.edit', ['id' => $id])
              ->withErrors($e->getErrors())
              ->withInput();
        } catch (PermissionsException $e) {
            Flash::error($e->getMessage());

            return redirect()->route('permissions.index');
        }

        Flash::success(trans('dashboard::dashboard.flash.permission.edit.success'));

        return redirect()->route('permissions.edit', ['id' => $id]);
    }
1200813
public function removeRolesAction($id, $class, Request $request)
    {
        $object = $this->find($class, $id);
        $roles = $this->decodeIdsString($request, 'Claroline\CoreBundle\Entity\Role');
        $this->crud->patch($object, 'role', Crud::COLLECTION_REMOVE, $roles);

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