From 5556c88e4402b3ec93f48307d750973928022578 Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko <50026114+maksalees@users.noreply.github.com> Date: Fri, 12 Nov 2021 15:31:23 +0200 Subject: [PATCH] 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 --- Web/Models/Entities/Club.php | 23 ++++++++-- Web/Models/Entities/Manager.php | 5 +++ Web/Presenters/GroupPresenter.php | 46 +++++++++++++++++--- Web/Presenters/templates/Group/Edit.xml | 7 +-- Web/Presenters/templates/Group/Followers.xml | 42 ++++++++++++------ Web/Presenters/templates/Group/View.xml | 12 +++-- Web/static/css/style.css | 3 +- install/sqls/00007-hidden-admins.sql | 2 + locales | 2 +- 9 files changed, 111 insertions(+), 31 deletions(-) create mode 100644 install/sqls/00007-hidden-admins.sql diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 0a4843e9..1da1850e 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -94,6 +94,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 { @@ -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; } diff --git a/Web/Models/Entities/Manager.php b/Web/Models/Entities/Manager.php index 272e9d82..0876e01e 100644 --- a/Web/Models/Entities/Manager.php +++ b/Web/Models/Entities/Manager.php @@ -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; diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index 16ac32ea..16fd6381 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -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(); diff --git a/Web/Presenters/templates/Group/Edit.xml b/Web/Presenters/templates/Group/Edit.xml index aaaeefee..ccc98ea9 100644 --- a/Web/Presenters/templates/Group/Edit.xml +++ b/Web/Presenters/templates/Group/Edit.xml @@ -74,9 +74,10 @@ {_group_administrators_list}: - getAdministratorsListDisplay() == 0}checked{/if}/> {_group_display_only_creator}
- getAdministratorsListDisplay() == 1}checked{/if}/> {_group_display_all_administrators}
- getAdministratorsListDisplay() == 2}checked{/if}/> {_group_dont_display_administrators_list}
+ {var areAllAdminsHidden = $club->getManagersCount(true) == 0} + {_group_display_only_creator}
+ {_group_display_all_administrators}
+ {_group_dont_display_administrators_list}
diff --git a/Web/Presenters/templates/Group/Followers.xml b/Web/Presenters/templates/Group/Followers.xml index 56f041ff..ead3368a 100644 --- a/Web/Presenters/templates/Group/Followers.xml +++ b/Web/Presenters/templates/Group/Followers.xml @@ -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} {$club->getCanonicalName()} » {_followers} + {_all_followers} + {_only_administrators} {/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} - {$x->getCanonicalName()} + {$x instanceof $Manager ? $x->getUser()->getCanonicalName() : $x->getCanonicalName()} {/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))} - + - + - {var manager = $club->getManager($x)} - + - + diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml index af761183..443fdecf 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -116,7 +116,8 @@ -
+ {* Это наверное костыль, ну да ладно *} +
{$author->getCanonicalName()}
@@ -131,10 +132,13 @@
- {tr("administrators", $club->getManagersCount() + 1)} + {tr("administrators", $club->getManagersCount(true))} +
+ {_"all_title"} +
{_"gender"}: {$x->isFemale() ? "женский" : "мужской"}{$user->isFemale() ? "женский" : "мужской"}
{_"registration_date"}: {$x->getRegistrationTime()}{$user->getRegistrationTime()}
{_role}: - {$club->canBeModifiedBy($x) ? tr("administrator") : tr("follower")} + {$club->getOwner()->getId() == $user->getId() ? !$club->isOwnerHidden() || $club->canBeModifiedBy($thisUser) : !is_null($manager) ? tr("administrator") : tr("follower")}
{_comment}: - {if $club->getOwner()->getId() === $x->getId()} + {if $club->getOwner()->getId() === $user->getId()} {$club->getOwnerComment()} {else} {$manager->getComment()} {/if}
{_actions}: - + {if $manager} {_devote} {else} @@ -93,9 +97,21 @@ {_set_comment} {/if} - + {_set_comment} + {if $manager} + | + + {if $manager->isHidden()}{_hidden_yes}{else}{_hidden_no}{/if} + + {/if} + {if $club->getOwner()->getId() == $user->getId()} + | + + {if $club->isOwnerHidden()}{_hidden_yes}{else}{_hidden_no}{/if} + + {/if}