Skip to content

Commit 7c8d10b

Browse files
authored
Feature: Add marketing opt-in (#957)
1 parent d1846ee commit 7c8d10b

File tree

47 files changed

+1403
-1040
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1403
-1040
lines changed

backend/app/DomainObjects/Generated/UserDomainObjectAbstract.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ abstract class UserDomainObjectAbstract extends \HiEvents\DomainObjects\Abstract
2323
final public const PENDING_EMAIL = 'pending_email';
2424
final public const TIMEZONE = 'timezone';
2525
final public const LOCALE = 'locale';
26+
final public const MARKETING_OPTED_IN_AT = 'marketing_opted_in_at';
2627

2728
protected int $id;
2829
protected string $email;
@@ -37,6 +38,7 @@ abstract class UserDomainObjectAbstract extends \HiEvents\DomainObjects\Abstract
3738
protected ?string $pending_email = null;
3839
protected string $timezone;
3940
protected string $locale = 'en';
41+
protected ?string $marketing_opted_in_at = null;
4042

4143
public function toArray(): array
4244
{
@@ -54,6 +56,7 @@ public function toArray(): array
5456
'pending_email' => $this->pending_email ?? null,
5557
'timezone' => $this->timezone ?? null,
5658
'locale' => $this->locale ?? null,
59+
'marketing_opted_in_at' => $this->marketing_opted_in_at ?? null,
5760
];
5861
}
5962

@@ -199,4 +202,15 @@ public function getLocale(): string
199202
{
200203
return $this->locale;
201204
}
205+
206+
public function setMarketingOptedInAt(?string $marketing_opted_in_at): self
207+
{
208+
$this->marketing_opted_in_at = $marketing_opted_in_at;
209+
return $this;
210+
}
211+
212+
public function getMarketingOptedInAt(): ?string
213+
{
214+
return $this->marketing_opted_in_at;
215+
}
202216
}

backend/app/Http/Actions/Accounts/CreateAccountAction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function __invoke(CreateAccountRequest $request): JsonResponse
5050
? $request->validated('locale')
5151
: $this->localeService->getLocaleOrDefault($request->getPreferredLanguage()),
5252
'invite_token' => $request->validated('invite_token'),
53+
'marketing_opt_in' => (bool) $request->validated('marketing_opt_in'),
5354
]));
5455
} catch (EmailAlreadyExists $e) {
5556
throw ValidationException::withMessages([

backend/app/Http/Actions/Users/UpdateMeAction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function __invoke(UpdateMeRequest $request): JsonResponse
3636
'current_password' => $request->validated('current_password'),
3737
'timezone' => $request->validated('timezone'),
3838
'locale' => $request->validated('locale'),
39+
'marketing_opt_in' => $request->has('marketing_opt_in') ? (bool) $request->validated('marketing_opt_in') : null,
3940
]));
4041

4142
return $this->resourceResponse(UserResource::class, $user);

backend/app/Http/Request/Account/CreateAccountRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function rules(): array
2525
'currency_code' => [Rule::in(array_values($currencies))],
2626
'locale' => ['nullable', Rule::in(Locale::getSupportedLocales())],
2727
'invite_token' => ['nullable', 'string'],
28+
'marketing_opt_in' => 'boolean|nullable',
2829
];
2930
}
3031
}

backend/app/Http/Request/User/UpdateMeRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function rules(): array
3030
'confirmed',
3131
Password::min(8)
3232
],
33+
'marketing_opt_in' => 'boolean|nullable',
3334
];
3435
}
3536
}

backend/app/Resources/User/UserResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function toArray(Request $request): array
3333
'is_email_verified' => $this->getEmailVerifiedAt() !== null,
3434
'has_pending_email_change' => $this->getPendingEmail() !== null,
3535
'locale' => $this->getLocale(),
36+
'marketing_opted_in_at' => $this->getMarketingOptedInAt(),
3637
$this->mergeWhen($isImpersonating, [
3738
'is_impersonating' => true,
3839
'impersonator_id' => $impersonatorId,

backend/app/Services/Application/Handlers/Account/CreateAccountHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function handle(CreateAccountDTO $accountData): AccountDomainObject
7676
'timezone' => $this->getTimezone($accountData),
7777
'email_verified_at' => $isSaasMode ? null : now()->toDateTimeString(),
7878
'locale' => $accountData->locale,
79+
'marketing_opted_in_at' => $accountData->marketing_opt_in ? now()->toDateTimeString() : null,
7980
]);
8081

8182
$this->accountUserAssociationService->associate(

backend/app/Services/Application/Handlers/Account/DTO/CreateAccountDTO.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function __construct(
1515
public readonly ?string $timezone = null,
1616
public readonly ?string $currency_code = null,
1717
public readonly ?string $invite_token = null,
18+
public readonly bool $marketing_opt_in = false,
1819
)
1920
{
2021
}

backend/app/Services/Application/Handlers/Auth/AcceptInvitationHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private function acceptInvitation(AcceptInvitationDTO $invitationData): void
6666
'password' => $this->hasher->make($invitationData->password),
6767
'timezone' => $invitationData->timezone,
6868
'email_verified_at' => now(),
69+
'marketing_opted_in_at' => $invitationData->marketing_opt_in ? now()->toDateTimeString() : null,
6970
],
7071
where: [
7172
'id' => $userId,

backend/app/Services/Application/Handlers/Auth/DTO/AcceptInvitationDTO.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ public function __construct(
1010
public readonly string $invitation_token,
1111
public readonly string $first_name,
1212
public readonly ?string $last_name = null,
13-
public readonly string $password,
14-
public readonly string $timezone,
13+
public readonly string $password = '',
14+
public readonly string $timezone = '',
15+
public readonly bool $marketing_opt_in = false,
1516
)
1617
{
1718
}

0 commit comments

Comments
 (0)