This commit is contained in:
n1rwana 2021-12-15 20:27:52 +03:00
parent 17937432bc
commit 1d52381654
4 changed files with 32 additions and 4 deletions

View file

@ -3,7 +3,7 @@ namespace openvk\Web\Presenters;
use openvk\Web\Models\Entities\{Club, Photo}; use openvk\Web\Models\Entities\{Club, Photo};
use openvk\Web\Models\Entities\Notifications\ClubModeratorNotification; use openvk\Web\Models\Entities\Notifications\ClubModeratorNotification;
use openvk\Web\Models\Repositories\{Clubs, Users, Albums, Managers}; use openvk\Web\Models\Repositories\{Clubs, Users, Albums, Managers};
use Chandler\Security\Authenticator;
final class GroupPresenter extends OpenVKPresenter final class GroupPresenter extends OpenVKPresenter
{ {
private $clubs; private $clubs;
@ -275,12 +275,19 @@ final class GroupPresenter extends OpenVKPresenter
$this->assertUserLoggedIn(); $this->assertUserLoggedIn();
$this->willExecuteWriteAction(); $this->willExecuteWriteAction();
if($_SERVER['REQUEST_METHOD'] !== "POST")
$this->redirect("/groups".$this->user->id);
if(!Authenticator::verifyHash($this->postParam("password"), $this->user->identity->getChandlerUser()->getRaw()->passwordHash))
$this->flashFail("err", tr("error"), tr("incorrect_password"));
$club = $this->clubs->get($id); $club = $this->clubs->get($id);
$newOwner = (new Users)->get($newOwnerID); $newOwner = (new Users)->get($newOwnerID);
if($this->user->id !== $club->getOwner()->getId()) if($this->user->id !== $club->getOwner()->getId())
$this->flashFail("err", tr("error"), tr("forbidden")); $this->flashFail("err", tr("error"), tr("forbidden"));
$club->setOwner($newOwnerID); $club->setOwner($newOwnerID);
$club->addManager($this->user->id);
$club->save(); $club->save();
$this->flashFail("succ", tr("information_-1"), tr("group_owner_setted", $newOwner->getCanonicalName(), $club->getName())); $this->flashFail("succ", tr("information_-1"), tr("group_owner_setted", $newOwner->getCanonicalName(), $club->getName()));

View file

@ -93,7 +93,7 @@
</a> </a>
{if $club->getOwner()->getId() != $user->getId() && $manager && $thisUser->getId() == $club->getOwner()->getId()} {if $club->getOwner()->getId() != $user->getId() && $manager && $thisUser->getId() == $club->getOwner()->getId()}
| |
<a href="/groups/{$club->getId()}/setNewOwner/{$user->getId()}"> <a href="javascript:changeOwner({$club->getId()}, {$user->getId()})">
{_promote_to_owner} {_promote_to_owner}
</a> </a>
{/if} {/if}
@ -122,4 +122,25 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<script>
function changeOwner(club, newOwner) {
let action = "/groups/" + club + "/setNewOwner/" + newOwner;
MessageBox("Передача прав владельца", `
Внимание! Вы передаёте права владельца пользователю {$user->getFullName()}. После передачи Вы получите роль администратора в сообществе.
<br/><br/>
<form id="transfer-owner-permissions-form" method="post">
<label for="password">Пароль</label>
<input type="password" id="password" name="password" required />
<input type="hidden" name="hash" value={$csrfToken} />
</form>
`, ["Передать", "Отмена"], [
() => {
$('#transfer-owner-permissions-form').attr('action', action);
document.querySelector("#transfer-owner-permissions-form").submit();
}, Function.noop
]);
}
</script>
{/block} {/block}

View file

@ -241,7 +241,7 @@
"group_display_all_administrators" = "Display all administrators"; "group_display_all_administrators" = "Display all administrators";
"group_dont_display_administrators_list" = "Display nothing"; "group_dont_display_administrators_list" = "Display nothing";
"group_owner_setted" = "New owner ($1) has been successfully assigned to community $2. If you want to return the community, please contact the technical support of the site."; "group_owner_setted" = "The new owner ($1) has been successfully assigned to the community $2. You have been granted administrator rights in the community. If you want to return the owner role, contact <a href='/support?act=new'>site technical support</a>.";
"participants_zero" = "No participants"; "participants_zero" = "No participants";
"participants_one" = "$1 participant"; "participants_one" = "$1 participant";

View file

@ -251,7 +251,7 @@
"group_display_all_administrators" = "Отображать всех администраторов"; "group_display_all_administrators" = "Отображать всех администраторов";
"group_dont_display_administrators_list" = "Ничего не отображать"; "group_dont_display_administrators_list" = "Ничего не отображать";
"group_owner_setted" = "Новый владелец ($1) успешно назначен в сообщество $2. Если Вы хотите вернуть сообщество, обратитесь в техническую поддержку сайта."; "group_owner_setted" = "Новый владелец ($1) успешно назначен в сообщество $2. Вам выданы права администратора в сообществе. Если Вы хотите вернуть роль владельца, обратитесь в <a href='/support?act=new'>техническую поддержку сайта</a>.";
"participants_zero" = "Ни одного участника"; "participants_zero" = "Ни одного участника";
"participants_one" = "Один участник"; "participants_one" = "Один участник";