Merge branch 'master' into feature-reports

This commit is contained in:
Alexander Minkin 2023-08-11 16:49:06 +03:00
commit 0b847fd7c5
Signed by untrusted user: WerySkok
GPG key ID: 88E9A2F3AFE44C30
20 changed files with 148 additions and 31 deletions

View file

@ -272,7 +272,7 @@ class Club extends RowModel
return false;
}
return $query;
return $query->group("follower");
}
function getFollowersCount(): int

View file

@ -85,7 +85,7 @@ abstract class Postable extends Attachable
return sizeof(DB::i()->getContext()->table("likes")->where([
"model" => static::class,
"target" => $this->getRecord()->id,
]));
])->group("origin"));
}
# TODO add pagination

View file

@ -39,11 +39,14 @@ class User extends RowModel
$query = "SELECT id FROM\n" . file_get_contents(__DIR__ . "/../sql/$filename.tsql");
$query .= "\n LIMIT " . $limit . " OFFSET " . ( ($page - 1) * $limit );
$ids = [];
$rels = DatabaseConnection::i()->getConnection()->query($query, $id, $id);
foreach($rels as $rel) {
$rel = (new Users)->get($rel->id);
if(!$rel) continue;
if(in_array($rel->getId(), $ids)) continue;
$ids[] = $rel->getId();
yield $rel;
}
}

View file

