protected function startup()
 {
     parent::startup();
     if (!($row = $this->addons->find($this->id, $this->auth->isAllowed('addon', 'delete')))) {
         $this->error('Addon not found!');
     }
     $this->addon = Addon::fromActiveRow($row, $this->addonVotes);
     $this->addonVersions->rsort($this->addon->versions);
 }
 /**
  * @param string
  * @return string|NULL
  */
 public function filterOut($vendor)
 {
     $row = $this->addons->findByComposerVendor($vendor)->limit(1)->fetch();
     if (!$row) {
         return NULL;
     }
     $addon = Addon::fromActiveRow($row);
     return $addon->composerVendor;
 }
 /**
  * @param string
  */
 public function renderSitemap($type = 'html')
 {
     $this->template->addons = $this->addons->findAll();
     $this->template->vendors = $this->addons->findVendors();
     $this->template->categories = $this->tags->findMainTags();
     $pages = array();
     foreach (Finder::findFiles('*.texy')->from($this->pagesDataPath) as $file) {
         /** @var \SplFileInfo $file */
         $slug = Strings::substring($file->getRealPath(), Strings::length($this->pagesDataPath) + 1, -5);
         $data = $this->pageProcessor->process(file_get_contents($file->getRealPath()));
         $createdAt = new \DateTime();
         $createdAt->setTimestamp($file->getMTime());
         $pages[] = (object) array('slug' => $slug, 'name' => $data['title'], 'createdAt' => $createdAt);
     }
     $this->template->pages = $pages;
     if ($type == 'xml') {
         $this->setView('sitemap.xml');
     }
 }
 protected function startup()
 {
     parent::startup();
     if ($this->token && $this->addonId) {
         $this->error('Parameters token and addonId must not be present at the same time.', 409);
     }
     if ($this->token) {
         $this->addon = $this->manager->restoreAddon($this->token);
     } elseif ($this->addonId) {
         $deleted = $this->auth->isAllowed('addon', 'delete');
         $row = $this->addons->find($this->addonId, $deleted);
         if (!$row) {
             $this->error('Addon not found.');
         }
         $this->addon = Addon::fromActiveRow($row);
     }
     if ($this->addon && !$this->auth->isAllowed($this->addon, 'manage')) {
         $this->error('You are not allowed to manage this addon.', 403);
     }
 }
 /**
  * Post receive hook, updates addon info
  */
 public function actionPostReceive()
 {
     $post = $this->getRequest()->getPost();
     if (!isset($post['payload'], $post['username'], $post['apiToken'])) {
         $this->error('Invalid request.');
     }
     $response = $this->getHttpResponse();
     try {
         $payload = Json::decode($post['payload']);
         if (!isset($payload->repository->url)) {
             $response->setCode(IResponse::S400_BAD_REQUEST);
             $this->sendJson(array('status' => 'error', 'message' => 'Missing or invalid payload'));
         }
     } catch (\Nette\Utils\JsonException $e) {
         $this->error('Invalid request.');
     }
     $username = $post['username'];
     $token = $post['apiToken'];
     $user = $this->users->findOneByName($username);
     if (!$user || $user->apiToken !== $token) {
         $response->setCode(IResponse::S403_FORBIDDEN);
         $this->sendJson(array('status' => 'error', 'message' => 'Invalid credentials'));
     }
     if (!GitHubImporter::isValid($payload->repository->url)) {
         $response->setCode(IResponse::S400_BAD_REQUEST);
         $this->sendJson(array('status' => 'error', 'message' => 'Could not parse payload repository URL'));
     }
     $repositoryUrl = GitHubImporter::normalizeUrl($payload->repository->url);
     $row = $this->addons->findOneBy(array('repository' => $repositoryUrl));
     if (!$row) {
         $this->error('Addon not found.');
     }
     $addon = Addon::fromActiveRow($row);
     $userIdentity = $this->users->createIdentity($user);
     $importer = $this->importerManager->createFromUrl($addon->repository);
     $this->manager->updateVersions($addon, $importer, $userIdentity);
     $this->sendJson(array('status' => "success"));
 }
예제 #6
0
 /**
  * @param string
  * @return bool
  */
 public function isComposerFullNameUnique($composerFullName)
 {
     $addon = $this->addonsRepo->findOneByComposerFullName($composerFullName);
     return $addon === FALSE;
 }
 public function renderDeleted()
 {
     $this->template->addons = $this->addons->findDeleted();
 }