From 23c64ae00cc0ad3cab863633d669c7108efa4166 Mon Sep 17 00:00:00 2001 From: geokrety-bot Date: Thu, 12 Dec 2024 14:47:52 +0100 Subject: [PATCH] chore: New users cannot send emails --- .../040_Users/Details/010_Details.robot | 2 +- .../acceptance/080_Messaging/10_Access.robot | 9 ++++ .../080_Messaging/20_SendMessage.robot | 49 ++++++++++++------- .../ressources/ComponentsLocator.robot | 1 + tests-qa/acceptance/ressources/Devel.robot | 5 ++ .../smarty/blocks/geokret/details.tpl | 4 +- .../smarty/blocks/user/details.tpl | 2 +- .../Controller/Devel/DatabaseSeed.php | 5 ++ .../GeoKrety/Controller/Pages/UserContact.php | 12 ++++- website/app/GeoKrety/Model/User.php | 8 +++ website/app/GeoKrety/Service/Config.php | 3 ++ 11 files changed, 77 insertions(+), 23 deletions(-) diff --git a/tests-qa/acceptance/040_Users/Details/010_Details.robot b/tests-qa/acceptance/040_Users/Details/010_Details.robot index e7a1e1ed71..5d535bb9d1 100644 --- a/tests-qa/acceptance/040_Users/Details/010_Details.robot +++ b/tests-qa/acceptance/040_Users/Details/010_Details.robot @@ -58,7 +58,7 @@ Has Public Information Go To Url ${url} Element Should Contain ${USER_PROFILE_USERNAME} ${user.name} Page Should Contain Element ${USER_PROFILE_JOIN_TIME_LABEL} - Element Should Contain ${USER_PROFILE_JOIN_TIME} second + Element Should Contain ${USER_PROFILE_JOIN_TIME} 1 week ago Page Should Contain Element ${USER_PROFILE_LANGUAGE_LABEL} Element Should Contain ${USER_PROFILE_LANGUAGE} English diff --git a/tests-qa/acceptance/080_Messaging/10_Access.robot b/tests-qa/acceptance/080_Messaging/10_Access.robot index 5f81fe6c48..80c3fb51c7 100644 --- a/tests-qa/acceptance/080_Messaging/10_Access.robot +++ b/tests-qa/acceptance/080_Messaging/10_Access.robot @@ -65,6 +65,14 @@ Users Without A Validated Email Cannot Be Contacted Go To Url ${PAGE_USER_3_CONTACT_URL} redirect=${PAGE_USER_3_PROFILE_URL} Page Should Contain This user has no valid email +New Users Cannot Contact + Sign In ${USER_4.name} Fast + Go To Url ${PAGE_USER_1_PROFILE_URL} + Page Should Not Contain Element ${USER_PROFILE_CONTACT_BUTTON} + + Go To Url ${PAGE_GEOKRETY_1_DETAILS_URL} + Page Should Not Contain Element ${GEOKRET_DETAILS_CONTACT_BUTTON} + Access By Not An Id Sign In ${USER_1.name} Fast Go To Url ${PAGE_USER_CONTACT_URL} userid=FOOBAR redirect=${PAGE_HOME_URL_EN} @@ -81,6 +89,7 @@ Access By GeoKrety Not An Id Test Setup Clear Database And Seed ${2} users Seed ${1} users with email status ${1} start_at=3 + Seed ${1} users with joined_days_ago ${1} start_at=4 Seed ${1} geokrety owned by ${1} Sign Out Fast diff --git a/tests-qa/acceptance/080_Messaging/20_SendMessage.robot b/tests-qa/acceptance/080_Messaging/20_SendMessage.robot index 55b81dd379..e98c9b32ef 100644 --- a/tests-qa/acceptance/080_Messaging/20_SendMessage.robot +++ b/tests-qa/acceptance/080_Messaging/20_SendMessage.robot @@ -8,27 +8,46 @@ Suite Setup Suite Setup ${SUBJECT} HELLO! ${MESSAGE} 🎉 Welcome to GeoKrety.org! +&{MESSAGE_2} subject=Subject message=The message *** Test Cases *** +Send Message Via User Contact Fresh Users + Sign In ${USER_3.name} Fast + Go To Url ${PAGE_USER_CONTACT_URL} userid=${USER_1.id} redirect=${PAGE_HOME_URL_EN} + + +Send Message Via User Contact Fresh Users Post + Sign In ${USER_3.name} Fast + Go To Url ${PAGE_USER_1_CONTACT_URL} redirect=${PAGE_HOME_URL_EN} + + Create Session gk ${GK_URL} + ${auth} = GET On Session gk /devel/users/${USER_3.name}/login + ${resp} = POST On Session gk url=${PAGE_USER_1_CONTACT_URL}?skip_csrf=True + ... data=&{MESSAGE_2} + ${url} = Convert To String ${resp.url} + Should Be Equal As Strings ${url} ${PAGE_HOME_URL_EN} + Delete All Sessions + Send Message Via User Contact - Sign In ${USER_1.name} Fast - Go To Url ${PAGE_USER_CONTACT_URL} userid=${USER_2.id} + Sign In ${USER_2.name} Fast + Go To Url ${PAGE_USER_CONTACT_URL} userid=${USER_1.id} Input Text ${USER_CONTACT_SUBJECT_INPUT} ${SUBJECT} Input Text ${USER_CONTACT_MESSAGE_INPUT} ${MESSAGE} Click Button ${MODAL_PANEL_SUBMIT_BUTTON} + Page Should Contain Your message to ${USER_1.name} has been sent Go To Url ${PAGE_DEV_MAILBOX_URL} - Element Should Contain ${DEV_MAILBOX_FIRST_MAIL_LINK} 💌 Contact from user ${USER_1.name} + Element Should Contain ${DEV_MAILBOX_FIRST_MAIL_LINK} 💌 Contact from user ${USER_2.name} Go To Url ${PAGE_DEV_MAILBOX_FIRST_MAIL_URL} Page Should Contain Contact from a GeoKrety.org user - Page Should Contain Hi ${USER_2.name} - Page Should Contain This email was sent by user ${USER_1.name} + Page Should Contain Hi ${USER_1.name} + Page Should Contain This email was sent by user ${USER_2.name} Page Should Contain Subject: ${SUBJECT} Page Should Contain ${MESSAGE} - Page Should Contain Reply to ${USER_1.name} - Page Should Contain Link ${PAGE_USER_1_CONTACT_URL} + Page Should Contain Reply to ${USER_2.name} + Page Should Contain Link ${PAGE_USER_2_CONTACT_URL} Sending From GeoKret Fill The Subject Sign In ${USER_1.name} Fast @@ -39,15 +58,9 @@ Sending From GeoKret Fill The Subject *** Keywords *** Suite Setup - Clear Database And Seed ${2} users - Seed ${1} geokrety owned by ${2} - Sign Out Fast + Clear Database And Seed ${1} users + Seed ${1} users with joined_days_ago ${10} start_at=2 + Seed ${1} users with joined_days_ago ${1} start_at=3 -Is Authorized - [Arguments] ${username}=${USER_1.name} - Sign In ${username} Fast - Go To Url ${PAGE_GEOKRETY_DETAILS_1_CONTACT_OWNER_URL} - Page Should Not Contain ${UNAUTHORIZED} - Wait Until Panel Contact user - Page Should Contain Element ${USER_CONTACT_SUBJECT_INPUT} - Page Should Contain Element ${USER_CONTACT_MESSAGE_INPUT} + Seed ${1} geokrety owned by ${1} + Sign Out Fast diff --git a/tests-qa/acceptance/ressources/ComponentsLocator.robot b/tests-qa/acceptance/ressources/ComponentsLocator.robot index 66f937199a..910b83d76a 100644 --- a/tests-qa/acceptance/ressources/ComponentsLocator.robot +++ b/tests-qa/acceptance/ressources/ComponentsLocator.robot @@ -47,6 +47,7 @@ ${GEOKRET_CREATE_LABEL_TEMPLATE_SELECT} //*[@id="inputLabelTemplate"] ${GEOKRET_DETAILS_DETAILS_PANEL} //*[@id="geokretyDetailsPanel"] ${GEOKRET_DETAILS_DETAILS_PANEL_HEADING} ${GEOKRET_DETAILS_DETAILS_PANEL}/div[contains(@class, "panel-heading")] ${GEOKRET_DETAILS_DETAILS_PANEL_BODY} ${GEOKRET_DETAILS_DETAILS_PANEL}/div[contains(@class, "panel-body")] +${GEOKRET_DETAILS_CONTACT_BUTTON} //*[@id="userContactButton"] ${GEOKRET_DETAILS_NAME} ${GEOKRET_DETAILS_DETAILS_PANEL}/div[@class="panel-heading"]/a[@data-gk-link="geokret"] ${GEOKRET_DETAILS_TYPE} ${GEOKRET_DETAILS_DETAILS_PANEL}/div[@class="panel-heading"]/small diff --git a/tests-qa/acceptance/ressources/Devel.robot b/tests-qa/acceptance/ressources/Devel.robot index e8944bc71c..d2ba019b0d 100644 --- a/tests-qa/acceptance/ressources/Devel.robot +++ b/tests-qa/acceptance/ressources/Devel.robot @@ -127,6 +127,11 @@ Seed ${count} users with email status ${email_status} Go To Url Fast ${PAGE_SEED_USER}?email_invalid\=${email_status}&i\=${start_at} count=${count} Empty Dev Mailbox Fast +Seed ${count} users with joined_days_ago ${joined_days_ago} + [Arguments] ${start_at}=1 + Go To Url Fast ${PAGE_SEED_USER}?joined_days_ago\=${joined_days_ago}&i\=${start_at} count=${count} + Empty Dev Mailbox Fast + Seed ${count} users without terms of use with status ${status} Go To Url Fast ${PAGE_SEED_USER}/status/${status}/no-terms-of-use count=${count} Empty Dev Mailbox Fast diff --git a/website/app-templates/smarty/blocks/geokret/details.tpl b/website/app-templates/smarty/blocks/geokret/details.tpl index 8a89d019fb..149d02e8df 100644 --- a/website/app-templates/smarty/blocks/geokret/details.tpl +++ b/website/app-templates/smarty/blocks/geokret/details.tpl @@ -29,8 +29,8 @@ {/if}
- {if $f3->get('SESSION.CURRENT_USER') and $geokret->owner and $geokret->owner->email} - {/if} diff --git a/website/app-templates/smarty/blocks/user/details.tpl b/website/app-templates/smarty/blocks/user/details.tpl index 7d66b58776..cb80ab71f0 100644 --- a/website/app-templates/smarty/blocks/user/details.tpl +++ b/website/app-templates/smarty/blocks/user/details.tpl @@ -3,7 +3,7 @@ {$user|userlink nofilter}
- {if $f3->get('SESSION.CURRENT_USER') && !$user->isCurrentUser() && $user->email} + {if $f3->get('SESSION.CURRENT_USER') && !$user->isCurrentUser() && $current_user->canSendMail() && $user->email} diff --git a/website/app/GeoKrety/Controller/Devel/DatabaseSeed.php b/website/app/GeoKrety/Controller/Devel/DatabaseSeed.php index c71ba9c171..1a5992f3c8 100644 --- a/website/app/GeoKrety/Controller/Devel/DatabaseSeed.php +++ b/website/app/GeoKrety/Controller/Devel/DatabaseSeed.php @@ -42,6 +42,11 @@ public function users(\Base $f3, $terms_of_use = true) { if ($terms_of_use) { $user->touch('terms_of_use_datetime'); } + $joined_days = GK_USERS_CONTACT_WAITING_DAYS + 1; + if ($f3->exists('GET.joined_days_ago')) { + $joined_days = $f3->get('GET.joined_days_ago'); + } + $user->joined_on_datetime = (new \DateTime())->sub(\DateInterval::createFromDateString(sprintf('%s day', $joined_days)))->format(GK_DB_DATETIME_FORMAT); if ($user->validate()) { $user->save(); echo sprintf("Create user: %s\n", $user->username); diff --git a/website/app/GeoKrety/Controller/Pages/UserContact.php b/website/app/GeoKrety/Controller/Pages/UserContact.php index 33c9bf55d3..2be5f7cc82 100644 --- a/website/app/GeoKrety/Controller/Pages/UserContact.php +++ b/website/app/GeoKrety/Controller/Pages/UserContact.php @@ -50,6 +50,9 @@ protected function _get(\Base $f3) { } public function get(\Base $f3) { + if (!$this->currentUser->canSendMail()) { + $f3->reroute('@home'); + } if (!$this->currentUser->isEmailValid()) { Danger::message_full_screen(_('Your email address must be validated before you can contact other players.'), _('Action is not possible')); } @@ -58,6 +61,9 @@ public function get(\Base $f3) { } public function get_ajax(\Base $f3) { + if (!$this->currentUser->canSendMail()) { + $f3->reroute('@home'); + } if (!$this->currentUser->isEmailValid()) { Danger::message(_('Your email address must be validated before you can contact other players.'), _('Action is not possible')); exit; @@ -67,11 +73,15 @@ public function get_ajax(\Base $f3) { } public function post(\Base $f3) { + if (!$this->currentUser->canSendMail()) { + $f3->reroute('@home'); + } + // TODO count move number + $this->checkCsrf(); if (!$this->currentUser->isEmailValid()) { Danger::message(_('Your email address must be validated before you can contact other players.'), _('Action is not possible')); exit; } - $this->checkCsrf(); $this->loadToUser($f3); $mail = $this->mail; $mail->subject = $f3->get('POST.subject'); diff --git a/website/app/GeoKrety/Model/User.php b/website/app/GeoKrety/Model/User.php index 75acc216c4..83dd1fb14d 100644 --- a/website/app/GeoKrety/Model/User.php +++ b/website/app/GeoKrety/Model/User.php @@ -340,6 +340,14 @@ public function accountStatusText(): string { return self::ACCOUNT_STATUS_TEXT[$this->account_valid]; } + public function isFreshUser(): bool { + return (new \DateTime())->diff($this->joined_on_datetime)->d <= GK_USERS_CONTACT_WAITING_DAYS; + } + + public function canSendMail(): bool { + return !$this->isFreshUser(); + } + public function emailStatusText(): string { return self::USER_EMAIL_TEXT[$this->email_invalid]; } diff --git a/website/app/GeoKrety/Service/Config.php b/website/app/GeoKrety/Service/Config.php index a8b9854eb8..d93e29693d 100644 --- a/website/app/GeoKrety/Service/Config.php +++ b/website/app/GeoKrety/Service/Config.php @@ -370,6 +370,9 @@ public function __construct() { define('GK_PICTURE_CAPTION_MAX_LENGTH', getenv('GK_PICTURE_CAPTION_MAX_LENGTH') ?: 50); define('GK_MOVE_COMMENT_MAX_LENGTH', getenv('GK_MOVE_COMMENT_MAX_LENGTH') ?: 5120); + // USERS + define('GK_USERS_CONTACT_WAITING_DAYS', (int) getenv('GK_USERS_CONTACT_WAITING_DAYS') ?: 7); + // GeoKrety generator define('GK_GENERATOR_MAX_COUNT', getenv('GK_GENERATOR_MAX_COUNT') ?: 100); define('GK_GENERATOR_TRACKING_CODE_ALPHABET', getenv('GK_GENERATOR_TRACKING_CODE_ALPHABET') ?: 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789');