Skip to content

Commit

Permalink
chore: New users cannot send emails
Browse files Browse the repository at this point in the history
  • Loading branch information
geokrety-bot committed Dec 13, 2024
1 parent ada6e92 commit 23c64ae
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tests-qa/acceptance/040_Users/Details/010_Details.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions tests-qa/acceptance/080_Messaging/10_Access.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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

Expand Down
49 changes: 31 additions & 18 deletions tests-qa/acceptance/080_Messaging/20_SendMessage.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions tests-qa/acceptance/ressources/ComponentsLocator.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests-qa/acceptance/ressources/Devel.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions website/app-templates/smarty/blocks/geokret/details.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
{/if}

<div class="btn-group pull-right" role="group">
{if $f3->get('SESSION.CURRENT_USER') and $geokret->owner and $geokret->owner->email}
<button class="btn btn-primary btn-xs" title="{t user=$geokret->owner->username}Send a message to %1{/t}" data-toggle="modal" data-target="#modal" data-type="user-contact-by-geokret" data-id="{$geokret->gkid}">
{if $f3->get('SESSION.CURRENT_USER') and $geokret->owner and $geokret->owner->email and isset($current_user) and $current_user->canSendMail()}
<button id="userContactButton" class="btn btn-primary btn-xs" title="{t user=$geokret->owner->username}Send a message to %1{/t}" data-toggle="modal" data-target="#modal" data-type="user-contact-by-geokret" data-id="{$geokret->gkid}">
{fa icon="envelope"}
</button>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion website/app-templates/smarty/blocks/user/details.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img id="userDetailsTypeIcon" src="{GK_CDN_IMAGES_URL}/log-icons/2/icon.svg" width="25px" height="25px" data-gk-type="" />
{$user|userlink nofilter}
<div class="btn-group pull-right" role="group">
{if $f3->get('SESSION.CURRENT_USER') && !$user->isCurrentUser() && $user->email}
{if $f3->get('SESSION.CURRENT_USER') && !$user->isCurrentUser() && $current_user->canSendMail() && $user->email}
<button id="userContactButton" class="btn btn-primary btn-xs" title="{t user=$user->username}Send a message to %1{/t}" data-toggle="modal" data-target="#modal" data-type="user-contact" data-id="{$user->id}">
{fa icon="envelope"}
</button>
Expand Down
5 changes: 5 additions & 0 deletions website/app/GeoKrety/Controller/Devel/DatabaseSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion website/app/GeoKrety/Controller/Pages/UserContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand All @@ -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;
Expand All @@ -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');
Expand Down
8 changes: 8 additions & 0 deletions website/app/GeoKrety/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
3 changes: 3 additions & 0 deletions website/app/GeoKrety/Service/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 23c64ae

Please sign in to comment.