/** * Update existing library. * * @return LibraryModel */ public function update($id) { if (!$this->input->get('name') || !$this->input->get('path')) { return new Response($this->app['translator']->trans('fillInAllFields'), 400); } $model = $this->model->find($id); if (!$model || $model->user_id != Sentry::getUser()->id) { return new Response($this->app['translator']->trans('cantEditLibrary'), 403); } $model->fill(array('name' => $this->input->get('name'), 'path' => $this->input->get('path')))->save(); return $model; }
public function matchReportAction(Logger $log, Request $request) { $log->addNotice("Match data received from " . $request->getClientIp()); $teamOneBZIDs = $this->params->get('teamOnePlayers'); $teamTwoBZIDs = $this->params->get('teamTwoPlayers'); $teamOnePlayers = $this->bzidsToIdArray($teamOneBZIDs); $teamTwoPlayers = $this->bzidsToIdArray($teamTwoBZIDs); $teamOne = $this->getTeam($teamOnePlayers); $teamTwo = $this->getTeam($teamTwoPlayers); // If we fail to get the the team ID for either the teams or both reported teams are the same team, we cannot // report the match due to it being illegal. // An invalid team could be found in either or both teams, so we need to check both teams and log the match // failure respectively. $error = true; if (!$teamOne->isValid()) { $log->addNotice("The BZIDs ({$teamOneBZIDs}) were not found on the same team. Match invalidated."); } elseif (!$teamTwo->isValid()) { $log->addNotice("The BZIDs ({$teamTwoBZIDs}) were not found on the same team. Match invalidated."); } else { $error = false; } if ($error) { throw new ForbiddenException("An invalid player was found during the match. Please message a referee to manually report the match."); } if ($teamOne->getId() == $teamTwo->getId()) { $log->addNotice("The '" . $teamOne->getName() . "' team played against each other in an official match. Match invalidated."); throw new ForbiddenException("Holy sanity check, Batman! The same team can't play against each other in an official match."); } $match = Match::enterMatch($teamOne->getId(), $teamTwo->getId(), $this->params->get('teamOneWins'), $this->params->get('teamTwoWins'), $this->params->get('duration'), null, $this->params->get('matchTime'), $teamOnePlayers, $teamTwoPlayers, $this->params->get('server'), $this->params->get('port'), $this->params->get('replayFile'), $this->params->get('mapPlayed')); $log->addNotice("Match reported automatically", array('winner' => array('name' => $match->getWinner()->getName(), 'score' => $match->getScore($match->getWinner())), 'loser' => array('name' => $match->getLoser()->getName(), 'score' => $match->getScore($match->getLoser())), 'eloDiff' => $match->getEloDiff())); // Output the match stats that will be sent back to BZFS return $match->getName(); }
/** * Save a new template to database. * * @return Builder\Themes\ThemesModel */ public function store() { if (!$this->app['sentry']->getUser()->hasAccess('templates.create')) { return new Response($this->app['translator']->trans('noPermTemplateCreate'), 403); } if (!$this->input->get('name')) { return new Response($this->app['translator']->trans('enterNameForTemplate'), 400); } $exists = $this->model->where('user_id', Sentry::getUser()->id)->where('name', $this->input->get('name'))->first(); if ($exists) { return new Response($this->app['translator']->trans('templateWithNameExists'), 400); } $rand = str_random(10); $this->model->user_id = Sentry::getUser()->id; $this->model->name = $this->input->get('name'); $this->model->color = $this->input->get('color'); $this->model->category = $this->input->get('category'); $this->model->thumbnail = 'assets/images/thumbnails/templates/template-' . $rand . '.png'; if ($this->model->save()) { foreach ($this->input->get('pages') as $k => $page) { $pModel = new \Builder\Projects\PageModel(); foreach ($page as $name => $value) { $pModel->{$name} = is_array($value) ? json_encode($value) : $value; } $this->model->pages()->save($pModel); } $model = $this->model->with('pages')->find($this->model->id); $model->thumbId = $rand; return $model; } }
public function assignPermissionsToAll() { if (!$this->sentry->getUser()->hasAccess('superuser') || !$this->input->has('permissions')) { return new Response($this->app['translator']->trans('noPermissionsGeneric'), 403); } UserModel::whereNull('permissions')->update(array('permissions' => $this->input->get('permissions'))); return new Response($this->app['translator']->trans('permissionsUpdated'), 200); }
/** * Delete all images by passed in ids. * * @return Response */ public function deleteMultiple() { if ($this->input->has('ids')) { foreach ($this->input->get('ids') as $id) { if ($img = $this->model->find($id)) { $this->fs->remove($this->app['base_dir'] . '/assets/images/uploads/' . $img->file_name); $this->model->destroy($id); } } } return new Response(json_encode($this->input->get('ids')), 200); }
/** * Apply query parameters to the supplied query builder. * * @param $builder * @param Symfony\Component\HttpFoundation\ParameterBag|League\Fractal\ParamBag $parameters * @return mixed */ protected function applyParameters($builder, $parameters = null) { if (!$parameters) { return $builder; } if ($parameters->get('sort')) { $builder = $this->sortBuilder($builder, $parameters); } if ($parameters->get('limit')) { $builder = $this->limitBuilder($builder, $parameters); } return $builder; }
/** * @dataProvider siteAccessMatchProvider */ public function testOnSiteAccessMatch($pathinfo, $semanticPathinfo, SiteAccess $siteaccess, $expectedAccess) { $container = $this->getContainerMock(); $container->expects($this->exactly(1))->method('get')->with('ezpublish.siteaccess')->will($this->returnValue($siteaccess)); $request = $this->getRequestMock(); $request->expects($this->any())->method('getPathInfo')->will($this->returnValue($pathinfo)); $request->attributes->set('semanticPathinfo', $semanticPathinfo); $mapper = new LegacyMapper(); $mapper->setContainer($container); $bag = new \Symfony\Component\HttpFoundation\ParameterBag(); $mapper->onBuildKernelWebHandler(new PreBuildKernelWebHandlerEvent($bag, $request)); self::assertSame($expectedAccess, $bag->get('siteaccess')); }
/** * Create a new project. * * @return Response */ public function store() { if (!$this->app['sentry']->getUser()->hasAccess('projects.create')) { return new Response($this->app['translator']->trans('noPermProjectCreate'), 403); } if (!$this->input->has('name')) { return new Response($this->app['translator']->trans('projectNameRequired'), 400); } if (Project::where('name', $this->input->get('name'))->first()) { return new Response($this->app['translator']->trans('projectWithNameExists'), 400); } return new Response($this->creator->create($this->input->all()), 201); }
/** * Save a new theme. * * @return void */ public function store() { if (!$this->app['sentry']->getUser()->hasAccess('themes.create')) { return new Response($this->app['translator']->trans('noPermThemeCreate'), 403); } $name = $this->input->get('name'); $data = $this->input->get('theme'); $vars = $this->input->get('vars', array()); //make sure we got a name passed in if (!$name) { return new Response($this->app['translator']->trans('enterNameForTheme'), 400); } $byName = $this->model->where('name', $name)->first(); //if we have an id it means we're gonna need to edit an existing theme if (isset($data['id'])) { $byId = $this->model->find($data['id']); if ($byName && $byName->name != $byId->name) { return new Response($this->app['translator']->trans('themeWithNameExists'), 400); } if ($byId && Sentry::getUser()->id == $byId->user_id) { return new Response($this->theme->update($byId, $this->input->all())); } } else { //update if theme is created by currently logged in user or return an error if ($byName && Sentry::getUser()->id == $byName->user_id) { return new Response($this->theme->update($byName, $this->input->all())); } elseif ($byName) { return new Response($this->app['translator']->trans('themeWithNameExists'), 400); } } //if we didn't return by this point we'll just create a new theme with given data try { $this->theme->create($this->input->all()); } catch (\Less_Exception_Compiler $e) { return new Response($this->app['translator']->trans('errorInTheme'), 400); } return new Response($this->model, 201); }
/** * Export project to remote ftp. * * @param string|int $id * @return Response */ public function exportProjectToFtp($id) { if (!$this->app['sentry']->getUser()->hasAccess('publish')) { return new Response($this->app['translator']->trans('noPermissionsGeneric'), 403); } if (!$this->input->get('host')) { return new Response($this->app['translator']->trans('ftpNoHost'), 400); } if (!$this->input->get('user')) { return new Response($this->app['translator']->trans('ftpNoUsername'), 400); } if (!$this->input->get('password')) { return new Response($this->app['translator']->trans('ftpNoPassword'), 400); } if (!$this->input->get('root')) { return new Response($this->app['translator']->trans('ftpNoFolder'), 400); } try { @$this->export->projectToFtp($id, $this->input->all()); } catch (\Exception $e) { return new Response($e->getMessage(), 400); } return new Response($this->app['translator']->trans('projectExportSuccess'), 200); }
/** * Create a new folder. * * @return Response */ public function store() { $folder = $this->model->create(array('user_id' => Sentry::getUser()->id, 'name' => $this->input->get('name'))); return new Response($folder, 201); }