Improvements related to group admins (#278)

Changes:
1. Add the ability to display only administrators on the page with a list of subscribers
2. Add the ability to hide the fact that the subscriber is an administrator
3. Fix display of large text in the block with the list of administrators
4. Fix display of the number of administrators
This commit is contained in:
Maxim Leshchenko 2021-11-12 15:31:23 +02:00 committed by GitHub
parent 3f74e426be
commit 5556c88e44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 111 additions and 31 deletions

View file

@ -95,6 +95,11 @@ class Club extends RowModel
return is_null($this->getRecord()->owner_comment) ? "" : $this->getRecord()->owner_comment;
}
function isOwnerHidden(): bool
{
return (bool) $this->getRecord()->owner_hidden;
}
function isOwnerClubPinned(): bool
{
return (bool) $this->getRecord()->owner_club_pinned;
@ -274,9 +279,11 @@ class Club extends RowModel
}
}
function getManagers(int $page = 1): \Traversable
function getManagers(int $page = 1, bool $ignoreHidden = false): \Traversable
{
$rels = $this->getRecord()->related("group_coadmins.club")->page($page, 6);
if($ignoreHidden)
$rels = $rels->where("hidden", false);
foreach($rels as $rel) {
$rel = (new Managers)->get($rel->id);
@ -286,13 +293,21 @@ class Club extends RowModel
}
}
function getManager(User $user): ?Manager
function getManager(User $user, bool $ignoreHidden = false): ?Manager
{
return (new Managers)->getByUserAndClub($user->getId(), $this->getId());
$manager = (new Managers)->getByUserAndClub($user->getId(), $this->getId());
if ($ignoreHidden && $manager !== null && $manager->isHidden())
return null;
return $manager;
}
function getManagersCount(): int
function getManagersCount(bool $ignoreHidden = false): int
{
if($ignoreHidden)
return sizeof($this->getRecord()->related("group_coadmins.club")->where("hidden", false)) + (int) !$this->isOwnerHidden();
return sizeof($this->getRecord()->related("group_coadmins.club")) + 1;
}

View file

