Compare commits

..

No commits in common. "eb81ed7a8213e7d49bb22710420189212ea41b1b" and "b80151583e7d1da3fffeed24d65e24dee65b8432" have entirely different histories.

5 changed files with 4 additions and 50 deletions

View file

@ -160,7 +160,6 @@ const MszMessages = () => {
if(msgsRecipient !== undefined) if(msgsRecipient !== undefined)
msgsRecipient.onUpdate(async info => { msgsRecipient.onUpdate(async info => {
msgsReply.setRecipient(typeof info.id === 'string' ? info.id : ''); msgsReply.setRecipient(typeof info.id === 'string' ? info.id : '');
msgsReply.setWarning(info.ban ? `${(typeof info.name === 'string' ? info.name : 'This user')} has been banned and will be unable to respond to your messages.` : undefined);
}); });
msgsReply.onSubmit(async form => { msgsReply.onSubmit(async form => {

View file

@ -11,8 +11,6 @@ const MszMessagesReply = function(element) {
const parserSelect = form.querySelector('.js-messages-reply-parser'); const parserSelect = form.querySelector('.js-messages-reply-parser');
const saveBtn = form.querySelector('.js-messages-reply-save'); const saveBtn = form.querySelector('.js-messages-reply-save');
const sendBtn = form.querySelector('.js-messages-reply-send'); const sendBtn = form.querySelector('.js-messages-reply-send');
const warnElem = form.querySelector('.js-reply-form-warning');
const warnText = warnElem instanceof Element ? warnElem.querySelector('.js-reply-form-warning-text') : undefined;
let submitHandler; let submitHandler;
form.addEventListener('submit', ev => { form.addEventListener('submit', ev => {
@ -135,18 +133,6 @@ const MszMessagesReply = function(element) {
return { return {
getElement: () => element, getElement: () => element,
setWarning: text => {
if(warnElem === undefined || warnText === undefined)
return;
if(text === undefined) {
warnElem.hidden = true;
warnText.textContent = '';
} else {
warnElem.hidden = false;
warnText.textContent = text;
}
},
setRecipient: userId => { setRecipient: userId => {
for(const field of form.elements) for(const field of form.elements)
if(field.name === 'recipient') { if(field.name === 'recipient') {

View file

@ -10,9 +10,8 @@ use Syokuhou\IConfig;
use Misuzu\{CSRF,Pagination,Perm,Template}; use Misuzu\{CSRF,Pagination,Perm,Template};
use Misuzu\Auth\AuthInfo; use Misuzu\Auth\AuthInfo;
use Misuzu\Parsers\Parser; use Misuzu\Parsers\Parser;
use Misuzu\Perms\Permissions;
use Misuzu\URLs\{URLInfo,URLRegistry}; use Misuzu\URLs\{URLInfo,URLRegistry};
use Misuzu\Users\{UsersContext,UserInfo}; use Misuzu\Users\UsersContext;
class MessagesRoutes extends RouteHandler { class MessagesRoutes extends RouteHandler {
public const FOLDER_META = [ public const FOLDER_META = [
@ -27,8 +26,7 @@ class MessagesRoutes extends RouteHandler {
private URLRegistry $urls, private URLRegistry $urls,
private AuthInfo $authInfo, private AuthInfo $authInfo,
private MessagesContext $msgsCtx, private MessagesContext $msgsCtx,
private UsersContext $usersCtx, private UsersContext $usersCtx
private Permissions $perms
) {} ) {}
private bool $canSendMessages; private bool $canSendMessages;
@ -43,8 +41,7 @@ class MessagesRoutes extends RouteHandler {
if(!$globalPerms->check(Perm::G_MESSAGES_VIEW)) if(!$globalPerms->check(Perm::G_MESSAGES_VIEW))
return 403; return 403;
$this->canSendMessages = $globalPerms->check(Perm::G_MESSAGES_SEND) $this->canSendMessages = $globalPerms->check(Perm::G_MESSAGES_SEND);
&& !$this->usersCtx->hasActiveBan($this->authInfo->getUserInfo());
if($request->getMethod() === 'POST' && $request->isFormContent()) { if($request->getMethod() === 'POST' && $request->isFormContent()) {
$content = $request->getContent(); $content = $request->getContent();
@ -174,7 +171,6 @@ class MessagesRoutes extends RouteHandler {
return [ return [
'id' => $userInfo->getId(), 'id' => $userInfo->getId(),
'name' => $userInfo->getName(), 'name' => $userInfo->getName(),
'ban' => $this->usersCtx->hasActiveBan($userInfo),
'avatar' => $this->urls->format('user-avatar', [ 'avatar' => $this->urls->format('user-avatar', [
'user' => $userInfo->getId(), 'user' => $userInfo->getId(),
'res' => 200, 'res' => 200,
@ -251,19 +247,6 @@ class MessagesRoutes extends RouteHandler {
]); ]);
} }
private function checkCanReceiveMessages(UserInfo|string $userInfo): ?array {
$globalPerms = $this->perms->getPermissions('global', $userInfo);
if(!$globalPerms->check(Perm::G_MESSAGES_VIEW))
return [
'error' => [
'name' => 'msgs:recipient_cannot_recv',
'text' => 'This person is not allowed to receive messages.',
],
];
return null;
}
private function checkMessageFields(string $title, string $body, int $parser): ?array { private function checkMessageFields(string $title, string $body, int $parser): ?array {
if(!Parser::isValid($parser)) if(!Parser::isValid($parser))
return [ return [
@ -365,10 +348,6 @@ class MessagesRoutes extends RouteHandler {
]; ];
} }
$error = $this->checkCanReceiveMessages($recipientInfo);
if($error !== null)
return $error;
$replyToInfo = null; $replyToInfo = null;
if(!empty($replyTo)) { if(!empty($replyTo)) {
try { try {
@ -483,10 +462,6 @@ class MessagesRoutes extends RouteHandler {
], ],
]; ];
$error = $this->checkCanReceiveMessages($messageInfo->getRecipientId());
if($error !== null)
return $error;
$sentAt = $draft ? null : time(); $sentAt = $draft ? null : time();
$msgsDb->updateMessage( $msgsDb->updateMessage(

View file

@ -248,8 +248,7 @@ class MisuzuContext {
$this->urls, $this->urls,
$this->authInfo, $this->authInfo,
$this->messagesCtx, $this->messagesCtx,
$this->usersCtx, $this->usersCtx
$this->perms
)); ));
$routingCtx->register(new \Misuzu\Changelog\ChangelogRoutes( $routingCtx->register(new \Misuzu\Changelog\ChangelogRoutes(

View file

@ -40,11 +40,6 @@
<form class="messages-reply-form js-messages-reply-form"> <form class="messages-reply-form js-messages-reply-form">
{{ input_hidden('recipient', '') }} {{ input_hidden('recipient', '') }}
<div class="warning js-reply-form-warning" hidden>
<div class="warning__content">
<p class="js-reply-form-warning-text"></p>
</div>
</div>
<div class="messages-reply-subject"> <div class="messages-reply-subject">
{{ input_text('title', 'messages-reply-subject-input', '', 'text', 'Subject', true) }} {{ input_text('title', 'messages-reply-subject-input', '', 'text', 'Subject', true) }}
</div> </div>