Репост в группу где ты не создатель

Добавил репост в группу, где ты не создатель, а так же исправил стиль кода
This commit is contained in:
lalka2016 2023-05-08 14:37:12 +03:00
parent b0ec86edbc
commit 07a1b33722
3 changed files with 34 additions and 24 deletions

View file

@ -466,19 +466,20 @@ final class Wall extends VKAPIRequestHandler
$nPost = new Post; $nPost = new Post;
$nPost->setOwner($this->user->getId()); $nPost->setOwner($this->user->getId());
if($group_id > 0)
{ if($group_id > 0) {
$club = (new ClubsRepo)->get($group_id); $club = (new ClubsRepo)->get($group_id);
if(!$club || !$club->canBeModifiedBy($this->user)) if(!$club)
{
$this->fail(42, "Invalid group"); $this->fail(42, "Invalid group");
}
if(!$club->canBeModifiedBy($this->user))
$this->fail(16, "Access to group denied");
$nPost->setWall($group_id*-1); $nPost->setWall($group_id*-1);
} } else {
else
{
$nPost->setWall($this->user->getId()); $nPost->setWall($this->user->getId());
} }
$nPost->setContent($message); $nPost->setContent($message);
$nPost->setApi_Source_Name($this->getPlatform()); $nPost->setApi_Source_Name($this->getPlatform());
$nPost->save(); $nPost->save();

View file

@ -73,11 +73,17 @@ class Clubs
function getOwnedClubs(int $id): \Traversable function getOwnedClubs(int $id): \Traversable
{ {
# infoapp
$result = DatabaseConnection::i()->getConnection()->query("SELECT * FROM `groups` WHERE `owner` = $id ORDER BY `id`");
$result = DatabaseConnection::i()->getConnection()->query("SELECT * FROM `groups` WHERE `owner` = $id ORDER BY `id`;");
$coadmins = DatabaseConnection::i()->getConnection()->query("SELECT * FROM `group_coadmins` WHERE `user` = $id ORDER BY `user`;");
foreach($result as $entry) foreach($result as $entry)
yield $this->get($entry->id); yield $this->get($entry->id);
foreach($coadmins as $coadmin)
yield $this->get($coadmin->club);
} }
use \Nette\SmartObject; use \Nette\SmartObject;
} }

View file

@ -707,23 +707,26 @@ final class UserPresenter extends OpenVKPresenter
$this->redirect("/settings"); $this->redirect("/settings");
} }
} }
function renderOwnedClubs(int $id) function renderOwnedClubs(int $id)
{ {
if($this->user->id == $id)
{
$this->assertUserLoggedIn(); $this->assertUserLoggedIn();
$clubs = iterator_to_array((new Clubs)->getOwnedClubs($id));
$json = array(); if($this->user->id == $id) {
foreach($clubs as $club) $clubs = iterator_to_array((new Clubs)->getOwnedClubs($id));
{ $json = [];
$json[]=array("name"=>$club->getName(),"id"=>$club->getId());
} foreach($clubs as $club)
$this->returnJson($json); $json[] = [
} "name" => $club->getName(),
else "id" => $club->getId()
{ ];
$this->returnJson($json);
} else {
$this->returnJson(["You are not allowed to see user-created groups"]); $this->returnJson(["You are not allowed to see user-created groups"]);
} }
} }
} }