@ -42,6 +42,11 @@ class Manager extends RowModel
return is_null($this->getRecord()->comment) ? "" : $this->getRecord()->comment;
}
function isHidden(): bool
{
return (bool) $this->getRecord()->hidden;
}
function isClubPinned(): bool
{
return (bool) $this->getRecord()->club_pinned;

View file

@ -83,15 +83,30 @@ final class GroupPresenter extends OpenVKPresenter
{
$this->assertUserLoggedIn();
$this->template->club = $this->clubs->get($id);
$this->template->followers = $this->template->club->getFollowers((int) ($this->queryParam("p") ?? 1));
$this->template->count = $this->template->club->getFollowersCount();
$this->template->paginatorConf = (object) [
"count" => $this->template->count,
"page" => $this->queryParam("p") ?? 1,
"amount" => NULL,
"perPage" => OPENVK_DEFAULT_PER_PAGE,
];
$this->template->club = $this->clubs->get($id);
$this->template->onlyShowManagers = $this->queryParam("onlyAdmins") == "1";
if($this->template->onlyShowManagers) {
$this->template->followers = null;
$this->template->managers = $this->template->club->getManagers((int) ($this->queryParam("p") ?? 1), !$this->template->club->canBeModifiedBy($this->user->identity));
if($this->template->club->canBeModifiedBy($this->user->identity) || !$this->template->club->isOwnerHidden()) {
$this->template->managers = array_merge([$this->template->club->getOwner()], iterator_to_array($this->template->managers));
}
$this->template->count = $this->template->club->getManagersCount();
return;
}
$this->template->followers = $this->template->club->getFollowers((int) ($this->queryParam("p") ?? 1));
$this->template->managers = null;
$this->template->count = $this->template->club->getFollowersCount();
}
function renderModifyAdmin(int $id): void
@ -99,6 +114,7 @@ final class GroupPresenter extends OpenVKPresenter
$user = is_null($this->queryParam("user")) ? $this->postParam("user") : $this->queryParam("user");
$comment = $this->postParam("comment");
$removeComment = $this->postParam("removeComment") === "1";
$hidden = ["0" => false, "1" => true][$this->queryParam("hidden")] ?? null;
//$index = $this->queryParam("index");
if(!$user)
$this->badRequest();
@ -108,10 +124,30 @@ final class GroupPresenter extends OpenVKPresenter
if(!$user || !$club)
$this->notFound();
if(!$club->canBeModifiedBy($this->user->identity ?? NULL) && $club->getOwner()->getId() !== $user->getId())
if(!$club->canBeModifiedBy($this->user->identity ?? NULL))
$this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс.");
if($removeComment) {
if(!is_null($hidden)) {
if($club->getOwner()->getId() == $user->getId()) {
$club->setOwner_Hidden($hidden);
$club->save();
} else {
$manager = (new Managers)->getByUserAndClub($user->getId(), $club->getId());
$manager->setHidden($hidden);
$manager->save();
}
if($club->getManagersCount(true) == 0) {
$club->setAdministrators_List_Display(2);
$club->save();
}
if($hidden) {
$this->flashFail("succ", "Операция успешна", "Теперь " . $user->getCanonicalName() . " будет показываться как обычный подписчик всем кроме других администраторов");
} else {
$this->flashFail("succ", "Операция успешна", "Теперь все будут знать про то что " . $user->getCanonicalName() . " - администратор");
}
} elseif($removeComment) {
if($club->getOwner()->getId() == $user->getId()) {
$club->setOwner_Comment(null);
$club->save();

View file

@ -74,9 +74,10 @@
<span class="nobold">{_group_administrators_list}: </span>
</td>
<td>
<input type="radio" name="administrators_list_display" value="0" {if $club->getAdministratorsListDisplay() == 0}checked{/if}/> {_group_display_only_creator}<br>
<input type="radio" name="administrators_list_display" value="1" {if $club->getAdministratorsListDisplay() == 1}checked{/if}/> {_group_display_all_administrators}<br>
<input type="radio" name="administrators_list_display" value="2" {if $club->getAdministratorsListDisplay() == 2}checked{/if}/> {_group_dont_display_administrators_list}<br>
{var areAllAdminsHidden = $club->getManagersCount(true) == 0}
<input type="radio" name="administrators_list_display" value="0" n:attr="checked => $club->getAdministratorsListDisplay() == 0, disabled => $areAllAdminsHidden" /> {_group_display_only_creator}<br>
<input type="radio" name="administrators_list_display" value="1" n:attr="checked => $club->getAdministratorsListDisplay() == 1, disabled => $areAllAdminsHidden" /> {_group_display_all_administrators}<br>
<input type="radio" name="administrators_list_display" value="2" n:attr="checked => $club->getAdministratorsListDisplay() == 2, disabled => $areAllAdminsHidden" /> {_group_dont_display_administrators_list}<br>
</td>
</tr>

View file

@ -1,5 +1,6 @@
{extends "../@listView.xml"}
{var iterator = $followers}
{var $Manager = openvk\Web\Models\Entities\Manager::class}
{var iterator = $onlyShowManagers ? $managers : $followers}
{var count = $paginatorConf->count}
{var page = $paginatorConf->page}
{var perPage = 6}
@ -9,6 +10,8 @@
{block header}
<a href="{$club->getURL()}">{$club->getCanonicalName()}</a>
» {_followers}
<a n:if="!$onlyShowManagers" href="/club{$club->getId()}/followers?onlyAdmins=1" style="float: right;">{_all_followers}</a>
<a n:if="$onlyShowManagers" href="/club{$club->getId()}/followers" style="float: right;">{_only_administrators}</a>
{/block}
{block actions}
@ -38,49 +41,50 @@
{/block}
{block link|strip|stripHtml}
/id{$x->getId()}
/id{$x instanceof $Manager ? $x->getUserId() : $x->getId()}
{/block}
{block preview}
<img src="{$x->getAvatarURL()}" alt="{$x->getCanonicalName()}" width=75 />
<img src="{$x instanceof $Manager ? $x->getUser()->getAvatarURL() : $x->getAvatarURL()}" alt="{$x instanceof $Manager ? $x->getUser()->getCanonicalName() : $x->getCanonicalName()}" width=75 />
{/block}
{block name}
{$x->getCanonicalName()}
{$x instanceof $Manager ? $x->getUser()->getCanonicalName() : $x->getCanonicalName()}
{/block}
{block description}
{var user = $x instanceof $Manager ? $x->getUser() : $x}
{var manager = $x instanceof $Manager ? $x : $club->getManager($user, !$club->canBeModifiedBy($thisUser))}
<table>
<tbody>
<tr>
<td width="120" valign="top"><span class="nobold">{_"gender"}: </span></td>
<td>{$x->isFemale() ? "женский" : "мужской"}</td>
<td>{$user->isFemale() ? "женский" : "мужской"}</td>
</tr>
<tr>
<td width="120" valign="top"><span class="nobold">{_"registration_date"}: </span></td>
<td>{$x->getRegistrationTime()}</td>
<td>{$user->getRegistrationTime()}</td>
</tr>
<tr>
<td width="120" valign="top"><span class="nobold">{_role}: </span></td>
<td>
{$club->canBeModifiedBy($x) ? tr("administrator") : tr("follower")}
{$club->getOwner()->getId() == $user->getId() ? !$club->isOwnerHidden() || $club->canBeModifiedBy($thisUser) : !is_null($manager) ? tr("administrator") : tr("follower")}
</td>
</tr>
{var manager = $club->getManager($x)}
<tr n:if="$manager && !empty($manager->getComment()) || $club->getOwner()->getId() === $x->getId() && !empty($club->getOwnerComment())">
<tr n:if="$manager && !empty($manager->getComment()) || $club->getOwner()->getId() === $user->getId() && !empty($club->getOwnerComment()) && (!$club->isOwnerHidden() || $club->canBeModifiedBy($thisUser))">
<td width="120" valign="top"><span class="nobold">{_comment}: </span></td>
<td>
{if $club->getOwner()->getId() === $x->getId()}
{if $club->getOwner()->getId() === $user->getId()}
{$club->getOwnerComment()}
{else}
{$manager->getComment()}
{/if}
</td>
</tr>
<tr n:if="$club->canBeModifiedBy($thisUser ?? NULL) && $club->getOwner()->getId() !== $x->getId() || $club->getOwner()->getId() == $x->getId()">
<tr n:if="$club->canBeModifiedBy($thisUser ?? NULL)">
<td width="120" valign="top"><span class="nobold">{_actions}: </span></td>
<td>
<a href="/club{$club->getId()}/setAdmin.jsp?user={$x->getId()}&hash={rawurlencode($csrfToken)}" n:if="$club->getOwner()->getId() !== $x->getId()">
<a href="/club{$club->getId()}/setAdmin.jsp?user={$user->getId()}&hash={rawurlencode($csrfToken)}" n:if="$club->getOwner()->getId() !== $user->getId()">
{if $manager}
{_devote}
{else}
@ -93,9 +97,21 @@
{_set_comment}
</a>
{/if}
<a n:if="$club->getOwner()->getId() === $x->getId()" href="javascript:setClubAdminComment('{$club->getId()}', '{$club->getOwner()->getId()}', '{rawurlencode($csrfToken)}')">
<a n:if="$club->getOwner()->getId() === $user->getId()" href="javascript:setClubAdminComment('{$club->getId()}', '{$club->getOwner()->getId()}', '{rawurlencode($csrfToken)}')">
{_set_comment}
</a>
{if $manager}
|
<a href="/club{$club->getId()}/setAdmin.jsp?user={$user->getId()}&hidden={(int) !$manager->isHidden()}&hash={rawurlencode($csrfToken)}">
{if $manager->isHidden()}{_hidden_yes}{else}{_hidden_no}{/if}
</a>
{/if}
{if $club->getOwner()->getId() == $user->getId()}
|
<a href="/club{$club->getId()}/setAdmin.jsp?user={$user->getId()}&hidden={(int) !$club->isOwnerHidden()}&hash={rawurlencode($csrfToken)}">
{if $club->isOwnerHidden()}{_hidden_yes}{else}{_hidden_no}{/if}
</a>
{/if}
</td>
</tr>
</tbody>

View file

@ -116,7 +116,8 @@
<img class="ava" src="{$author->getAvatarUrl()}" />
</a>
</div>
<div class="info info-without-subtitle-centered" n:if="empty($club->getOwnerComment())">
{* Это наверное костыль, ну да ладно *}
<div n:class="info, strlen($author->getCanonicalName()) < 22 ? info-centered" n:if="empty($club->getOwnerComment())">
<a href="{$author->getURL()}" class="title">{$author->getCanonicalName()}</a>
</div>
<div class="info" n:if="!empty($club->getOwnerComment())">
@ -131,10 +132,13 @@
</div>
<div>
<div class="content_subtitle">
{tr("administrators", $club->getManagersCount() + 1)}
{tr("administrators", $club->getManagersCount(true))}
<div style="float: right;">
<a href="/club{$club->getId()}/followers?onlyAdmins=1">{_"all_title"}</a>
</div>
</div>
<div class="avatar-list">
<div class="avatar-list-item">
<div class="avatar-list-item" n:if="!$club->isOwnerHidden()">
{var author = $club->getOwner()}
<div class="avatar">
<a href="{$author->getURL()}">
@ -146,7 +150,7 @@
<div class="subtitle" n:if="!empty($club->getOwnerComment())">{$club->getOwnerComment()}</div>
</div>
</div>
<div class="avatar-list-item" n:foreach="$club->getManagers(1) as $manager">
<div class="avatar-list-item" n:foreach="$club->getManagers(1, true) as $manager">
{var user = $manager->getUser()}
<div class="avatar">
<a href="{$user->getURL()}">

View file

@ -1480,9 +1480,10 @@ body.scrolled .toTop:hover {
.avatar-list-item .info {
float: left;
padding-left: 8px;
width: 134px;
}
.avatar-list-item .info-without-subtitle-centered {
.avatar-list-item .info-centered {
padding-top: 8px;
}

View file

@ -0,0 +1,2 @@
ALTER TABLE `group_coadmins` ADD COLUMN `hidden` BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `groups` ADD COLUMN `owner_hidden` BOOLEAN NOT NULL DEFAULT FALSE AFTER `owner_comment`;

@ -1 +1 @@
Subproject commit a4003623be856185679a7976423b7914455d8ab9
Subproject commit b1c49d9b3aa7aa0a7421aa853c60af0007196f84