@ -1,4 +1,4 @@
(SELECT follower AS __id FROM
(SELECT DISTINCT(follower) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
LEFT JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -1,4 +1,4 @@
(SELECT follower AS __id FROM
(SELECT DISTINCT(follower) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
INNER JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -1,4 +1,4 @@
(SELECT follower AS __id FROM
(SELECT DISTINCT(follower) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
INNER JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -1,4 +1,4 @@
(SELECT target AS __id FROM
(SELECT DISTINCT(target) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
RIGHT JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -132,7 +132,8 @@ final class AdminPresenter extends OpenVKPresenter
$club->save();
break;
case "ban":
$club->setBlock_reason($this->postParam("ban_reason"));
$reason = mb_strlen(trim($this->postParam("ban_reason"))) > 0 ? $this->postParam("ban_reason") : NULL;
$club->setBlock_reason($reason);
$club->save();
break;
}

View file

@ -22,6 +22,9 @@ final class CommentPresenter extends OpenVKPresenter
$comment = (new Comments)->get($id);
if(!$comment || $comment->isDeleted()) $this->notFound();
if ($comment->getTarget() instanceof Post && $comment->getTarget()->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if(!is_null($this->user)) $comment->toggleLike($this->user->identity);
@ -48,6 +51,9 @@ final class CommentPresenter extends OpenVKPresenter
else if($entity instanceof Topic)
$club = $entity->getClub();
if ($entity instanceof Post && $entity->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if($_FILES["_vid_attachment"] && OPENVK_ROOT_CONF['openvk']['preferences']['videos']['disableUploading'])
$this->flashFail("err", tr("error"), "Video uploads are disabled by the system administrator.");
@ -130,7 +136,9 @@ final class CommentPresenter extends OpenVKPresenter
if(!$comment) $this->notFound();
if(!$comment->canBeDeletedBy($this->user->identity))
$this->throwError(403, "Forbidden", "У вас недостаточно прав чтобы редактировать этот ресурс.");
if ($comment->getTarget() instanceof Post && $comment->getTarget()->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
$comment->delete();
$this->flashFail(
"succ",

View file

@ -24,10 +24,14 @@ final class GroupPresenter extends OpenVKPresenter
if(!$club) {
$this->notFound();
} else {
$this->template->albums = (new Albums)->getClubAlbums($club, 1, 3);
$this->template->albumsCount = (new Albums)->getClubAlbumsCount($club);
$this->template->topics = (new Topics)->getLastTopics($club, 3);
$this->template->topicsCount = (new Topics)->getClubTopicsCount($club);
if ($club->isBanned()) {
$this->template->_template = "Group/Banned.xml";
} else {
$this->template->albums = (new Albums)->getClubAlbums($club, 1, 3);
$this->template->albumsCount = (new Albums)->getClubAlbumsCount($club);
$this->template->topics = (new Topics)->getLastTopics($club, 3);
$this->template->topicsCount = (new Topics)->getClubTopicsCount($club);
}
$this->template->club = $club;
}
@ -39,7 +43,7 @@ final class GroupPresenter extends OpenVKPresenter
$this->willExecuteWriteAction();
if($_SERVER["REQUEST_METHOD"] === "POST") {
if(!empty($this->postParam("name")))
if(!empty($this->postParam("name")) && mb_strlen(trim($this->postParam("name"))) > 0)
{
$club = new Club;
$club->setName($this->postParam("name"));
@ -72,6 +76,7 @@ final class GroupPresenter extends OpenVKPresenter
$club = $this->clubs->get((int) $this->postParam("id"));
if(!$club) exit("Invalid state");
if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden"));
$club->toggleSubscription($this->user->identity);
@ -83,6 +88,8 @@ final class GroupPresenter extends OpenVKPresenter
$this->assertUserLoggedIn();
$this->template->club = $this->clubs->get($id);
if ($this->template->club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden"));
$this->template->onlyShowManagers = $this->queryParam("onlyAdmins") == "1";
if($this->template->onlyShowManagers) {
$this->template->followers = NULL;
@ -118,6 +125,8 @@ final class GroupPresenter extends OpenVKPresenter
$this->badRequest();
$club = $this->clubs->get($id);
if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden"));
$user = (new Users)->get((int) $user);
if(!$user || !$club)
$this->notFound();
@ -194,6 +203,8 @@ final class GroupPresenter extends OpenVKPresenter
$club = $this->clubs->get($id);
if(!$club || !$club->canBeModifiedBy($this->user->identity))
$this->notFound();
else if ($club->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
else
$this->template->club = $club;
@ -201,7 +212,7 @@ final class GroupPresenter extends OpenVKPresenter
if(!$club->setShortcode( empty($this->postParam("shortcode")) ? NULL : $this->postParam("shortcode") ))
$this->flashFail("err", tr("error"), tr("error_shorturl_incorrect"));
$club->setName(empty($this->postParam("name")) ? $club->getName() : $this->postParam("name"));
$club->setName((empty($this->postParam("name")) || mb_strlen(trim($this->postParam("name"))) === 0) ? $club->getName() : $this->postParam("name"));
$club->setAbout(empty($this->postParam("about")) ? NULL : $this->postParam("about"));
$club->setWall(empty($this->postParam("wall")) ? 0 : 1);
$club->setAdministrators_List_Display(empty($this->postParam("administrators_list_display")) ? 0 : $this->postParam("administrators_list_display"));
@ -255,6 +266,7 @@ final class GroupPresenter extends OpenVKPresenter
{
$photo = new Photo;
$club = $this->clubs->get($id);
if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden"));
if($_SERVER["REQUEST_METHOD"] === "POST" && $_FILES["ava"]["error"] === UPLOAD_ERR_OK) {
try {
$anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"];
@ -343,6 +355,8 @@ final class GroupPresenter extends OpenVKPresenter
$club = $this->clubs->get($id);
if(!$club->canBeModifiedBy($this->user->identity))
$this->notFound();
else if ($club->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
else
$this->template->club = $club;
@ -375,6 +389,7 @@ final class GroupPresenter extends OpenVKPresenter
$this->flashFail("err", tr("error"), tr("incorrect_password"));
$club = $this->clubs->get($id);
if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden"));
$newOwner = (new Users)->get($newOwnerId);
if($this->user->id !== $club->getOwner()->getId())
$this->flashFail("err", tr("error"), tr("forbidden"));

View file

@ -66,7 +66,7 @@ final class PhotosPresenter extends OpenVKPresenter
}
if($_SERVER["REQUEST_METHOD"] === "POST") {
if(empty($this->postParam("name")))
if(empty($this->postParam("name")) || mb_strlen(trim($this->postParam("name"))) === 0)
$this->flashFail("err", tr("error"), tr("error_segmentation"));
else if(strlen($this->postParam("name")) > 36)
$this->flashFail("err", tr("error"), tr("error_data_too_big", "name", 36, "bytes"));
@ -101,7 +101,7 @@ final class PhotosPresenter extends OpenVKPresenter
if(strlen($this->postParam("name")) > 36)
$this->flashFail("err", tr("error"), tr("error_data_too_big", "name", 36, "bytes"));
$album->setName(empty($this->postParam("name")) ? $album->getName() : $this->postParam("name"));
$album->setName((empty($this->postParam("name")) || mb_strlen(trim($this->postParam("name"))) === 0) ? $album->getName() : $this->postParam("name"));
$album->setDescription(empty($this->postParam("desc")) ? NULL : $this->postParam("desc"));
$album->setEdited(time());
$album->save();

View file

@ -385,7 +385,7 @@ final class SupportPresenter extends OpenVKPresenter
$agent->setNumerate((int) $this->postParam("number") ?? NULL);
$agent->setIcon($this->postParam("avatar"));
$agent->save();
$this->flashFail("succ", "Успех", "Профиль отредактирован.");
$this->flashFail("succ", tr("agent_profile_edited"));
} else {
$agent = new SupportAgent;
$agent->setAgent($this->user->identity->getId());
@ -393,7 +393,27 @@ final class SupportPresenter extends OpenVKPresenter
$agent->setNumerate((int) $this->postParam("number") ?? NULL);
$agent->setIcon($this->postParam("avatar"));
$agent->save();
$this->flashFail("succ", "Успех", "Профиль создан. Теперь пользователи видят Ваши псевдоним и аватарку вместо стандартных аватарки и номера.");
$this->flashFail("succ", tr("agent_profile_created_1"), tr("agent_profile_created_2"));
}
}
function renderCloseTicket(int $id): void
{
$this->assertUserLoggedIn();
$this->assertNoCSRF();
$this->willExecuteWriteAction();
$ticket = $this->tickets->get($id);
if($ticket->isDeleted() === 1 || $ticket->getType() === 2 || $ticket->getUserId() !== $this->user->id) {
header("HTTP/1.1 403 Forbidden");
header("Location: /support/view/" . $id);
exit;
}
$ticket->setType(2);
$ticket->save();
$this->flashFail("succ", tr("ticket_changed"), tr("ticket_changed_comment"));
}
}

View file

@ -46,13 +46,13 @@ final class WallPresenter extends OpenVKPresenter
function renderWall(int $user, bool $embedded = false): void
{
$owner = ($user < 0 ? (new Clubs) : (new Users))->get(abs($user));
if ($owner->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if(is_null($this->user)) {
$canPost = false;
} else if($user > 0) {
if(!$owner->isBanned())
$canPost = $owner->getPrivacyPermission("wall.write", $this->user->identity);
else
$this->flashFail("err", tr("error"), tr("forbidden"));
$canPost = $owner->getPrivacyPermission("wall.write", $this->user->identity);
} else if($user < 0) {
if($owner->canBeModifiedBy($this->user->identity))
$canPost = true;
@ -100,6 +100,8 @@ final class WallPresenter extends OpenVKPresenter
} else if($user < 0) {
if($owner->canBeModifiedBy($this->user->identity))
$canPost = true;
else if ($owner->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
else
$canPost = $owner->canPost();
} else {
@ -212,11 +214,12 @@ final class WallPresenter extends OpenVKPresenter
$wallOwner = ($wall > 0 ? (new Users)->get($wall) : (new Clubs)->get($wall * -1))
?? $this->flashFail("err", tr("failed_to_publish_post"), tr("error_4"));
if ($wallOwner->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if($wall > 0) {
if(!$wallOwner->isBanned())
$canPost = $wallOwner->getPrivacyPermission("wall.write", $this->user->identity);
else
$this->flashFail("err", tr("not_enough_permissions"), tr("not_enough_permissions_comment"));
$canPost = $wallOwner->getPrivacyPermission("wall.write", $this->user->identity);
} else if($wall < 0) {
if($wallOwner->canBeModifiedBy($this->user->identity))
$canPost = true;
@ -354,6 +357,9 @@ final class WallPresenter extends OpenVKPresenter
} else {
$this->template->wallOwner = (new Clubs)->get(abs($post->getTargetWall()));
$this->template->isWallOfGroup = true;
if ($this->template->wallOwner->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
}
$this->template->cCount = $post->getCommentsCount();
$this->template->cPage = (int) ($_GET["p"] ?? 1);
@ -368,7 +374,10 @@ final class WallPresenter extends OpenVKPresenter
$post = $this->posts->getPostById($wall, $post_id);
if(!$post || $post->isDeleted()) $this->notFound();
if ($post->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if(!is_null($this->user)) {
$post->toggleLike($this->user->identity);
}
@ -386,6 +395,9 @@ final class WallPresenter extends OpenVKPresenter
if(!$post || $post->isDeleted())
$this->notFound();
if ($post->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
$where = $this->postParam("type") ?? "wall";
$groupId = NULL;
@ -444,6 +456,9 @@ final class WallPresenter extends OpenVKPresenter
$wallOwner = ($wall > 0 ? (new Users)->get($wall) : (new Clubs)->get($wall * -1))
?? $this->flashFail("err", tr("failed_to_delete_post"), tr("error_4"));
if ($wallOwner->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if($wall < 0) $canBeDeletedByOtherUser = $wallOwner->canBeModifiedBy($this->user->identity);
else $canBeDeletedByOtherUser = false;
@ -467,6 +482,9 @@ final class WallPresenter extends OpenVKPresenter
$post = $this->posts->getPostById($wall, $post_id);
if(!$post)
$this->notFound();
if ($post->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if(!$post->canBePinnedBy($this->user->identity))
$this->flashFail("err", tr("not_enough_permissions"), tr("not_enough_permissions_comment"));

View file

@ -0,0 +1,22 @@
{extends "../@layout.xml"}
{block title}{$club->getCanonicalName()}{/block}
{block header}{include title}{/block}
{block content}
<center>
<img src="/assets/packages/static/openvk/img/oof.apng" alt="Сообщество заблокировано." style="width: 20%;"/>
<p>
{tr("group_banned", htmlentities($club->getCanonicalName()))|noescape}
<br/>
{_user_banned_comment} <b>{$club->getBanReason()}</b>.
</p>
{if isset($thisUser)}
<p n:if="$thisUser->getChandlerUser()->can('access')->model('admin')->whichBelongsTo(NULL)">
<br />
<a href="/admin/clubs/id{$club->getId()}?act=ban" target="_blank" class="button">{_edit}</a>
</p>
{/if}
</center>
{/block}

View file

@ -55,7 +55,6 @@
<input name="name" type="text" value="{$agent->getCanonicalName()}" placeholder="{_helpdesk_agent} #777" />
<br/><br/>
<label for="number">{_helpdesk_show_number}?</label>
{$agent->isShowNumber()}
<select name="number">
<option value="1" n:attr="selected => $agent->isShowNumber() === 1 ? true : false">{_yes}</option>
<option value="0" n:attr="selected => $agent->isShowNumber() === 0 ? true : false">{_no}</option>
@ -71,7 +70,7 @@
</div>
</div>
{else}
<h4>Создать</h4>
<h4>{_create}</h4>
<br/>
<form method="post" action="/support/agent{$agent_id}/edit">
<label for="name">{_helpdesk_showing_name}</label>

View file

@ -19,7 +19,7 @@
<a n:attr="id => ($act === 'closed' ? 'act_tab_a' : 'ki')" href="?act=closed">{_support_closed}</a>
</div>
<div class="tab">
<a href="/support/agent{$thisUser->getId()}">Мой профиль</a>
<a href="/support/agent{$thisUser->getId()}">{_agent_profile}</a>
</div>
{/block}

View file

@ -27,6 +27,14 @@
function errorHandler(id, mark) {
document.getElementById("markText-" + id).innerHTML = {_error};
}
function closeTicket() {
let url = `/support/ticket${{$ticket->getId()}}/close?hash=${{urlencode($csrfToken)}}`;
$.ajax(url, {
error: () => alert(tr("error")),
success: () => location.reload()
});
}
</script>
{if $ticket->isDeleted() == 0}
@ -34,6 +42,11 @@
<a href="#" style="font-size:13px;"><b>{$ticket->getName()}</b></a>
<br />{_status}: {$ticket->getStatus()}
</div>
{if $ticket->getType() === 1}
<div class="post-author" style="border-top: none; padding: 14px; margin-top: 14px;">
{_you_can_close_this_ticket_1} <a onClick="closeTicket()">{_you_can_close_this_ticket_2}</a>.
</div>
{/if}
<div class="text" style="padding-top: 10px; border-bottom: #ECECEC solid 1px;">
{$ticket->getText()|noescape}
<br /></br>

View file

@ -35,6 +35,8 @@ routes:
handler: "Support->agent"
- url: "/support/agent{num}/edit"
handler: "Support->editAgent"
- url: "/support/ticket{num}/close"
handler: "Support->closeTicket"
- url: "/language"
handler: "About->language"
- url: "/language/{text}.js"

View file

@ -331,6 +331,8 @@
"search_by_groups" = "Search by groups";
"search_group_desc" = "Here you can browse through the existing groups and choose a group to suit your needs...";
"group_banned" = "Unfortunately, we had to block the <b>$1</b> group.";
/* Albums */
"create" = "Create";
@ -921,6 +923,13 @@
"banned_in_support_1" = "Sorry, <b>$1</b>, but now you can't create tickets.";
"banned_in_support_2" = "And the reason for this is simple: <b>$1</b>. Unfortunately, this time we had to take away this opportunity from you forever.";
"you_can_close_this_ticket_1" = "If you have no more questions, you can ";
"you_can_close_this_ticket_2" = "close this ticket";
"agent_profile_created_1" = "Profile created";
"agent_profile_created_2" = "Now users see your customized name and avatar instead of the default ones.";
"agent_profile_edited" = "Profile edited";
"agent_profile" = "My Agent Card";
/* Invite */
"invite" = "Invite";

View file

@ -314,6 +314,7 @@
"search_group" = "Поиск группы";
"search_by_groups" = "Поиск по группам";
"search_group_desc" = "Здесь Вы можете просмотреть существующие группы и выбрать группу себе по вкусу...";
"group_banned" = "К сожалению, нам пришлось заблокировать сообщество <b>$1</b>.";
/* Albums */
@ -851,6 +852,12 @@
"ticket_changed_comment" = "Изменения вступят силу через несколько секунд.";
"banned_in_support_1" = "Извините, <b>$1</b>, но теперь вам нельзя создавать обращения.";
"banned_in_support_2" = "А причина этому проста: <b>$1</b>. К сожалению, на этот раз нам пришлось отобрать у вас эту возможность навсегда.";
"you_can_close_this_ticket_1" = "Если у Вас больше нет вопросов, Вы можете ";
"you_can_close_this_ticket_2" = "закрыть этот тикет";
"agent_profile_created_1" = "Профиль создан";
"agent_profile_created_2" = "Теперь пользователи видят Ваши псевдоним и аватарку вместо стандартных аватарки и номера.";
"agent_profile_edited" = "Профиль отредактирован";
"agent_profile" = "Карточка агента";
/* Invite */