Change email display logic

Logic moved from rules to user model.
This commit is contained in:
Visman 2023-07-29 21:04:08 +07:00
parent dde662fadc
commit edfae72916
5 changed files with 81 additions and 58 deletions

View file

@ -37,13 +37,8 @@ class Email extends Page
return $this->c->Message->message('Bad request');
}
$rules = $this->c->ProfileRules->setUser($this->curUser);
if (
! $rules->viewEmail
|| ! $rules->sendEmail
) {
$message = null === $rules->sendEmail ? 'Form email disabled' : 'Bad request';
if (empty($this->curUser->linkEmail)) {
$message = null === $this->curUser->linkEmail ? 'Form email disabled' : 'Bad request';
return $this->c->Message->message($message);
}

View file

@ -72,6 +72,7 @@ class View extends Profile
$fields[] = [
'type' => 'endwrap',
];
if (
$this->rules->useAvatar
&& $this->curUser->avatar
@ -82,6 +83,7 @@ class View extends Profile
'value' => 'avatar',
];
}
$form['sets']['header'] = [
'class' => ['header'],
'legend' => 'Essentials',
@ -109,6 +111,7 @@ class View extends Profile
// личное
$fields = [];
if ('' != $this->curUser->realname) {
$fields['realname'] = [
'class' => ['pline'],
@ -117,10 +120,12 @@ class View extends Profile
'value' => $this->curUser->censorRealname,
];
}
$genders = [
FORK_GEN_MAN => __('Male'),
FORK_GEN_FEM => __('Female'),
];
if (isset($genders[$this->curUser->gender])) {
$fields['gender'] = [
'class' => ['pline'],
@ -129,6 +134,7 @@ class View extends Profile
'caption' => 'Gender',
];
}
if ('' != $this->curUser->location) {
$fields['location'] = [
'class' => ['pline'],
@ -137,6 +143,7 @@ class View extends Profile
'value' => $this->curUser->censorLocation,
];
}
if (! empty($fields)) {
$form['sets']['personal'] = [
'class' => ['data'],
@ -147,6 +154,7 @@ class View extends Profile
// контактная информация
$fields = [];
if ($this->rules->sendPM) {
$this->c->Csrf->setHashExpiration(3600);
@ -166,27 +174,27 @@ class View extends Profile
'href' => $this->c->Router->link('PMAction', $pmArgs),
];
}
if ($this->rules->viewEmail) {
if (0 === $this->curUser->email_setting) {
if (! empty($this->curUser->linkEmail)) {
if (\str_starts_with($this->curUser->linkEmail, 'mailto:')) {
$fields['email'] = [
'class' => ['pline'],
'type' => 'link',
'caption' => 'Email info',
'value' => $this->curUser->censorEmail,
'href' => 'mailto:' . $this->curUser->censorEmail,
'value' => \substr($this->curUser->linkEmail, 7),
'href' => $this->curUser->linkEmail,
];
} elseif ($this->rules->sendEmail) {
$this->c->Csrf->setHashExpiration(3600);
} else {
$fields['email'] = [
'class' => ['pline'],
'type' => 'link',
'caption' => 'Email info',
'value' => __('Send email'),
'href' => $this->c->Router->link('SendEmail', ['id' => $this->curUser->id]),
'href' => $this->curUser->linkEmail,
];
}
}
if (
$this->rules->viewWebsite
&& $this->curUser->url
@ -201,6 +209,7 @@ class View extends Profile
'rel' => 'ugc',
];
}
if (! empty($fields)) {
$form['sets']['contacts'] = [
'class' => ['data'],
@ -212,6 +221,7 @@ class View extends Profile
// подпись
if ($this->rules->useSignature) {
$fields = [];
if ($this->curUser->isSignature) {
$fields['signature'] = [
'type' => 'yield',
@ -221,6 +231,7 @@ class View extends Profile
$this->signatureSection = true;
}
if (! empty($fields)) {
$form['sets']['signature'] = [
'class' => ['data'],
@ -244,6 +255,7 @@ class View extends Profile
'value' => dt($this->curUser->last_post, true),
'caption' => 'Last post info',
];
if ($this->curUser->last_post > 0) {
if (1 === $this->user->g_search) {
$fields['posts'] = [
@ -289,10 +301,12 @@ class View extends Profile
];
}
}
if ($this->rules->viewSubscription) {
$subscr = $this->c->subscriptions;
$subscrInfo = $subscr->info($this->curUser);
$isLink = 1 === $this->user->g_search;
if (! empty($subscrInfo[$subscr::FORUMS_DATA])) {
$fields['forums_subscr'] = [
'class' => ['pline'],
@ -309,6 +323,7 @@ class View extends Profile
'title' => __('Show forums subscriptions'),
];
}
if (! empty($subscrInfo[$subscr::TOPICS_DATA])) {
$fields['topics_subscr'] = [
'class' => ['pline'],
@ -326,6 +341,7 @@ class View extends Profile
];
}
}
$form['sets']['activity'] = [
'class' => ['data'],
'legend' => 'User activity',
@ -334,6 +350,7 @@ class View extends Profile
// приватная информация
$fields = [];
if ($this->rules->viewLastVisit) {
$fields['lastvisit'] = [
'class' => ['pline'],
@ -344,6 +361,7 @@ class View extends Profile
'caption' => 'Last visit info',
];
}
if ($this->rules->viewOEmail) {
$fields['open-email'] = [
'class' => $this->curUser->email_confirmed ? ['pline', 'confirmed'] : ['pline', 'unconfirmed'],
@ -353,6 +371,7 @@ class View extends Profile
'href' => 'mailto:' . $this->curUser->censorEmail,
];
}
if (
$this->rules->viewIP
&& false !== \filter_var($this->curUser->registration_ip, \FILTER_VALIDATE_IP)
@ -371,13 +390,13 @@ class View extends Profile
'title' => __('IP title'),
];
}
$form['sets']['private'] = [
'class' => ['data'],
'legend' => 'Private information',
'fields' => $fields,
];
return $form;
}
}

View file

@ -62,20 +62,6 @@ class Profile extends Rules
return $this->my || $this->user->isAdmMod;
}
protected function getviewEmail(): bool
{
return ! $this->my
&& (
$this->user->isAdmMod // ???? модераторы у админов должны видеть email?
|| (
! $this->user->isGuest
&& ! $this->user->isAdmMod
&& 1 === $this->user->g_send_email
&& $this->curUser->email_setting < 2
)
);
}
protected function geteditEmail(): bool
{
return $this->my || $this->admin;
@ -86,21 +72,6 @@ class Profile extends Rules
return $this->my && ! $this->curUser->email_confirmed;
}
protected function getsendEmail(): ?bool // ???? проверка на подтвержденный email?
{
if ($this->viewEmail) {
if ($this->user->isAdmMod) {
return true;
} elseif (1 === $this->curUser->email_setting) {
return true;
}
} elseif (2 === $this->curUser->email_setting) {
return null;
}
return false;
}
protected function getsendPM(): bool
{
return ! $this->my

View file

@ -30,13 +30,14 @@ class User extends DataModel
parent::__construct($container);
$this->zDepend = [
'group_id' => ['isUnverified', 'isGuest', 'isAdmin', 'isAdmMod', 'isBanByName', 'link', 'usePM'],
'id' => ['isGuest', 'link', 'online'],
'group_id' => ['isUnverified', 'isGuest', 'isAdmin', 'isAdmMod', 'isBanByName', 'link', 'usePM', 'linkEmail'],
'id' => ['isGuest', 'link', 'online', 'linkEmail'],
'last_visit' => ['currentVisit'],
'signature' => ['isSignature'],
'email' => ['email_normal'],
'email' => ['email_normal', 'linkEmail'],
'username' => ['username_normal'],
'g_pm' => ['usePM'],
'email_setting' => ['linkEmail'],
];
}
@ -366,4 +367,41 @@ class User extends DataModel
|| $this->isAdmin
);
}
/**
* Формирует ссылку на отправку письма от $this->c->user к $this
* ???? Результат используется как условие для вариантов отображения
*/
protected function getlinkEmail(): ?string
{
if (
$this->c->user->isGuest
|| $this->id === $this->c->user->id
|| empty($this->email)
) {
return '';
} elseif (2 === $this->email_setting) {
return null;
} elseif (
0 === $this->email_setting
|| (
$this->isGuest
&& $this->c->user->isAdmMod
)
) {
return 'mailto:' . $this->censorEmail;
} elseif (
1 === $this->email_setting
&& (
1 === $this->c->user->g_send_email
|| $this->c->user->isAdmin
)
) {
$this->c->Csrf->setHashExpiration(3600);
return $this->c->Router->link('SendEmail', ['id' => $this->id]);
} else {
return '';
}
}
}

View file

@ -115,8 +115,8 @@
@if ($post->user->url)
<li class="f-user-contacts f-website"><a href="{{ $post->user->censorUrl }}" title="{{ __('Website title') }}" rel="ugc"><span class="f-psfont">{!! __('Website') !!}</span></a></li>
@endif
@if (($post->user->isGuest && $post->user->email && $p->user->isAdmMod) || 0 === $post->user->email_setting)
<li class="f-user-contacts f-email"><a href="mailto:{{ $post->user->censorEmail }}" title="{{ __('Email title') }}" rel="ugc"><span class="f-psfont">{!! __('Email ') !!}</span></a></li>
@if ($post->user->linkEmail)
<li class="f-user-contacts f-email"><a href="{{ $post->user->linkEmail }}" title="{{ __('Email title') }}" rel="ugc"><span class="f-psfont">{!! __('Email ') !!}</span></a></li>
@endif
</ul>
@endif