diff --git a/docker/redis/Dockerfile b/docker/redis/Dockerfile
--- a/docker/redis/Dockerfile
+++ b/docker/redis/Dockerfile
@@ -1,4 +1,4 @@
-FROM fedora:30
+FROM fedora:34
ENV container docker
ENV SYSTEMD_PAGER=''
diff --git a/src/.env.example b/src/.env.example
--- a/src/.env.example
+++ b/src/.env.example
@@ -3,10 +3,11 @@
APP_KEY=
APP_DEBUG=true
APP_URL=http://127.0.0.1:8000
+#APP_PASSPHRASE=
APP_PUBLIC_URL=
APP_DOMAIN=kolabnow.com
APP_THEME=default
-APP_TENANT_ID=1
+APP_TENANT_ID=5
APP_LOCALE=en
APP_LOCALES=en,de
@@ -34,6 +35,8 @@
SESSION_DRIVER=file
SESSION_LIFETIME=120
+OPENEXCHANGERATES_API_KEY="from openexchangerates.org"
+
MFA_DSN=mysql://roundcube:Welcome2KolabSystems@127.0.0.1/roundcube
MFA_TOTP_DIGITS=6
MFA_TOTP_INTERVAL=30
diff --git a/src/app/Auth/SecondFactor.php b/src/app/Auth/SecondFactor.php
--- a/src/app/Auth/SecondFactor.php
+++ b/src/app/Auth/SecondFactor.php
@@ -2,8 +2,6 @@
namespace App\Auth;
-use App\Sku;
-use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Kolab2FA\Storage\Base;
@@ -93,17 +91,11 @@
public function factors(): array
{
// First check if the user has the 2FA SKU
- $sku_2fa = Sku::where('title', '2fa')->first();
+ if ($this->user->hasSku('2fa')) {
+ $factors = (array) $this->enumerate();
+ $factors = array_unique($factors);
- if ($sku_2fa) {
- $has_2fa = $this->user->entitlements()->where('sku_id', $sku_2fa->id)->first();
-
- if ($has_2fa) {
- $factors = (array) $this->enumerate();
- $factors = array_unique($factors);
-
- return $factors;
- }
+ return $factors;
}
return [];
@@ -186,7 +178,7 @@
*/
public static function code(string $email): string
{
- $sf = new self(User::where('email', $email)->first());
+ $sf = new self(\App\User::where('email', $email)->first());
$driver = $sf->getDriver('totp:8132a46b1f741f88de25f47e');
return (string) $driver->get_code();
diff --git a/src/app/Backends/OpenExchangeRates.php b/src/app/Backends/OpenExchangeRates.php
--- a/src/app/Backends/OpenExchangeRates.php
+++ b/src/app/Backends/OpenExchangeRates.php
@@ -7,7 +7,7 @@
/**
* Import exchange rates from openexchangerates.org
*
- * @param string Base currency
+ * @param string $baseCurrency Base currency
*
* @return array exchange rates
*/
diff --git a/src/app/Console/Command.php b/src/app/Console/Command.php
--- a/src/app/Console/Command.php
+++ b/src/app/Console/Command.php
@@ -7,6 +7,13 @@
abstract class Command extends \Illuminate\Console\Command
{
/**
+ * This needs to be here to be used.
+ *
+ * @var null
+ */
+ protected $commandPrefix = null;
+
+ /**
* Annotate this command as being dangerous for any potential unintended consequences.
*
* Commands are considered dangerous if;
@@ -77,6 +84,10 @@
$model = new $objectClass();
}
+ if ($this->commandPrefix == 'scalpel') {
+ return $model;
+ }
+
$modelsWithTenant = [
\App\Discount::class,
\App\Domain::class,
@@ -91,22 +102,20 @@
\App\Wallet::class,
];
- $tenant_id = \config('app.tenant_id');
+ $tenantId = \config('app.tenant_id');
// Add tenant filter
if (in_array($objectClass, $modelsWithTenant)) {
- $model = $model->withEnvTenant();
+ $model = $model->withEnvTenantContext();
} elseif (in_array($objectClass, $modelsWithOwner)) {
- $model = $model->whereExists(function ($query) use ($tenant_id) {
+ $model = $model->whereExists(function ($query) use ($tenantId) {
$query->select(DB::raw(1))
->from('users')
->whereRaw('wallets.user_id = users.id')
- ->whereRaw('users.tenant_id ' . ($tenant_id ? "= $tenant_id" : 'is null'));
+ ->whereRaw('users.tenant_id ' . ($tenantId ? "= $tenantId" : 'is null'));
});
}
- // TODO: tenant check for Entitlement, Transaction, etc.
-
return $model;
}
diff --git a/src/app/Console/Commands/Domain/CreateCommand.php b/src/app/Console/Commands/Domain/CreateCommand.php
--- a/src/app/Console/Commands/Domain/CreateCommand.php
+++ b/src/app/Console/Commands/Domain/CreateCommand.php
@@ -19,7 +19,7 @@
*
* @var string
*/
- protected $description = "Create a domain.";
+ protected $description = "Create a domain";
/**
* Execute the console command.
diff --git a/src/app/Console/Commands/Domain/DeleteCommand.php b/src/app/Console/Commands/Domain/DeleteCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Domain/DeleteCommand.php
@@ -0,0 +1,34 @@
+argument('domain');
+
+ $domain = $this->getDomain($argument);
+
+ if (!$domain) {
+ $this->error("No such domain {$argument}");
+ return 1;
+ }
+
+ if ($domain->isPublic()) {
+ $this->error("This domain is a public registration domain.");
+ return 1;
+ }
+
+ parent::handle();
+ }
+}
diff --git a/src/app/Console/Commands/Domain/UsersCommand.php b/src/app/Console/Commands/Domain/UsersCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Domain/UsersCommand.php
@@ -0,0 +1,13 @@
+getDomain($this->argument('domain'));
-
- if (!$domain) {
- return 1;
- }
-
- $domain->delete();
- }
-}
diff --git a/src/app/Console/Commands/DomainList.php b/src/app/Console/Commands/DomainList.php
--- a/src/app/Console/Commands/DomainList.php
+++ b/src/app/Console/Commands/DomainList.php
@@ -34,7 +34,7 @@
$domains = Domain::orderBy('namespace');
}
- $domains->withEnvTenant()->each(
+ $domains->withEnvTenantContext()->each(
function ($domain) {
$msg = $domain->namespace;
diff --git a/src/app/Console/Commands/DomainListUsers.php b/src/app/Console/Commands/DomainListUsers.php
deleted file mode 100644
--- a/src/app/Console/Commands/DomainListUsers.php
+++ /dev/null
@@ -1,83 +0,0 @@
-getDomain($this->argument('domain'));
-
- if (!$domain) {
- return 1;
- }
-
- if ($domain->isPublic()) {
- $this->error("This domain is a public registration domain.");
- return 1;
- }
-
- // TODO: actually implement listing users
- $wallet = $domain->wallet();
-
- if (!$wallet) {
- $this->error("This domain isn't billed to a wallet.");
- return 1;
- }
-
- $mailboxSKU = \App\Sku::where('title', 'mailbox')->first();
-
- if (!$mailboxSKU) {
- $this->error("No mailbox SKU available.");
- }
-
- $entitlements = $wallet->entitlements()
- ->where('entitleable_type', \App\User::class)
- ->where('sku_id', $mailboxSKU->id)->get();
-
- $users = [];
-
- foreach ($entitlements as $entitlement) {
- $users[] = $entitlement->entitleable;
- }
-
- usort($users, function ($a, $b) {
- return $a->email > $b->email;
- });
-
- foreach ($users as $user) {
- $this->info($user->email);
- }
- }
-}
diff --git a/src/app/Console/Commands/PackageSkus.php b/src/app/Console/Commands/PackageSkus.php
--- a/src/app/Console/Commands/PackageSkus.php
+++ b/src/app/Console/Commands/PackageSkus.php
@@ -28,7 +28,7 @@
*/
public function handle()
{
- $packages = Package::withEnvTenant()->get();
+ $packages = Package::withEnvTenantContext()->get();
foreach ($packages as $package) {
$this->info(sprintf("Package: %s", $package->title));
diff --git a/src/app/Console/Commands/PlanPackages.php b/src/app/Console/Commands/PlanPackages.php
--- a/src/app/Console/Commands/PlanPackages.php
+++ b/src/app/Console/Commands/PlanPackages.php
@@ -38,7 +38,7 @@
*/
public function handle()
{
- $plans = Plan::withEnvTenant()->get();
+ $plans = Plan::withEnvTenantContext()->get();
foreach ($plans as $plan) {
$this->info(sprintf("Plan: %s", $plan->title));
diff --git a/src/app/Console/Commands/User/DeleteCommand.php b/src/app/Console/Commands/User/DeleteCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/User/DeleteCommand.php
@@ -0,0 +1,15 @@
+withEnvTenantContext()->where('email', $this->argument('user'))->first();
+
+ if (!$user) {
+ $user = \App\User::withTrashed()->withEnvTenantContext()->where('id', $this->argument('user'))->first();
+ }
+
+ if (!$user) {
+ $this->error("No such user '" . $this->argument('user') . "' within this tenant context.");
+ $this->info("Try ./artisan scalpel:user:read --attr=email --attr=tenant_id " . $this->argument('user'));
+ return 1;
+ }
+
+ $statuses = [
+ 'active' => \App\User::STATUS_ACTIVE,
+ 'suspended' => \App\User::STATUS_SUSPENDED,
+ 'deleted' => \App\User::STATUS_DELETED,
+ 'ldapReady' => \App\User::STATUS_LDAP_READY,
+ 'imapReady' => \App\User::STATUS_IMAP_READY,
+ ];
+
+ $user_state = [];
+
+ foreach (\array_keys($statuses) as $state) {
+ $func = 'is' . \ucfirst($state);
+ if ($user->$func()) {
+ $user_state[] = $state;
+ }
+ }
+
+ $this->info("Status: " . \implode(',', $user_state));
+ }
+}
diff --git a/src/app/Console/Commands/UserStatus.php b/src/app/Console/Commands/UserStatus.php
deleted file mode 100644
--- a/src/app/Console/Commands/UserStatus.php
+++ /dev/null
@@ -1,53 +0,0 @@
-getUser($this->argument('user'));
-
- if (!$user) {
- return 1;
- }
-
- $statuses = [
- 'active' => User::STATUS_ACTIVE,
- 'suspended' => User::STATUS_SUSPENDED,
- 'deleted' => User::STATUS_DELETED,
- 'ldapReady' => User::STATUS_LDAP_READY,
- 'imapReady' => User::STATUS_IMAP_READY,
- ];
-
- foreach ($statuses as $text => $bit) {
- $func = 'is' . \ucfirst($text);
-
- $this->info(sprintf("%d %s: %s", $bit, $text, $user->$func()));
- }
-
- $this->info("In total: {$user->status}");
- }
-}
diff --git a/src/app/Console/Commands/WalletBalances.php b/src/app/Console/Commands/WalletBalances.php
--- a/src/app/Console/Commands/WalletBalances.php
+++ b/src/app/Console/Commands/WalletBalances.php
@@ -29,7 +29,7 @@
{
$wallets = \App\Wallet::select('wallets.*')
->join('users', 'users.id', '=', 'wallets.user_id')
- ->withEnvTenant('users')
+ ->withEnvTenantContext('users')
->all();
$wallets->each(
diff --git a/src/app/Console/Commands/WalletCharge.php b/src/app/Console/Commands/WalletCharge.php
--- a/src/app/Console/Commands/WalletCharge.php
+++ b/src/app/Console/Commands/WalletCharge.php
@@ -41,7 +41,7 @@
// Get all wallets, excluding deleted accounts
$wallets = Wallet::select('wallets.*')
->join('users', 'users.id', '=', 'wallets.user_id')
- ->withEnvTenant('users')
+ ->withEnvTenantContext('users')
->whereNull('users.deleted_at')
->cursor();
}
diff --git a/src/app/Console/Commands/WalletExpected.php b/src/app/Console/Commands/WalletExpected.php
--- a/src/app/Console/Commands/WalletExpected.php
+++ b/src/app/Console/Commands/WalletExpected.php
@@ -38,7 +38,7 @@
} else {
$wallets = \App\Wallet::select('wallets.*')
->join('users', 'users.id', '=', 'wallets.user_id')
- ->withEnvTenant('users')
+ ->withEnvTenantContext('users')
->all();
}
diff --git a/src/app/Console/Development/UserStatus.php b/src/app/Console/Development/UserStatus.php
deleted file mode 100644
--- a/src/app/Console/Development/UserStatus.php
+++ /dev/null
@@ -1,86 +0,0 @@
-argument('userid'))->firstOrFail();
-
- $this->info("Found user: {$user->id}");
-
- $statuses = [
- 'active' => User::STATUS_ACTIVE,
- 'suspended' => User::STATUS_SUSPENDED,
- 'deleted' => User::STATUS_DELETED,
- 'ldapReady' => User::STATUS_LDAP_READY,
- 'imapReady' => User::STATUS_IMAP_READY,
- ];
-
- // I'd prefer "-state" and "+state" syntax, but it's not possible
- $delete = false;
- if ($update = $this->option('del')) {
- $delete = true;
- } elseif ($update = $this->option('add')) {
- // do nothing
- }
-
- if (!empty($update)) {
- $map = \array_change_key_case($statuses);
- $update = \strtolower($update);
-
- if (isset($map[$update])) {
- if ($delete && $user->status & $map[$update]) {
- $user->status ^= $map[$update];
- $user->save();
- } elseif (!$delete && !($user->status & $map[$update])) {
- $user->status |= $map[$update];
- $user->save();
- }
- }
- }
-
- $user_state = [];
- foreach (\array_keys($statuses) as $state) {
- $func = 'is' . \ucfirst($state);
- if ($user->$func()) {
- $user_state[] = $state;
- }
- }
-
- $this->info("Status: " . \implode(',', $user_state));
- }
-}
diff --git a/src/app/Console/ObjectDeleteCommand.php b/src/app/Console/ObjectDeleteCommand.php
--- a/src/app/Console/ObjectDeleteCommand.php
+++ b/src/app/Console/ObjectDeleteCommand.php
@@ -36,6 +36,10 @@
$classes = class_uses_recursive($this->objectClass);
+ if (in_array(SoftDeletes::class, $classes)) {
+ $this->signature .= " {--with-deleted : Consider deleted {$this->objectName}s}";
+ }
+
parent::__construct();
}
@@ -87,9 +91,19 @@
if ($this->commandPrefix == 'scalpel') {
$this->objectClass::withoutEvents(
function () use ($object) {
- $object->delete();
+ if ($object->deleted_at) {
+ $object->forceDelete();
+ } else {
+ $object->delete();
+ }
}
);
+ } else {
+ if ($object->deleted_at) {
+ $object->forceDelete();
+ } else {
+ $object->delete();
+ }
}
}
}
diff --git a/src/app/Domain.php b/src/app/Domain.php
--- a/src/app/Domain.php
+++ b/src/app/Domain.php
@@ -115,7 +115,7 @@
*/
public static function getPublicDomains(): array
{
- return self::withEnvTenant()
+ return self::withEnvTenantContext()
->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC))
->get(['namespace'])->pluck('namespace')->toArray();
}
@@ -420,6 +420,43 @@
}
/**
+ * List the users of a domain, so long as the domain is not a public registration domain.
+ *
+ * @return array
+ */
+ public function users(): array
+ {
+ if ($this->isPublic()) {
+ return [];
+ }
+
+ $wallet = $this->wallet();
+
+ if (!$wallet) {
+ return [];
+ }
+
+ $mailboxSKU = \App\Sku::withObjectTenantContext($this)->where('title', 'mailbox')->first();
+
+ if (!$mailboxSKU) {
+ \Log::error("No mailbox SKU available.");
+ return [];
+ }
+
+ $entitlements = $wallet->entitlements()
+ ->where('entitleable_type', \App\User::class)
+ ->where('sku_id', $mailboxSKU->id)->get();
+
+ $users = [];
+
+ foreach ($entitlements as $entitlement) {
+ $users[] = $entitlement->entitleable;
+ }
+
+ return $users;
+ }
+
+ /**
* Verify if a domain exists in DNS
*
* @return bool True if registered, False otherwise
diff --git a/src/app/Group.php b/src/app/Group.php
--- a/src/app/Group.php
+++ b/src/app/Group.php
@@ -58,7 +58,7 @@
throw new \Exception("Group already assigned to a wallet");
}
- $sku = \App\Sku::where('title', 'group')->first();
+ $sku = \App\Sku::withObjectTenantContext($this)->where('title', 'group')->first();
$exists = $wallet->entitlements()->where('sku_id', $sku->id)->count();
\App\Entitlement::create([
diff --git a/src/app/Handlers/Beta/Base.php b/src/app/Handlers/Beta/Base.php
--- a/src/app/Handlers/Beta/Base.php
+++ b/src/app/Handlers/Beta/Base.php
@@ -19,14 +19,7 @@
// 2) active and a 'beta' entitlement must exist.
if ($sku->active) {
- $beta = \App\Sku::where('title', 'beta')->first();
- if (!$beta) {
- return false;
- }
-
- if ($user->entitlements()->where('sku_id', $beta->id)->first()) {
- return true;
- }
+ return $user->hasSku('beta');
} else {
if ($user->entitlements()->where('sku_id', $sku->id)->first()) {
return true;
diff --git a/src/app/Http/Controllers/API/SignupController.php b/src/app/Http/Controllers/API/SignupController.php
--- a/src/app/Http/Controllers/API/SignupController.php
+++ b/src/app/Http/Controllers/API/SignupController.php
@@ -43,14 +43,15 @@
$plans = [];
// Use reverse order just to have individual on left, group on right ;)
- Plan::select()->orderByDesc('title')->get()->map(function ($plan) use (&$plans) {
- $plans[] = [
- 'title' => $plan->title,
- 'name' => $plan->name,
- 'button' => __('app.planbutton', ['plan' => $plan->name]),
- 'description' => $plan->description,
- ];
- });
+ Plan::withEnvTenantContext()->orderByDesc('title')->get()
+ ->map(function ($plan) use (&$plans) {
+ $plans[] = [
+ 'title' => $plan->title,
+ 'name' => $plan->name,
+ 'button' => __('app.planbutton', ['plan' => $plan->name]),
+ 'description' => $plan->description,
+ ];
+ });
return response()->json(['status' => 'success', 'plans' => $plans]);
}
@@ -121,7 +122,7 @@
*/
public function invitation($id)
{
- $invitation = SignupInvitation::withEnvTenant()->find($id);
+ $invitation = SignupInvitation::withEnvTenantContext()->find($id);
if (empty($invitation) || $invitation->isCompleted()) {
return $this->errorResponse(404);
@@ -218,7 +219,7 @@
// Signup via invitation
if ($request->invitation) {
- $invitation = SignupInvitation::withEnvTenant()->find($request->invitation);
+ $invitation = SignupInvitation::withEnvTenantContext()->find($request->invitation);
if (empty($invitation) || $invitation->isCompleted()) {
return $this->errorResponse(404);
@@ -345,13 +346,13 @@
if (!$this->plan) {
// Get the plan if specified and exists...
if ($this->code && $this->code->plan) {
- $plan = Plan::where('title', $this->code->plan)->first();
+ $plan = Plan::withEnvTenantContext()->where('title', $this->code->plan)->first();
}
// ...otherwise use the default plan
if (empty($plan)) {
// TODO: Get default plan title from config
- $plan = Plan::where('title', 'individual')->first();
+ $plan = Plan::withEnvTenantContext()->where('title', 'individual')->first();
}
$this->plan = $plan;
diff --git a/src/app/Http/Controllers/API/V4/Admin/DiscountsController.php b/src/app/Http/Controllers/API/V4/Admin/DiscountsController.php
--- a/src/app/Http/Controllers/API/V4/Admin/DiscountsController.php
+++ b/src/app/Http/Controllers/API/V4/Admin/DiscountsController.php
@@ -8,26 +8,32 @@
class DiscountsController extends Controller
{
/**
- * Returns (active) discounts defined in the system.
+ * Returns (active) discounts defined in the system for the user context.
+ *
+ * @param int $id User identifier
*
* @return \Illuminate\Http\JsonResponse JSON response
*/
- public function index()
+ public function userDiscounts($id)
{
- $discounts = [];
+ $user = \App\User::find($id);
+
+ if (!$this->checkTenant($user)) {
+ return $this->errorResponse(404);
+ }
- Discount::withEnvTenant()
+ $discounts = Discount::withObjectTenantContext($user)
->where('active', true)
->orderBy('discount')
->get()
- ->map(function ($discount) use (&$discounts) {
+ ->map(function ($discount) {
$label = $discount->discount . '% - ' . $discount->description;
if ($discount->code) {
$label .= " [{$discount->code}]";
}
- $discounts[] = [
+ return [
'id' => $discount->id,
'discount' => $discount->discount,
'code' => $discount->code,
diff --git a/src/app/Http/Controllers/API/V4/Admin/DomainsController.php b/src/app/Http/Controllers/API/V4/Admin/DomainsController.php
--- a/src/app/Http/Controllers/API/V4/Admin/DomainsController.php
+++ b/src/app/Http/Controllers/API/V4/Admin/DomainsController.php
@@ -20,7 +20,7 @@
$result = collect([]);
if ($owner) {
- if ($owner = User::withEnvTenant()->find($owner)) {
+ if ($owner = User::find($owner)) {
foreach ($owner->wallets as $wallet) {
$entitlements = $wallet->entitlements()->where('entitleable_type', Domain::class)->get();
@@ -33,7 +33,7 @@
$result = $result->sortBy('namespace')->values();
}
} elseif (!empty($search)) {
- if ($domain = Domain::withEnvTenant()->where('namespace', $search)->first()) {
+ if ($domain = Domain::where('namespace', $search)->first()) {
$result->push($domain);
}
}
@@ -64,9 +64,9 @@
*/
public function suspend(Request $request, $id)
{
- $domain = Domain::withEnvTenant()->find($id);
+ $domain = Domain::find($id);
- if (empty($domain) || $domain->isPublic()) {
+ if (!$this->checkTenant($domain) || $domain->isPublic()) {
return $this->errorResponse(404);
}
@@ -88,9 +88,9 @@
*/
public function unsuspend(Request $request, $id)
{
- $domain = Domain::withEnvTenant()->find($id);
+ $domain = Domain::find($id);
- if (empty($domain) || $domain->isPublic()) {
+ if (!$this->checkTenant($domain) || $domain->isPublic()) {
return $this->errorResponse(404);
}
diff --git a/src/app/Http/Controllers/API/V4/Admin/GroupsController.php b/src/app/Http/Controllers/API/V4/Admin/GroupsController.php
--- a/src/app/Http/Controllers/API/V4/Admin/GroupsController.php
+++ b/src/app/Http/Controllers/API/V4/Admin/GroupsController.php
@@ -20,7 +20,7 @@
$result = collect([]);
if ($owner) {
- if ($owner = User::withEnvTenant()->find($owner)) {
+ if ($owner = User::find($owner)) {
foreach ($owner->wallets as $wallet) {
$wallet->entitlements()->where('entitleable_type', Group::class)->get()
->each(function ($entitlement) use ($result) {
@@ -31,7 +31,7 @@
$result = $result->sortBy('namespace')->values();
}
} elseif (!empty($search)) {
- if ($group = Group::withEnvTenant()->where('email', $search)->first()) {
+ if ($group = Group::where('email', $search)->first()) {
$result->push($group);
}
}
@@ -78,9 +78,9 @@
*/
public function suspend(Request $request, $id)
{
- $group = Group::withEnvTenant()->find($id);
+ $group = Group::find($id);
- if (empty($group)) {
+ if (!$this->checkTenant($group)) {
return $this->errorResponse(404);
}
@@ -102,9 +102,9 @@
*/
public function unsuspend(Request $request, $id)
{
- $group = Group::withEnvTenant()->find($id);
+ $group = Group::find($id);
- if (empty($group)) {
+ if (!$this->checkTenant($group)) {
return $this->errorResponse(404);
}
diff --git a/src/app/Http/Controllers/API/V4/Admin/PackagesController.php b/src/app/Http/Controllers/API/V4/Admin/PackagesController.php
deleted file mode 100644
--- a/src/app/Http/Controllers/API/V4/Admin/PackagesController.php
+++ /dev/null
@@ -1,7 +0,0 @@
-withEnvTenant();
+ $query = $query->withEnvTenantContext();
}
}
- // TODO: Tenant selector for admins
-
return $query;
}
}
diff --git a/src/app/Http/Controllers/API/V4/Admin/UsersController.php b/src/app/Http/Controllers/API/V4/Admin/UsersController.php
--- a/src/app/Http/Controllers/API/V4/Admin/UsersController.php
+++ b/src/app/Http/Controllers/API/V4/Admin/UsersController.php
@@ -8,6 +8,7 @@
use App\User;
use App\UserAlias;
use App\UserSetting;
+use App\Wallet;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
@@ -37,19 +38,14 @@
$result = collect([]);
if ($owner) {
- $owner = User::where('id', $owner)
- ->withEnvTenant()
- ->whereNull('role')
- ->first();
+ $owner = User::find($owner);
if ($owner) {
- $result = $owner->users(false)->whereNull('role')->orderBy('email')->get();
+ $result = $owner->users(false)->orderBy('email')->get();
}
} elseif (strpos($search, '@')) {
// Search by email
$result = User::withTrashed()->where('email', $search)
- ->withEnvTenant()
- ->whereNull('role')
->orderBy('email')
->get();
@@ -72,8 +68,6 @@
if (!$user_ids->isEmpty()) {
$result = User::withTrashed()->whereIn('id', $user_ids)
- ->withEnvTenant()
- ->whereNull('role')
->orderBy('email')
->get();
}
@@ -81,36 +75,39 @@
} elseif (is_numeric($search)) {
// Search by user ID
$user = User::withTrashed()->where('id', $search)
- ->withEnvTenant()
- ->whereNull('role')
->first();
if ($user) {
$result->push($user);
}
- } elseif (!empty($search)) {
+ } elseif (strpos($search, '.') !== false) {
// Search by domain
$domain = Domain::withTrashed()->where('namespace', $search)
- ->withEnvTenant()
->first();
if ($domain) {
- if (
- ($wallet = $domain->wallet())
- && ($owner = $wallet->owner()->withTrashed()->withEnvTenant()->first())
- && empty($owner->role)
- ) {
+ if (($wallet = $domain->wallet()) && ($owner = $wallet->owner()->withTrashed()->first())) {
+ $result->push($owner);
+ }
+ }
+ } elseif (!empty($search)) {
+ $wallet = Wallet::find($search);
+
+ if ($wallet) {
+ if ($owner = $wallet->owner()->withTrashed()->first()) {
$result->push($owner);
}
}
}
// Process the result
- $result = $result->map(function ($user) {
- $data = $user->toArray();
- $data = array_merge($data, self::userStatuses($user));
- return $data;
- });
+ $result = $result->map(
+ function ($user) {
+ $data = $user->toArray();
+ $data = array_merge($data, self::userStatuses($user));
+ return $data;
+ }
+ );
$result = [
'list' => $result,
@@ -131,13 +128,17 @@
*/
public function reset2FA(Request $request, $id)
{
- $user = User::withEnvTenant()->find($id);
+ $user = User::find($id);
- if (empty($user) || !$this->guard()->user()->canUpdate($user)) {
+ if (!$this->checkTenant($user)) {
return $this->errorResponse(404);
}
- $sku = Sku::where('title', '2fa')->first();
+ if (!$this->guard()->user()->canUpdate($user)) {
+ return $this->errorResponse(403);
+ }
+
+ $sku = Sku::withObjectTenantContext($user)->where('title', '2fa')->first();
// Note: we do select first, so the observer can delete
// 2FA preferences from Roundcube database, so don't
@@ -152,6 +153,42 @@
}
/**
+ * Display information on the user account specified by $id.
+ *
+ * @param int $id The account to show information for.
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function show($id)
+ {
+ $user = User::find($id);
+
+ if (!$this->checkTenant($user)) {
+ return $this->errorResponse(404);
+ }
+
+ if (!$this->guard()->user()->canRead($user)) {
+ return $this->errorResponse(403);
+ }
+
+ $response = $this->userResponse($user);
+
+ // Simplified Entitlement/SKU information,
+ // TODO: I agree this format may need to be extended in future
+ $response['skus'] = [];
+ foreach ($user->entitlements as $ent) {
+ $sku = $ent->sku;
+ if (!isset($response['skus'][$sku->id])) {
+ $response['skus'][$sku->id] = ['costs' => [], 'count' => 0];
+ }
+ $response['skus'][$sku->id]['count']++;
+ $response['skus'][$sku->id]['costs'][] = $ent->cost;
+ }
+
+ return response()->json($response);
+ }
+
+ /**
* Create a new user record.
*
* @param \Illuminate\Http\Request $request The API request.
@@ -173,12 +210,16 @@
*/
public function suspend(Request $request, $id)
{
- $user = User::withEnvTenant()->find($id);
+ $user = User::find($id);
- if (empty($user) || !$this->guard()->user()->canUpdate($user)) {
+ if (!$this->checkTenant($user)) {
return $this->errorResponse(404);
}
+ if (!$this->guard()->user()->canUpdate($user)) {
+ return $this->errorResponse(403);
+ }
+
$user->suspend();
return response()->json([
@@ -197,12 +238,16 @@
*/
public function unsuspend(Request $request, $id)
{
- $user = User::withEnvTenant()->find($id);
+ $user = User::find($id);
- if (empty($user) || !$this->guard()->user()->canUpdate($user)) {
+ if (!$this->checkTenant($user)) {
return $this->errorResponse(404);
}
+ if (!$this->guard()->user()->canUpdate($user)) {
+ return $this->errorResponse(403);
+ }
+
$user->unsuspend();
return response()->json([
@@ -221,12 +266,16 @@
*/
public function update(Request $request, $id)
{
- $user = User::withEnvTenant()->find($id);
+ $user = User::find($id);
- if (empty($user) || !$this->guard()->user()->canUpdate($user)) {
+ if (!$this->checkTenant($user)) {
return $this->errorResponse(404);
}
+ if (!$this->guard()->user()->canUpdate($user)) {
+ return $this->errorResponse(403);
+ }
+
// For now admins can change only user external email address
$rules = [];
diff --git a/src/app/Http/Controllers/API/V4/Admin/WalletsController.php b/src/app/Http/Controllers/API/V4/Admin/WalletsController.php
--- a/src/app/Http/Controllers/API/V4/Admin/WalletsController.php
+++ b/src/app/Http/Controllers/API/V4/Admin/WalletsController.php
@@ -8,7 +8,6 @@
use App\Transaction;
use App\Wallet;
use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
@@ -25,7 +24,7 @@
{
$wallet = Wallet::find($id);
- if (empty($wallet) || !Auth::guard()->user()->canRead($wallet)) {
+ if (empty($wallet) || !$this->checkTenant($wallet->owner)) {
return $this->errorResponse(404);
}
@@ -61,9 +60,9 @@
public function oneOff(Request $request, $id)
{
$wallet = Wallet::find($id);
- $user = Auth::guard()->user();
+ $user = $this->guard()->user();
- if (empty($wallet) || !$user->canRead($wallet)) {
+ if (empty($wallet) || !$this->checkTenant($wallet->owner)) {
return $this->errorResponse(404);
}
@@ -130,7 +129,7 @@
{
$wallet = Wallet::find($id);
- if (empty($wallet) || !Auth::guard()->user()->canRead($wallet)) {
+ if (empty($wallet) || !$this->checkTenant($wallet->owner)) {
return $this->errorResponse(404);
}
@@ -138,7 +137,7 @@
if (empty($request->discount)) {
$wallet->discount()->dissociate();
$wallet->save();
- } elseif ($discount = Discount::withEnvTenant()->find($request->discount)) {
+ } elseif ($discount = Discount::withObjectTenantContext($wallet->owner)->find($request->discount)) {
$wallet->discount()->associate($discount);
$wallet->save();
}
diff --git a/src/app/Http/Controllers/API/V4/DomainsController.php b/src/app/Http/Controllers/API/V4/DomainsController.php
--- a/src/app/Http/Controllers/API/V4/DomainsController.php
+++ b/src/app/Http/Controllers/API/V4/DomainsController.php
@@ -7,7 +7,6 @@
use App\Backends\LDAP;
use Carbon\Carbon;
use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Auth;
class DomainsController extends Controller
{
@@ -18,7 +17,7 @@
*/
public function index()
{
- $user = Auth::guard()->user();
+ $user = $this->guard()->user();
$list = [];
foreach ($user->domains() as $domain) {
@@ -51,10 +50,13 @@
*/
public function confirm($id)
{
- $domain = Domain::findOrFail($id);
+ $domain = Domain::find($id);
- // Only owner (or admin) has access to the domain
- if (!Auth::guard()->user()->canRead($domain)) {
+ if (!$this->checkTenant($domain)) {
+ return $this->errorResponse(404);
+ }
+
+ if (!$this->guard()->user()->canRead($domain)) {
return $this->errorResponse(403);
}
@@ -117,10 +119,13 @@
*/
public function show($id)
{
- $domain = Domain::withEnvTenant()->findOrFail($id);
+ $domain = Domain::find($id);
+
+ if (!$this->checkTenant($domain)) {
+ return $this->errorResponse(404);
+ }
- // Only owner (or admin) has access to the domain
- if (!Auth::guard()->user()->canRead($domain)) {
+ if (!$this->guard()->user()->canRead($domain)) {
return $this->errorResponse(403);
}
@@ -152,10 +157,13 @@
*/
public function status($id)
{
- $domain = Domain::withEnvTenant()->findOrFail($id);
+ $domain = Domain::find($id);
+
+ if (!$this->checkTenant($domain)) {
+ return $this->errorResponse(404);
+ }
- // Only owner (or admin) has access to the domain
- if (!Auth::guard()->user()->canRead($domain)) {
+ if (!$this->guard()->user()->canRead($domain)) {
return $this->errorResponse(403);
}
diff --git a/src/app/Http/Controllers/API/V4/GroupsController.php b/src/app/Http/Controllers/API/V4/GroupsController.php
--- a/src/app/Http/Controllers/API/V4/GroupsController.php
+++ b/src/app/Http/Controllers/API/V4/GroupsController.php
@@ -32,9 +32,9 @@
*/
public function destroy($id)
{
- $group = Group::withEnvTenant()->find($id);
+ $group = Group::find($id);
- if (empty($group)) {
+ if (!$this->checkTenant($group)) {
return $this->errorResponse(404);
}
@@ -96,9 +96,9 @@
*/
public function show($id)
{
- $group = Group::withEnvTenant()->find($id);
+ $group = Group::find($id);
- if (empty($group)) {
+ if (!$this->checkTenant($group)) {
return $this->errorResponse(404);
}
@@ -123,9 +123,9 @@
*/
public function status($id)
{
- $group = Group::withEnvTenant()->find($id);
+ $group = Group::find($id);
- if (empty($group)) {
+ if (!$this->checkTenant($group)) {
return $this->errorResponse(404);
}
@@ -308,9 +308,9 @@
*/
public function update(Request $request, $id)
{
- $group = Group::withEnvTenant()->find($id);
+ $group = Group::find($id);
- if (empty($group)) {
+ if (!$this->checkTenant($group)) {
return $this->errorResponse(404);
}
diff --git a/src/app/Http/Controllers/API/V4/OpenViduController.php b/src/app/Http/Controllers/API/V4/OpenViduController.php
--- a/src/app/Http/Controllers/API/V4/OpenViduController.php
+++ b/src/app/Http/Controllers/API/V4/OpenViduController.php
@@ -218,8 +218,7 @@
}
// Check if there's still a valid meet entitlement for the room owner
- $sku = \App\Sku::where('title', 'meet')->first();
- if ($sku && !$room->owner->entitlements()->where('sku_id', $sku->id)->first()) {
+ if (!$room->owner->hasSku('meet')) {
return $this->errorResponse(404, \trans('meet.room-not-found'));
}
diff --git a/src/app/Http/Controllers/API/V4/PackagesController.php b/src/app/Http/Controllers/API/V4/PackagesController.php
--- a/src/app/Http/Controllers/API/V4/PackagesController.php
+++ b/src/app/Http/Controllers/API/V4/PackagesController.php
@@ -54,7 +54,7 @@
{
// TODO: Packages should have an 'active' flag too, I guess
$response = [];
- $packages = Package::select()->orderBy('title')->get();
+ $packages = Package::withSubjectTenantContext()->select()->orderBy('title')->get();
foreach ($packages as $package) {
$response[] = [
diff --git a/src/app/Http/Controllers/API/V4/PaymentsController.php b/src/app/Http/Controllers/API/V4/PaymentsController.php
--- a/src/app/Http/Controllers/API/V4/PaymentsController.php
+++ b/src/app/Http/Controllers/API/V4/PaymentsController.php
@@ -7,7 +7,6 @@
use App\Wallet;
use App\Payment;
use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
class PaymentsController extends Controller
@@ -19,7 +18,7 @@
*/
public function mandate()
{
- $user = Auth::guard()->user();
+ $user = $this->guard()->user();
// TODO: Wallet selection
$wallet = $user->wallets()->first();
@@ -38,10 +37,10 @@
*/
public function mandateCreate(Request $request)
{
- $current_user = Auth::guard()->user();
+ $user = $this->guard()->user();
// TODO: Wallet selection
- $wallet = $current_user->wallets()->first();
+ $wallet = $user->wallets()->first();
// Input validation
if ($errors = self::mandateValidate($request, $wallet)) {
@@ -81,7 +80,7 @@
*/
public function mandateDelete()
{
- $user = Auth::guard()->user();
+ $user = $this->guard()->user();
// TODO: Wallet selection
$wallet = $user->wallets()->first();
@@ -107,10 +106,10 @@
*/
public function mandateUpdate(Request $request)
{
- $current_user = Auth::guard()->user();
+ $user = $this->guard()->user();
// TODO: Wallet selection
- $wallet = $current_user->wallets()->first();
+ $wallet = $user->wallets()->first();
// Input validation
if ($errors = self::mandateValidate($request, $wallet)) {
@@ -190,10 +189,10 @@
*/
public function store(Request $request)
{
- $current_user = Auth::guard()->user();
+ $user = $this->guard()->user();
// TODO: Wallet selection
- $wallet = $current_user->wallets()->first();
+ $wallet = $user->wallets()->first();
$rules = [
'amount' => 'required|numeric',
@@ -244,10 +243,10 @@
// TODO currently unused
// public function cancel(Request $request)
// {
- // $current_user = Auth::guard()->user();
+ // $user = $this->guard()->user();
// // TODO: Wallet selection
- // $wallet = $current_user->wallets()->first();
+ // $wallet = $user->wallets()->first();
// $paymentId = $request->payment;
@@ -372,9 +371,9 @@
*
* @return \Illuminate\Http\JsonResponse The response
*/
- public static function paymentMethods(Request $request)
+ public function paymentMethods(Request $request)
{
- $user = Auth::guard()->user();
+ $user = $this->guard()->user();
// TODO: Wallet selection
$wallet = $user->wallets()->first();
@@ -393,9 +392,9 @@
*
* @return \Illuminate\Http\JsonResponse The response
*/
- public static function hasPayments(Request $request)
+ public function hasPayments(Request $request)
{
- $user = Auth::guard()->user();
+ $user = $this->guard()->user();
// TODO: Wallet selection
$wallet = $user->wallets()->first();
@@ -421,9 +420,9 @@
*
* @return \Illuminate\Http\JsonResponse The response
*/
- public static function payments(Request $request)
+ public function payments(Request $request)
{
- $user = Auth::guard()->user();
+ $user = $this->guard()->user();
// TODO: Wallet selection
$wallet = $user->wallets()->first();
diff --git a/src/app/Http/Controllers/API/V4/Reseller/DomainsController.php b/src/app/Http/Controllers/API/V4/Reseller/DomainsController.php
--- a/src/app/Http/Controllers/API/V4/Reseller/DomainsController.php
+++ b/src/app/Http/Controllers/API/V4/Reseller/DomainsController.php
@@ -2,6 +2,54 @@
namespace App\Http\Controllers\API\V4\Reseller;
+use App\Domain;
+use App\User;
+
class DomainsController extends \App\Http\Controllers\API\V4\Admin\DomainsController
{
+ /**
+ * Search for domains
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function index()
+ {
+ $search = trim(request()->input('search'));
+ $owner = trim(request()->input('owner'));
+ $result = collect([]);
+
+ if ($owner) {
+ if ($owner = User::withSubjectTenantContext()->find($owner)) {
+ foreach ($owner->wallets as $wallet) {
+ $entitlements = $wallet->entitlements()->where('entitleable_type', Domain::class)->get();
+
+ foreach ($entitlements as $entitlement) {
+ $domain = $entitlement->entitleable;
+ $result->push($domain);
+ }
+ }
+
+ $result = $result->sortBy('namespace')->values();
+ }
+ } elseif (!empty($search)) {
+ if ($domain = Domain::withSubjectTenantContext()->where('namespace', $search)->first()) {
+ $result->push($domain);
+ }
+ }
+
+ // Process the result
+ $result = $result->map(function ($domain) {
+ $data = $domain->toArray();
+ $data = array_merge($data, self::domainStatuses($domain));
+ return $data;
+ });
+
+ $result = [
+ 'list' => $result,
+ 'count' => count($result),
+ 'message' => \trans('app.search-foundxdomains', ['x' => count($result)]),
+ ];
+
+ return response()->json($result);
+ }
}
diff --git a/src/app/Http/Controllers/API/V4/Reseller/GroupsController.php b/src/app/Http/Controllers/API/V4/Reseller/GroupsController.php
--- a/src/app/Http/Controllers/API/V4/Reseller/GroupsController.php
+++ b/src/app/Http/Controllers/API/V4/Reseller/GroupsController.php
@@ -2,6 +2,56 @@
namespace App\Http\Controllers\API\V4\Reseller;
+use App\Group;
+use App\User;
+
class GroupsController extends \App\Http\Controllers\API\V4\Admin\GroupsController
{
+ /**
+ * Search for groups
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function index()
+ {
+ $search = trim(request()->input('search'));
+ $owner = trim(request()->input('owner'));
+ $result = collect([]);
+
+ if ($owner) {
+ if ($owner = User::withSubjectTenantContext()->find($owner)) {
+ foreach ($owner->wallets as $wallet) {
+ $wallet->entitlements()->where('entitleable_type', Group::class)->get()
+ ->each(function ($entitlement) use ($result) {
+ $result->push($entitlement->entitleable);
+ });
+ }
+
+ $result = $result->sortBy('namespace')->values();
+ }
+ } elseif (!empty($search)) {
+ if ($group = Group::withSubjectTenantContext()->where('email', $search)->first()) {
+ $result->push($group);
+ }
+ }
+
+ // Process the result
+ $result = $result->map(function ($group) {
+ $data = [
+ 'id' => $group->id,
+ 'email' => $group->email,
+ ];
+
+ $data = array_merge($data, self::groupStatuses($group));
+ return $data;
+ });
+
+ $result = [
+ 'list' => $result,
+ 'count' => count($result),
+ 'message' => \trans('app.search-foundxdistlists', ['x' => count($result)]),
+ ];
+
+ return response()->json($result);
+ }
}
diff --git a/src/app/Http/Controllers/API/V4/Reseller/InvitationsController.php b/src/app/Http/Controllers/API/V4/Reseller/InvitationsController.php
--- a/src/app/Http/Controllers/API/V4/Reseller/InvitationsController.php
+++ b/src/app/Http/Controllers/API/V4/Reseller/InvitationsController.php
@@ -28,7 +28,7 @@
*/
public function destroy($id)
{
- $invitation = SignupInvitation::withUserTenant()->find($id);
+ $invitation = SignupInvitation::withSubjectTenantContext()->find($id);
if (empty($invitation)) {
return $this->errorResponse(404);
@@ -66,7 +66,7 @@
$page = intval(request()->input('page')) ?: 1;
$hasMore = false;
- $result = SignupInvitation::withUserTenant()
+ $result = SignupInvitation::withSubjectTenantContext()
->latest()
->limit($pageSize + 1)
->offset($pageSize * ($page - 1));
@@ -108,7 +108,7 @@
*/
public function resend($id)
{
- $invitation = SignupInvitation::withUserTenant()->find($id);
+ $invitation = SignupInvitation::withSubjectTenantContext()->find($id);
if (empty($invitation)) {
return $this->errorResponse(404);
@@ -139,6 +139,9 @@
$errors = [];
$invitations = [];
+ $envTenantId = \config('app.tenant_id');
+ $subjectTenantId = auth()->user()->tenant_id;
+
if (!empty($request->file) && is_object($request->file)) {
// Expected a text/csv file with multiple email addresses
if (!$request->file->isValid()) {
@@ -194,8 +197,14 @@
$count = 0;
foreach ($invitations as $idx => $invitation) {
- SignupInvitation::create($invitation);
+ $inv = SignupInvitation::create($invitation);
$count++;
+
+ // Set the invitation tenant to the reseller tenant
+ if ($envTenantId != $subjectTenantId) {
+ $inv->tenant_id = $subjectTenantId;
+ $inv->save();
+ }
}
return response()->json([
diff --git a/src/app/Http/Controllers/API/V4/Reseller/PackagesController.php b/src/app/Http/Controllers/API/V4/Reseller/PackagesController.php
deleted file mode 100644
--- a/src/app/Http/Controllers/API/V4/Reseller/PackagesController.php
+++ /dev/null
@@ -1,7 +0,0 @@
-user();
+
+ if ($addQuery) {
+ $query = $addQuery($query, $user->tenant_id);
+ } else {
+ $query = $query->withSubjectTenantContext();
+ }
+
+ return $query;
+ }
}
diff --git a/src/app/Http/Controllers/API/V4/Reseller/UsersController.php b/src/app/Http/Controllers/API/V4/Reseller/UsersController.php
--- a/src/app/Http/Controllers/API/V4/Reseller/UsersController.php
+++ b/src/app/Http/Controllers/API/V4/Reseller/UsersController.php
@@ -2,6 +2,107 @@
namespace App\Http\Controllers\API\V4\Reseller;
+use App\Domain;
+use App\Group;
+use App\User;
+use App\UserAlias;
+use App\UserSetting;
+
class UsersController extends \App\Http\Controllers\API\V4\Admin\UsersController
{
+ /**
+ * Searching of user accounts.
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function index()
+ {
+ $search = trim(request()->input('search'));
+ $owner = trim(request()->input('owner'));
+ $result = collect([]);
+
+ if ($owner) {
+ $owner = User::where('id', $owner)
+ ->withSubjectTenantContext()
+ ->whereNull('role')
+ ->first();
+
+ if ($owner) {
+ $result = $owner->users(false)->whereNull('role')->orderBy('email')->get();
+ }
+ } elseif (strpos($search, '@')) {
+ // Search by email
+ $result = User::withTrashed()->where('email', $search)
+ ->withSubjectTenantContext()
+ ->whereNull('role')
+ ->orderBy('email')
+ ->get();
+
+ if ($result->isEmpty()) {
+ // Search by an alias
+ $user_ids = UserAlias::where('alias', $search)->get()->pluck('user_id');
+
+ // Search by an external email
+ $ext_user_ids = UserSetting::where('key', 'external_email')
+ ->where('value', $search)
+ ->get()
+ ->pluck('user_id');
+
+ $user_ids = $user_ids->merge($ext_user_ids)->unique();
+
+ // Search by a distribution list email
+ if ($group = Group::withTrashed()->where('email', $search)->first()) {
+ $user_ids = $user_ids->merge([$group->wallet()->user_id])->unique();
+ }
+
+ if (!$user_ids->isEmpty()) {
+ $result = User::withTrashed()->whereIn('id', $user_ids)
+ ->withSubjectTenantContext()
+ ->whereNull('role')
+ ->orderBy('email')
+ ->get();
+ }
+ }
+ } elseif (is_numeric($search)) {
+ // Search by user ID
+ $user = User::withTrashed()->where('id', $search)
+ ->withSubjectTenantContext()
+ ->whereNull('role')
+ ->first();
+
+ if ($user) {
+ $result->push($user);
+ }
+ } elseif (!empty($search)) {
+ // Search by domain
+ $domain = Domain::withTrashed()->where('namespace', $search)
+ ->withSubjectTenantContext()
+ ->first();
+
+ if ($domain) {
+ if (
+ ($wallet = $domain->wallet())
+ && ($owner = $wallet->owner()->withTrashed()->withSubjectTenantContext()->first())
+ && empty($owner->role)
+ ) {
+ $result->push($owner);
+ }
+ }
+ }
+
+ // Process the result
+ $result = $result->map(function ($user) {
+ $data = $user->toArray();
+ $data = array_merge($data, self::userStatuses($user));
+ return $data;
+ });
+
+ $result = [
+ 'list' => $result,
+ 'count' => count($result),
+ 'message' => \trans('app.search-foundxusers', ['x' => count($result)]),
+ ];
+
+ return response()->json($result);
+ }
}
diff --git a/src/app/Http/Controllers/API/V4/Reseller/WalletsController.php b/src/app/Http/Controllers/API/V4/Reseller/WalletsController.php
--- a/src/app/Http/Controllers/API/V4/Reseller/WalletsController.php
+++ b/src/app/Http/Controllers/API/V4/Reseller/WalletsController.php
@@ -2,10 +2,6 @@
namespace App\Http\Controllers\API\V4\Reseller;
-use App\Discount;
-use App\Wallet;
-use Illuminate\Http\Request;
-
class WalletsController extends \App\Http\Controllers\API\V4\Admin\WalletsController
{
}
diff --git a/src/app/Http/Controllers/API/V4/SkusController.php b/src/app/Http/Controllers/API/V4/SkusController.php
--- a/src/app/Http/Controllers/API/V4/SkusController.php
+++ b/src/app/Http/Controllers/API/V4/SkusController.php
@@ -5,7 +5,6 @@
use App\Http\Controllers\Controller;
use App\Sku;
use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Auth;
class SkusController extends Controller
{
@@ -54,7 +53,7 @@
public function index()
{
// Note: Order by title for consistent ordering in tests
- $skus = Sku::withEnvTenant()->where('active', true)->orderBy('title')->get();
+ $skus = Sku::withSubjectTenantContext()->where('active', true)->orderBy('title')->get();
$response = [];
@@ -120,13 +119,13 @@
*/
public function userSkus($id)
{
- $user = \App\User::withEnvTenant()->find($id);
+ $user = \App\User::find($id);
- if (empty($user)) {
+ if (!$this->checkTenant($user)) {
return $this->errorResponse(404);
}
- if (!Auth::guard()->user()->canRead($user)) {
+ if (!$this->guard()->user()->canRead($user)) {
return $this->errorResponse(403);
}
@@ -134,7 +133,7 @@
$response = [];
// Note: Order by title for consistent ordering in tests
- $skus = Sku::withEnvTenant()->orderBy('title')->get();
+ $skus = Sku::withObjectTenantContext($user)->orderBy('title')->get();
foreach ($skus as $sku) {
if (!class_exists($sku->handler_class)) {
diff --git a/src/app/Http/Controllers/API/V4/UsersController.php b/src/app/Http/Controllers/API/V4/UsersController.php
--- a/src/app/Http/Controllers/API/V4/UsersController.php
+++ b/src/app/Http/Controllers/API/V4/UsersController.php
@@ -47,7 +47,7 @@
*/
public function destroy($id)
{
- $user = User::find($id);
+ $user = User::withEnvTenantContext()->find($id);
if (empty($user)) {
return $this->errorResponse(404);
@@ -95,7 +95,7 @@
*/
public function show($id)
{
- $user = User::find($id);
+ $user = User::withEnvTenantContext()->find($id);
if (empty($user)) {
return $this->errorResponse(404);
@@ -131,7 +131,7 @@
*/
public function status($id)
{
- $user = User::find($id);
+ $user = User::withEnvTenantContext()->find($id);
if (empty($user)) {
return $this->errorResponse(404);
@@ -289,7 +289,7 @@
return $error_response;
}
- if (empty($request->package) || !($package = \App\Package::find($request->package))) {
+ if (empty($request->package) || !($package = \App\Package::withEnvTenantContext()->find($request->package))) {
$errors = ['package' => \trans('validation.packagerequired')];
return response()->json(['status' => 'error', 'errors' => $errors], 422);
}
@@ -340,7 +340,7 @@
*/
public function update(Request $request, $id)
{
- $user = User::find($id);
+ $user = User::withEnvTenantContext()->find($id);
if (empty($user)) {
return $this->errorResponse(404);
@@ -411,7 +411,7 @@
}
// list of skus, [id=>obj]
- $skus = Sku::all()->mapWithKeys(
+ $skus = Sku::withEnvTenantContext()->get()->mapWithKeys(
function ($sku) {
return [$sku->id => $sku];
}
@@ -689,7 +689,7 @@
}
// Check if domain exists
- $domain = Domain::where('namespace', $domain)->first();
+ $domain = Domain::withEnvTenantContext()->where('namespace', $domain)->first();
if (empty($domain)) {
return \trans('validation.domaininvalid');
@@ -763,7 +763,7 @@
}
// Check if domain exists
- $domain = Domain::where('namespace', $domain)->first();
+ $domain = Domain::withEnvTenantContext()->where('namespace', $domain)->first();
if (empty($domain)) {
return \trans('validation.domaininvalid');
diff --git a/src/app/Http/Controllers/API/V4/WalletsController.php b/src/app/Http/Controllers/API/V4/WalletsController.php
--- a/src/app/Http/Controllers/API/V4/WalletsController.php
+++ b/src/app/Http/Controllers/API/V4/WalletsController.php
@@ -8,7 +8,6 @@
use App\Providers\PaymentProvider;
use Carbon\Carbon;
use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Auth;
/**
* API\WalletsController
@@ -58,12 +57,12 @@
{
$wallet = Wallet::find($id);
- if (empty($wallet)) {
+ if (empty($wallet) || !$this->checkTenant($wallet->owner)) {
return $this->errorResponse(404);
}
// Only owner (or admin) has access to the wallet
- if (!Auth::guard()->user()->canRead($wallet)) {
+ if (!$this->guard()->user()->canRead($wallet)) {
return $this->errorResponse(403);
}
@@ -126,8 +125,12 @@
{
$wallet = Wallet::find($id);
+ if (empty($wallet) || !$this->checkTenant($wallet->owner)) {
+ return $this->errorResponse(404);
+ }
+
// Only owner (or admin) has access to the wallet
- if (!Auth::guard()->user()->canRead($wallet)) {
+ if (!$this->guard()->user()->canRead($wallet)) {
abort(403);
}
@@ -171,8 +174,12 @@
{
$wallet = Wallet::find($id);
+ if (empty($wallet) || !$this->checkTenant($wallet->owner)) {
+ return $this->errorResponse(404);
+ }
+
// Only owner (or admin) has access to the wallet
- if (!Auth::guard()->user()->canRead($wallet)) {
+ if (!$this->guard()->user()->canRead($wallet)) {
return $this->errorResponse(403);
}
@@ -205,8 +212,12 @@
{
$wallet = Wallet::find($id);
+ if (empty($wallet) || !$this->checkTenant($wallet->owner)) {
+ return $this->errorResponse(404);
+ }
+
// Only owner (or admin) has access to the wallet
- if (!Auth::guard()->user()->canRead($wallet)) {
+ if (!$this->guard()->user()->canRead($wallet)) {
return $this->errorResponse(403);
}
diff --git a/src/app/Http/Controllers/Controller.php b/src/app/Http/Controllers/Controller.php
--- a/src/app/Http/Controllers/Controller.php
+++ b/src/app/Http/Controllers/Controller.php
@@ -50,6 +50,29 @@
}
/**
+ * Check if current user has access to the specified object
+ * by being an admin or existing in the same tenant context.
+ *
+ * @param ?object $object Model object
+ *
+ * @return bool
+ */
+ protected function checkTenant(object $object = null): bool
+ {
+ if (empty($object)) {
+ return false;
+ }
+
+ $user = $this->guard()->user();
+
+ if ($user->role == 'admin') {
+ return true;
+ }
+
+ return $object->tenant_id == $user->tenant_id;
+ }
+
+ /**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\Guard
diff --git a/src/app/Http/Middleware/AuthenticateReseller.php b/src/app/Http/Middleware/AuthenticateReseller.php
--- a/src/app/Http/Middleware/AuthenticateReseller.php
+++ b/src/app/Http/Middleware/AuthenticateReseller.php
@@ -25,10 +25,6 @@
abort(403, "Unauthorized");
}
- if ($user->tenant_id != \config('app.tenant_id')) {
- abort(403, "Unauthorized");
- }
-
return $next($request);
}
}
diff --git a/src/app/Observers/SkuObserver.php b/src/app/Observers/SkuObserver.php
--- a/src/app/Observers/SkuObserver.php
+++ b/src/app/Observers/SkuObserver.php
@@ -24,7 +24,5 @@
}
$sku->tenant_id = \config('app.tenant_id');
-
- // TODO: We should make sure that tenant_id + title is unique
}
}
diff --git a/src/app/Observers/UserAliasObserver.php b/src/app/Observers/UserAliasObserver.php
--- a/src/app/Observers/UserAliasObserver.php
+++ b/src/app/Observers/UserAliasObserver.php
@@ -30,6 +30,13 @@
return false;
}
+ if ($alias->user) {
+ if ($alias->user->tenant_id != $domain->tenant_id) {
+ \Log::error("Reseller for user '{$alias->user->email}' and domain '{$domain->namespace}' differ.");
+ return false;
+ }
+ }
+
return true;
}
diff --git a/src/app/Providers/AppServiceProvider.php b/src/app/Providers/AppServiceProvider.php
--- a/src/app/Providers/AppServiceProvider.php
+++ b/src/app/Providers/AppServiceProvider.php
@@ -63,54 +63,96 @@
}
// Register some template helpers
- Blade::directive('theme_asset', function ($path) {
- $path = trim($path, '/\'"');
- return "";
- });
+ Blade::directive(
+ 'theme_asset',
+ function ($path) {
+ $path = trim($path, '/\'"');
+ return "";
+ }
+ );
+
+ Builder::macro(
+ 'withEnvTenantContext',
+ function (string $table = null) {
+ $tenantId = \config('app.tenant_id');
- // Query builder 'withEnvTenant' macro
- Builder::macro('withEnvTenant', function (string $table = null) {
- $tenant_id = \config('app.tenant_id');
+ if ($tenantId) {
+ /** @var Builder $this */
+ return $this->where(($table ? "$table." : "") . "tenant_id", $tenantId);
+ }
- if ($tenant_id) {
/** @var Builder $this */
- return $this->where(($table ? "$table." : '') . 'tenant_id', $tenant_id);
+ return $this->whereNull(($table ? "$table." : "") . "tenant_id");
}
+ );
+
+ Builder::macro(
+ 'withObjectTenantContext',
+ function (object $object, string $table = null) {
+ // backend artisan cli
+ if (app()->runningInConsole()) {
+ /** @var Builder $this */
+ return $this->where(($table ? "$table." : "") . "tenant_id", $object->tenant_id);
+ }
+
+ $subject = auth()->user();
+
+ if ($subject->role == "admin") {
+ /** @var Builder $this */
+ return $this->where(($table ? "$table." : "") . "tenant_id", $object->tenant_id);
+ }
- /** @var Builder $this */
- return $this->whereNull(($table ? "$table." : '') . 'tenant_id');
- });
+ $tenantId = $subject->tenant_id;
- // Query builder 'withUserTenant' macro
- Builder::macro('withUserTenant', function (string $table = null) {
- $tenant_id = auth()->user()->tenant_id;
+ if ($tenantId) {
+ /** @var Builder $this */
+ return $this->where(($table ? "$table." : "") . "tenant_id", $tenantId);
+ }
- if ($tenant_id) {
/** @var Builder $this */
- return $this->where(($table ? "$table." : '') . 'tenant_id', $tenant_id);
+ return $this->whereNull(($table ? "$table." : "") . "tenant_id");
}
+ );
+
+ Builder::macro(
+ 'withSubjectTenantContext',
+ function (string $table = null) {
+ if ($user = auth()->user()) {
+ $tenantId = $user->tenant_id;
+ } else {
+ $tenantId = \config('app.tenant_id');
+ }
+
+ if ($tenantId) {
+ /** @var Builder $this */
+ return $this->where(($table ? "$table." : "") . "tenant_id", $tenantId);
+ }
- /** @var Builder $this */
- return $this->whereNull(($table ? "$table." : '') . 'tenant_id');
- });
+ /** @var Builder $this */
+ return $this->whereNull(($table ? "$table." : "") . "tenant_id");
+ }
+ );
// Query builder 'whereLike' mocro
- Builder::macro('whereLike', function (string $column, string $search, int $mode = 0) {
- $search = addcslashes($search, '%_');
-
- switch ($mode) {
- case 2:
- $search .= '%';
- break;
- case 1:
- $search = '%' . $search;
- break;
- default:
- $search = '%' . $search . '%';
- }
+ Builder::macro(
+ 'whereLike',
+ function (string $column, string $search, int $mode = 0) {
+ $search = addcslashes($search, '%_');
+
+ switch ($mode) {
+ case 2:
+ $search .= '%';
+ break;
+ case 1:
+ $search = '%' . $search;
+ break;
+ default:
+ $search = '%' . $search . '%';
+ }
- /** @var Builder $this */
- return $this->where($column, 'like', $search);
- });
+ /** @var Builder $this */
+ return $this->where($column, 'like', $search);
+ }
+ );
}
}
diff --git a/src/app/Providers/Payment/Mollie.php b/src/app/Providers/Payment/Mollie.php
--- a/src/app/Providers/Payment/Mollie.php
+++ b/src/app/Providers/Payment/Mollie.php
@@ -583,6 +583,7 @@
);
$availableMethods = [];
+
foreach ($providerMethods as $method) {
$availableMethods[$method->id] = [
'id' => $method->id,
diff --git a/src/app/Tenant.php b/src/app/Tenant.php
--- a/src/app/Tenant.php
+++ b/src/app/Tenant.php
@@ -13,6 +13,7 @@
class Tenant extends Model
{
protected $fillable = [
+ 'id',
'title',
];
diff --git a/src/app/User.php b/src/app/User.php
--- a/src/app/User.php
+++ b/src/app/User.php
@@ -312,7 +312,7 @@
if ($this->tenant_id) {
$domains = Domain::where('tenant_id', $this->tenant_id);
} else {
- $domains = Domain::withEnvTenant();
+ $domains = Domain::withEnvTenantContext();
}
$domains = $domains->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC))
@@ -462,9 +462,9 @@
*
* @return bool True if specified SKU entitlement exists
*/
- public function hasSku($title): bool
+ public function hasSku(string $title): bool
{
- $sku = Sku::where('title', $title)->first();
+ $sku = Sku::withObjectTenantContext($this)->where('title', $title)->first();
if (!$sku) {
return false;
diff --git a/src/app/Utils.php b/src/app/Utils.php
--- a/src/app/Utils.php
+++ b/src/app/Utils.php
@@ -159,6 +159,38 @@
fclose($fp);
}
+
+ /**
+ * Generate a passphrase. Not intended for use in production, so limited to environments that are not production.
+ *
+ * @return string
+ */
+ public static function generatePassphrase()
+ {
+ if (\config('app.env') == 'production') {
+ throw new \Exception("Thou shall not pass!");
+ }
+
+ if (\config('app.passphrase')) {
+ return \config('app.passphrase');
+ }
+
+ $alphaLow = 'abcdefghijklmnopqrstuvwxyz';
+ $alphaUp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $num = '0123456789';
+ $stdSpecial = '~`!@#$%^&*()-_+=[{]}\\|\'";:/?.>,<';
+
+ $source = $alphaLow . $alphaUp . $num . $stdSpecial;
+
+ $result = '';
+
+ for ($x = 0; $x < 16; $x++) {
+ $result .= substr($source, rand(0, (strlen($source) - 1)), 1);
+ }
+
+ return $result;
+ }
+
/**
* Calculate the broadcast address provided a net number and a prefix.
*
diff --git a/src/config/app.php b/src/config/app.php
--- a/src/config/app.php
+++ b/src/config/app.php
@@ -53,6 +53,8 @@
'url' => env('APP_URL', 'http://localhost'),
+ 'passphrase' => env('APP_PASSPHRASE', null),
+
'public_url' => env('APP_PUBLIC_URL', env('APP_URL', 'http://localhost')),
'asset_url' => env('ASSET_URL', null),
diff --git a/src/database/migrations/2020_05_05_095212_create_tenants_table.php b/src/database/migrations/2020_05_05_095212_create_tenants_table.php
--- a/src/database/migrations/2020_05_05_095212_create_tenants_table.php
+++ b/src/database/migrations/2020_05_05_095212_create_tenants_table.php
@@ -23,19 +23,21 @@
}
);
- \App\Tenant::create(['title' => 'Kolab Now']);
+ $tenantId = \config('app.tenant_id');
- foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $table_name) {
+ $tenant = \App\Tenant::create(['id' => $tenantId, 'title' => 'Kolab Now']);
+
+ foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $tableName) {
Schema::table(
- $table_name,
+ $tableName,
function (Blueprint $table) {
$table->bigInteger('tenant_id')->unsigned()->nullable();
$table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('set null');
}
);
- if ($tenant_id = \config('app.tenant_id')) {
- DB::statement("UPDATE `{$table_name}` SET `tenant_id` = {$tenant_id}");
+ if ($tenantId) {
+ DB::statement("UPDATE `{$tableName}` SET `tenant_id` = {$tenantId}");
}
}
@@ -48,9 +50,6 @@
}
);
}
-
- // FIXME: Should we also have package_skus.fee ?
- // We have package_skus.cost, but I think it is not used anywhere.
}
/**
@@ -60,9 +59,9 @@
*/
public function down()
{
- foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $table_name) {
+ foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $tableName) {
Schema::table(
- $table_name,
+ $tableName,
function (Blueprint $table) {
$table->dropForeign(['tenant_id']);
$table->dropColumn('tenant_id');
diff --git a/src/database/seeds/local/DiscountSeeder.php b/src/database/seeds/local/DiscountSeeder.php
--- a/src/database/seeds/local/DiscountSeeder.php
+++ b/src/database/seeds/local/DiscountSeeder.php
@@ -38,5 +38,21 @@
'code' => 'TEST',
]
);
+
+ // We're running in reseller mode, add a sample discount
+ $tenants = \App\Tenant::where('id', '!=', \config('app.tenant_id'))->get();
+
+ foreach ($tenants as $tenant) {
+ $discount = Discount::create(
+ [
+ 'description' => "Sample Discount by Reseller '{$tenant->title}'",
+ 'discount' => 10,
+ 'active' => true,
+ ]
+ );
+
+ $discount->tenant_id = $tenant->id;
+ $discount->save();
+ }
}
}
diff --git a/src/database/seeds/local/DomainSeeder.php b/src/database/seeds/local/DomainSeeder.php
--- a/src/database/seeds/local/DomainSeeder.php
+++ b/src/database/seeds/local/DomainSeeder.php
@@ -33,7 +33,7 @@
[
'namespace' => $domain,
'status' => Domain::STATUS_CONFIRMED + Domain::STATUS_ACTIVE,
- 'type' => Domain::TYPE_PUBLIC
+ 'type' => Domain::TYPE_PUBLIC,
]
);
}
@@ -43,7 +43,7 @@
[
'namespace' => \config('app.domain'),
'status' => DOMAIN::STATUS_CONFIRMED + Domain::STATUS_ACTIVE,
- 'type' => Domain::TYPE_PUBLIC
+ 'type' => Domain::TYPE_PUBLIC,
]
);
}
@@ -59,23 +59,27 @@
[
'namespace' => $domain,
'status' => Domain::STATUS_CONFIRMED + Domain::STATUS_ACTIVE,
- 'type' => Domain::TYPE_EXTERNAL
+ 'type' => Domain::TYPE_EXTERNAL,
]
);
}
- // example tenant domain, note that 'tenant_id' is not a fillable.
- $domain = Domain::create(
- [
- 'namespace' => 'example-tenant.dev-local',
- 'status' => Domain::STATUS_CONFIRMED + Domain::STATUS_ACTIVE,
- 'type' => Domain::TYPE_PUBLIC
- ]
- );
+ // We're running in reseller mode, add a sample discount
+ $tenants = \App\Tenant::where('id', '!=', \config('app.tenant_id'))->get();
- $tenant = \App\Tenant::where('title', 'Sample Tenant')->first();
+ foreach ($tenants as $tenant) {
+ $domainNamespace = strtolower(str_replace(' ', '-', $tenant->title)) . '.dev-local';
- $domain->tenant_id = $tenant->id;
- $domain->save();
+ $domain = Domain::create(
+ [
+ 'namespace' => $domainNamespace,
+ 'status' => Domain::STATUS_CONFIRMED + Domain::STATUS_ACTIVE,
+ 'type' => Domain::TYPE_PUBLIC,
+ ]
+ );
+
+ $domain->tenant_id = $tenant->id;
+ $domain->save();
+ }
}
}
diff --git a/src/database/seeds/local/PackageSeeder.php b/src/database/seeds/local/PackageSeeder.php
--- a/src/database/seeds/local/PackageSeeder.php
+++ b/src/database/seeds/local/PackageSeeder.php
@@ -15,16 +15,17 @@
*/
public function run()
{
- $skuGroupware = Sku::firstOrCreate(['title' => 'groupware']);
- $skuMailbox = Sku::firstOrCreate(['title' => 'mailbox']);
- $skuStorage = Sku::firstOrCreate(['title' => 'storage']);
+ $skuDomain = Sku::where(['title' => 'domain-hosting', 'tenant_id' => \config('app.tenant_id')])->first();
+ $skuGroupware = Sku::where(['title' => 'groupware', 'tenant_id' => \config('app.tenant_id')])->first();
+ $skuMailbox = Sku::where(['title' => 'mailbox', 'tenant_id' => \config('app.tenant_id')])->first();
+ $skuStorage = Sku::where(['title' => 'storage', 'tenant_id' => \config('app.tenant_id')])->first();
$package = Package::create(
[
'title' => 'kolab',
'name' => 'Groupware Account',
'description' => 'A fully functional groupware account.',
- 'discount_rate' => 0
+ 'discount_rate' => 0,
]
);
@@ -40,7 +41,7 @@
// be the number of SKU free units.
$package->skus()->updateExistingPivot(
$skuStorage,
- ['qty' => 2],
+ ['qty' => 5],
false
);
@@ -49,7 +50,7 @@
'title' => 'lite',
'name' => 'Lite Account',
'description' => 'Just mail and no more.',
- 'discount_rate' => 0
+ 'discount_rate' => 0,
]
);
@@ -61,8 +62,8 @@
$package->skus()->saveMany($skus);
$package->skus()->updateExistingPivot(
- Sku::firstOrCreate(['title' => 'storage']),
- ['qty' => 2],
+ $skuStorage,
+ ['qty' => 5],
false
);
@@ -71,14 +72,95 @@
'title' => 'domain-hosting',
'name' => 'Domain Hosting',
'description' => 'Use your own, existing domain.',
- 'discount_rate' => 0
+ 'discount_rate' => 0,
]
);
$skus = [
- Sku::firstOrCreate(['title' => 'domain-hosting'])
+ $skuDomain
];
$package->skus()->saveMany($skus);
+
+ // We're running in reseller mode, add a sample discount
+ $tenants = \App\Tenant::where('id', '!=', \config('app.tenant_id'))->get();
+
+ foreach ($tenants as $tenant) {
+ $skuDomain = Sku::where(['title' => 'domain-hosting', 'tenant_id' => $tenant->id])->first();
+ $skuGroupware = Sku::where(['title' => 'groupware', 'tenant_id' => $tenant->id])->first();
+ $skuMailbox = Sku::where(['title' => 'mailbox', 'tenant_id' => $tenant->id])->first();
+ $skuStorage = Sku::where(['title' => 'storage', 'tenant_id' => $tenant->id])->first();
+
+ $package = Package::create(
+ [
+ 'title' => 'kolab',
+ 'name' => 'Groupware Account',
+ 'description' => 'A fully functional groupware account.',
+ 'discount_rate' => 0
+ ]
+ );
+
+ $package->tenant_id = $tenant->id;
+ $package->save();
+
+ $skus = [
+ $skuMailbox,
+ $skuGroupware,
+ $skuStorage
+ ];
+
+ $package->skus()->saveMany($skus);
+
+ // This package contains 2 units of the storage SKU, which just so happens to also
+ // be the number of SKU free units.
+ $package->skus()->updateExistingPivot(
+ $skuStorage,
+ ['qty' => 5],
+ false
+ );
+
+ $package = Package::create(
+ [
+ 'title' => 'lite',
+ 'name' => 'Lite Account',
+ 'description' => 'Just mail and no more.',
+ 'discount_rate' => 0
+ ]
+ );
+
+ $package->tenant_id = $tenant->id;
+ $package->save();
+
+ $skus = [
+ $skuMailbox,
+ $skuStorage
+ ];
+
+ $package->skus()->saveMany($skus);
+
+ $package->skus()->updateExistingPivot(
+ $skuStorage,
+ ['qty' => 5],
+ false
+ );
+
+ $package = Package::create(
+ [
+ 'title' => 'domain-hosting',
+ 'name' => 'Domain Hosting',
+ 'description' => 'Use your own, existing domain.',
+ 'discount_rate' => 0
+ ]
+ );
+
+ $package->tenant_id = $tenant->id;
+ $package->save();
+
+ $skus = [
+ $skuDomain
+ ];
+
+ $package->skus()->saveMany($skus);
+ }
}
}
diff --git a/src/database/seeds/local/PlanSeeder.php b/src/database/seeds/local/PlanSeeder.php
--- a/src/database/seeds/local/PlanSeeder.php
+++ b/src/database/seeds/local/PlanSeeder.php
@@ -15,101 +15,6 @@
*/
public function run()
{
- /*
- $plan = Plan::create(
- [
- 'title' => 'family',
- 'description' => 'A group of accounts for 2 or more users.',
- 'discount_qty' => 0,
- 'discount_rate' => 0
- ]
- );
-
- $packages = [
- Package::firstOrCreate(['title' => 'kolab']),
- Package::firstOrCreate(['title' => 'domain-hosting'])
- ];
-
- $plan->packages()->saveMany($packages);
-
- $plan->packages()->updateExistingPivot(
- Package::firstOrCreate(['title' => 'kolab']),
- [
- 'qty_min' => 2,
- 'qty_max' => -1,
- 'discount_qty' => 2,
- 'discount_rate' => 50
- ],
- false
- );
-
- $plan = Plan::create(
- [
- 'title' => 'small-business',
- 'description' => 'Accounts for small business owners.',
- 'discount_qty' => 0,
- 'discount_rate' => 10
- ]
- );
-
- $packages = [
- Package::firstOrCreate(['title' => 'kolab']),
- Package::firstOrCreate(['title' => 'domain-hosting'])
- ];
-
- $plan->packages()->saveMany($packages);
-
- $plan->packages()->updateExistingPivot(
- Package::firstOrCreate(['title' => 'kolab']),
- [
- 'qty_min' => 5,
- 'qty_max' => 25,
- 'discount_qty' => 5,
- 'discount_rate' => 30
- ],
- false
- );
-
- $plan = Plan::create(
- [
- 'title' => 'large-business',
- 'description' => 'Accounts for large businesses.',
- 'discount_qty' => 0,
- 'discount_rate' => 10
- ]
- );
-
- $packages = [
- Package::firstOrCreate(['title' => 'kolab']),
- Package::firstOrCreate(['title' => 'lite']),
- Package::firstOrCreate(['title' => 'domain-hosting'])
- ];
-
- $plan->packages()->saveMany($packages);
-
- $plan->packages()->updateExistingPivot(
- Package::firstOrCreate(['title' => 'kolab']),
- [
- 'qty_min' => 20,
- 'qty_max' => -1,
- 'discount_qty' => 10,
- 'discount_rate' => 10
- ],
- false
- );
-
- $plan->packages()->updateExistingPivot(
- Package::firstOrCreate(['title' => 'lite']),
- [
- 'qty_min' => 0,
- 'qty_max' => -1,
- 'discount_qty' => 10,
- 'discount_rate' => 10
- ],
- false
- );
- */
-
$description = <<<'EOD'
Everything you need to get started or try Kolab Now, including:
@@ -133,7 +38,7 @@
);
$packages = [
- Package::firstOrCreate(['title' => 'kolab'])
+ Package::where(['title' => 'kolab', 'tenant_id' => \config('app.tenant_id')])->first()
];
$plan->packages()->saveMany($packages);
@@ -160,10 +65,77 @@
);
$packages = [
- Package::firstOrCreate(['title' => 'domain-hosting']),
- Package::firstOrCreate(['title' => 'kolab']),
+ Package::where(['title' => 'domain-hosting', 'tenant_id' => \config('app.tenant_id')])->first(),
+ Package::where(['title' => 'kolab', 'tenant_id' => \config('app.tenant_id')])->first()
];
$plan->packages()->saveMany($packages);
+
+ // We're running in reseller mode, add a sample discount
+ $tenants = \App\Tenant::where('id', '!=', \config('app.tenant_id'))->get();
+
+ foreach ($tenants as $tenant) {
+ $description = <<<'EOD'
+Everything you need to get started or try Kolab Now, including:
+
+ - Perfect for anyone wanting to move to Kolab Now
+ - Suite of online apps: Secure email, calendar, address book, files and more
+ - Access for anywhere: Sync all your devices to your Kolab Now account
+ - Secure hosting: Managed right here on our own servers in Switzerland
+ - Start protecting your data today, no ads, no crawling, no compromise
+ - An ideal replacement for services like Gmail, Office 365, etc…
+
+EOD;
+
+ $plan = Plan::create(
+ [
+ 'title' => 'individual',
+ 'name' => 'Individual Account',
+ 'description' => $description,
+ 'discount_qty' => 0,
+ 'discount_rate' => 0
+ ]
+ );
+
+ $plan->tenant_id = $tenant->id;
+ $plan->save();
+
+ $packages = [
+ Package::where(['title' => 'kolab', 'tenant_id' => $tenant->id])->first()
+ ];
+
+ $plan->packages()->saveMany($packages);
+
+ $description = <<<'EOD'
+All the features of the Individual Account, with the following extras:
+
+ - Perfect for anyone wanting to move a group or small business to Kolab Now
+ - Recommended to support users from 1 to 100
+ - Use your own personal domains with Kolab Now
+ - Manage and add users through our online admin area
+ - Flexible pricing based on user count
+
+EOD;
+
+ $plan = Plan::create(
+ [
+ 'title' => 'group',
+ 'name' => 'Group Account',
+ 'description' => $description,
+ 'discount_qty' => 0,
+ 'discount_rate' => 0
+ ]
+ );
+
+ $plan->tenant_id = $tenant->id;
+ $plan->save();
+
+ $packages = [
+ Package::where(['title' => 'domain-hosting', 'tenant_id' => $tenant->id])->first(),
+ Package::where(['title' => 'kolab', 'tenant_id' => $tenant->id])->first()
+ ];
+
+ $plan->packages()->saveMany($packages);
+ }
}
}
diff --git a/src/database/seeds/local/SkuSeeder.php b/src/database/seeds/local/SkuSeeder.php
--- a/src/database/seeds/local/SkuSeeder.php
+++ b/src/database/seeds/local/SkuSeeder.php
@@ -19,7 +19,7 @@
'title' => 'mailbox',
'name' => 'User Mailbox',
'description' => 'Just a mailbox',
- 'cost' => 444,
+ 'cost' => 500,
'units_free' => 0,
'period' => 'monthly',
'handler_class' => 'App\Handlers\Mailbox',
@@ -82,7 +82,7 @@
'name' => 'Storage Quota',
'description' => 'Some wiggle room',
'cost' => 25,
- 'units_free' => 2,
+ 'units_free' => 5,
'period' => 'monthly',
'handler_class' => 'App\Handlers\Storage',
'active' => true,
@@ -94,7 +94,7 @@
'title' => 'groupware',
'name' => 'Groupware Features',
'description' => 'Groupware functions like Calendar, Tasks, Notes, etc.',
- 'cost' => 555,
+ 'cost' => 490,
'units_free' => 0,
'period' => 'monthly',
'handler_class' => 'App\Handlers\Groupware',
@@ -144,7 +144,7 @@
'title' => 'activesync',
'name' => 'Activesync',
'description' => 'Mobile synchronization',
- 'cost' => 100,
+ 'cost' => 0,
'units_free' => 0,
'period' => 'monthly',
'handler_class' => 'App\Handlers\Activesync',
@@ -153,7 +153,9 @@
);
// Check existence because migration might have added this already
- if (!\App\Sku::where('title', 'beta')->first()) {
+ $sku = \App\Sku::where(['title' => 'beta', 'tenant_id' => \config('app.tenant_id')])->first();
+
+ if (!$sku) {
Sku::create(
[
'title' => 'beta',
@@ -169,7 +171,9 @@
}
// Check existence because migration might have added this already
- if (!\App\Sku::where('title', 'meet')->first()) {
+ $sku = \App\Sku::where(['title' => 'meet', 'tenant_id' => \config('app.tenant_id')])->first();
+
+ if (!$sku) {
Sku::create(
[
'title' => 'meet',
@@ -185,7 +189,9 @@
}
// Check existence because migration might have added this already
- if (!\App\Sku::where('title', 'group')->first()) {
+ $sku = \App\Sku::where(['title' => 'group', 'tenant_id' => \config('app.tenant_id')])->first();
+
+ if (!$sku) {
Sku::create(
[
'title' => 'group',
@@ -201,17 +207,126 @@
}
// Check existence because migration might have added this already
- if (!\App\Sku::where('title', 'distlist')->first()) {
- \App\Sku::create([
- 'title' => 'distlist',
- 'name' => 'Distribution lists',
- 'description' => 'Access to mail distribution lists',
- 'cost' => 0,
- 'units_free' => 0,
- 'period' => 'monthly',
- 'handler_class' => 'App\Handlers\Distlist',
- 'active' => true,
- ]);
+ $sku = \App\Sku::where(['title' => 'distlist', 'tenant_id' => \config('app.tenant_id')])->first();
+
+ if (!$sku) {
+ \App\Sku::create(
+ [
+ 'title' => 'distlist',
+ 'name' => 'Distribution lists',
+ 'description' => 'Access to mail distribution lists',
+ 'cost' => 0,
+ 'units_free' => 0,
+ 'period' => 'monthly',
+ 'handler_class' => 'App\Handlers\Distlist',
+ 'active' => true,
+ ]
+ );
+ }
+
+ // for tenants that are not the configured tenant id
+ $tenants = \App\Tenant::where('id', '!=', \config('app.tenant_id'))->get();
+
+ foreach ($tenants as $tenant) {
+ $sku = Sku::create(
+ [
+ 'title' => 'mailbox',
+ 'name' => 'User Mailbox',
+ 'description' => 'Just a mailbox',
+ 'cost' => 500,
+ 'fee' => 333,
+ 'units_free' => 0,
+ 'period' => 'monthly',
+ 'handler_class' => 'App\Handlers\Mailbox',
+ 'active' => true,
+ ]
+ );
+
+ $sku->tenant_id = $tenant->id;
+ $sku->save();
+
+ $sku = Sku::create(
+ [
+ 'title' => 'storage',
+ 'name' => 'Storage Quota',
+ 'description' => 'Some wiggle room',
+ 'cost' => 25,
+ 'fee' => 16,
+ 'units_free' => 5,
+ 'period' => 'monthly',
+ 'handler_class' => 'App\Handlers\Storage',
+ 'active' => true,
+ ]
+ );
+
+ $sku->tenant_id = $tenant->id;
+ $sku->save();
+
+ $sku = Sku::create(
+ [
+ 'title' => 'domain-hosting',
+ 'name' => 'External Domain',
+ 'description' => 'Host a domain that is externally registered',
+ 'cost' => 100,
+ 'fee' => 66,
+ 'units_free' => 1,
+ 'period' => 'monthly',
+ 'handler_class' => 'App\Handlers\DomainHosting',
+ 'active' => true,
+ ]
+ );
+
+ $sku->tenant_id = $tenant->id;
+ $sku->save();
+
+ $sku = Sku::create(
+ [
+ 'title' => 'groupware',
+ 'name' => 'Groupware Features',
+ 'description' => 'Groupware functions like Calendar, Tasks, Notes, etc.',
+ 'cost' => 490,
+ 'fee' => 327,
+ 'units_free' => 0,
+ 'period' => 'monthly',
+ 'handler_class' => 'App\Handlers\Groupware',
+ 'active' => true,
+ ]
+ );
+
+ $sku->tenant_id = $tenant->id;
+ $sku->save();
+
+ $sku = Sku::create(
+ [
+ 'title' => '2fa',
+ 'name' => '2-Factor Authentication',
+ 'description' => 'Two factor authentication for webmail and administration panel',
+ 'cost' => 0,
+ 'units_free' => 0,
+ 'period' => 'monthly',
+ 'handler_class' => 'App\Handlers\Auth2F',
+ 'active' => true,
+ ]
+ );
+
+ $sku->tenant_id = $tenant->id;
+ $sku->save();
+
+ $sku = Sku::create(
+ [
+ 'title' => 'activesync',
+ 'name' => 'Activesync',
+ 'description' => 'Mobile synchronization',
+ 'cost' => 0,
+ 'units_free' => 0,
+ 'period' => 'monthly',
+ 'handler_class' => 'App\Handlers\Activesync',
+ 'active' => true,
+ ]
+ );
+
+ $sku->tenant_id = $tenant->id;
+ $sku->save();
}
}
}
diff --git a/src/database/seeds/local/TenantSeeder.php b/src/database/seeds/local/TenantSeeder.php
--- a/src/database/seeds/local/TenantSeeder.php
+++ b/src/database/seeds/local/TenantSeeder.php
@@ -14,16 +14,24 @@
*/
public function run()
{
- if (!Tenant::find(1)) {
- Tenant::create([
- 'title' => 'Kolab Now'
- ]);
- }
+ if (\config('app.tenant_id')) {
+ $tenant = Tenant::where(['title' => 'Kolab Now'])->first();
+
+ if (!$tenant) {
+ Tenant::create(['title' => 'Kolab Now']);
+ }
+
+ $tenant = Tenant::where(['title' => 'Sample Tenant'])->first();
+
+ if (!$tenant) {
+ $tenant = Tenant::create(['title' => 'Sample Tenant']);
+ }
+
+ $tenant = Tenant::where(['title' => 'kanarip.ch'])->first();
- if (!Tenant::find(2)) {
- Tenant::create([
- 'title' => 'Sample Tenant'
- ]);
+ if (!$tenant) {
+ $tenant = Tenant::create(['title' => 'kanarip.ch']);
+ }
}
}
}
diff --git a/src/database/seeds/local/UserSeeder.php b/src/database/seeds/local/UserSeeder.php
--- a/src/database/seeds/local/UserSeeder.php
+++ b/src/database/seeds/local/UserSeeder.php
@@ -34,7 +34,7 @@
$john = User::create(
[
'email' => 'john@kolab.org',
- 'password' => 'simple123',
+ 'password' => \App\Utils::generatePassphrase()
]
);
@@ -55,17 +55,17 @@
$wallet = $john->wallets->first();
- $package_domain = \App\Package::where('title', 'domain-hosting')->first();
- $package_kolab = \App\Package::where('title', 'kolab')->first();
- $package_lite = \App\Package::where('title', 'lite')->first();
+ $packageDomain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
+ $packageKolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $packageLite = \App\Package::withEnvTenantContext()->where('title', 'lite')->first();
- $domain->assignPackage($package_domain, $john);
- $john->assignPackage($package_kolab);
+ $domain->assignPackage($packageDomain, $john);
+ $john->assignPackage($packageKolab);
$jack = User::create(
[
'email' => 'jack@kolab.org',
- 'password' => 'simple123',
+ 'password' => \App\Utils::generatePassphrase()
]
);
@@ -80,7 +80,7 @@
$jack->setAliases(['jack.daniels@kolab.org']);
- $john->assignPackage($package_kolab, $jack);
+ $john->assignPackage($packageKolab, $jack);
foreach ($john->entitlements as $entitlement) {
$entitlement->created_at = Carbon::now()->subMonthsWithoutOverflow(1);
@@ -91,7 +91,7 @@
$ned = User::create(
[
'email' => 'ned@kolab.org',
- 'password' => 'simple123',
+ 'password' => \App\Utils::generatePassphrase()
]
);
@@ -104,16 +104,18 @@
]
);
- $john->assignPackage($package_kolab, $ned);
+ $john->assignPackage($packageKolab, $ned);
- $ned->assignSku(\App\Sku::where('title', 'activesync')->first(), 1);
+ $ned->assignSku(\App\Sku::withEnvTenantContext()->where('title', 'activesync')->first(), 1);
// Ned is a controller on Jack's wallet
$john->wallets()->first()->addController($ned);
// Ned is also our 2FA test user
- $sku2fa = Sku::firstOrCreate(['title' => '2fa']);
+ $sku2fa = Sku::withEnvTenantContext()->where('title', '2fa')->first();
+
$ned->assignSku($sku2fa);
+
try {
SecondFactor::seed('ned@kolab.org');
} catch (\Exception $e) {
@@ -123,11 +125,11 @@
$joe = User::create(
[
'email' => 'joe@kolab.org',
- 'password' => 'simple123',
+ 'password' => \App\Utils::generatePassphrase()
]
);
- $john->assignPackage($package_lite, $joe);
+ $john->assignPackage($packageLite, $joe);
//$john->assignSku(Sku::firstOrCreate(['title' => 'beta']));
//$john->assignSku(Sku::firstOrCreate(['title' => 'meet']));
@@ -139,36 +141,64 @@
$jeroen = User::create(
[
'email' => 'jeroen@jeroen.jeroen',
- 'password' => 'jeroen',
+ 'password' => \App\Utils::generatePassphrase()
]
);
$jeroen->role = 'admin';
$jeroen->save();
- $tenant1 = \App\Tenant::where('title', 'Kolab Now')->first();
- $tenant2 = \App\Tenant::where('title', 'Sample Tenant')->first();
-
- $reseller1 = User::create(
+ $reseller = User::create(
[
- 'email' => 'reseller@kolabnow.com',
- 'password' => 'reseller',
+ 'email' => 'reseller@' . \config('app.domain'),
+ 'password' => \App\Utils::generatePassphrase()
]
);
- $reseller1->tenant_id = $tenant1->id;
- $reseller1->role = 'reseller';
- $reseller1->save();
+ $reseller->role = 'reseller';
+ $reseller->save();
- $reseller2 = User::create(
- [
- 'email' => 'reseller@reseller.com',
- 'password' => 'reseller',
- ]
- );
+ $reseller->assignPackage($packageKolab);
+
+ // for tenants that are not the configured tenant id
+ $tenants = \App\Tenant::where('id', '!=', \config('app.tenant_id'))->get();
+
+ foreach ($tenants as $tenant) {
+ $domain = Domain::where('tenant_id', $tenant->id)->first();
- $reseller2->tenant_id = $tenant2->id;
- $reseller2->role = 'reseller';
- $reseller2->save();
+ $packageKolab = \App\Package::where(
+ [
+ 'title' => 'kolab',
+ 'tenant_id' => $tenant->id
+ ]
+ )->first();
+
+ if ($domain) {
+ $reseller = User::create(
+ [
+ 'email' => 'reseller@' . $domain->namespace,
+ 'password' => \App\Utils::generatePassphrase()
+ ]
+ );
+
+ $reseller->role = 'reseller';
+ $reseller->tenant_id = $tenant->id;
+ $reseller->save();
+
+ $reseller->assignPackage($packageKolab);
+
+ $user = User::create(
+ [
+ 'email' => 'user@' . $domain->namespace,
+ 'password' => \App\Utils::generatePassphrase()
+ ]
+ );
+
+ $user->tenant_id = $tenant->id;
+ $user->save();
+
+ $user->assignPackage($packageKolab);
+ }
+ }
}
}
diff --git a/src/phpstan.neon b/src/phpstan.neon
--- a/src/phpstan.neon
+++ b/src/phpstan.neon
@@ -4,8 +4,9 @@
ignoreErrors:
- '#Access to an undefined property Illuminate\\Contracts\\Auth\\Authenticatable#'
- '#Access to an undefined property [a-zA-Z\\]+::\$pivot#'
- - '#Call to an undefined [a-zA-Z0-9<>\\ ]+::withEnvTenant\(\)#'
- - '#Call to an undefined [a-zA-Z0-9<>\\ ]+::withUserTenant\(\)#'
+ - '#Call to an undefined [a-zA-Z0-9<>\\ ]+::withEnvTenantContext\(\)#'
+ - '#Call to an undefined [a-zA-Z0-9<>\\ ]+::withObjectTenantContext\(\)#'
+ - '#Call to an undefined [a-zA-Z0-9<>\\ ]+::withSubjectTenantContext\(\)#'
- '#Call to an undefined method Tests\\Browser::#'
level: 4
parallel:
diff --git a/src/resources/vue/Admin/User.vue b/src/resources/vue/Admin/User.vue
--- a/src/resources/vue/Admin/User.vue
+++ b/src/resources/vue/Admin/User.vue
@@ -566,7 +566,7 @@
if (!this.discounts.length) {
// Fetch discounts
- axios.get('/api/v4/discounts')
+ axios.get('/api/v4/users/' + this.user.id + '/discounts')
.then(response => {
this.discounts = response.data.list
})
diff --git a/src/routes/api.php b/src/routes/api.php
--- a/src/routes/api.php
+++ b/src/routes/api.php
@@ -155,9 +155,9 @@
Route::post('groups/{id}/suspend', 'API\V4\Admin\GroupsController@suspend');
Route::post('groups/{id}/unsuspend', 'API\V4\Admin\GroupsController@unsuspend');
- Route::apiResource('packages', API\V4\Admin\PackagesController::class);
Route::apiResource('skus', API\V4\Admin\SkusController::class);
Route::apiResource('users', API\V4\Admin\UsersController::class);
+ Route::get('users/{id}/discounts', 'API\V4\Reseller\DiscountsController@userDiscounts');
Route::post('users/{id}/reset2FA', 'API\V4\Admin\UsersController@reset2FA');
Route::get('users/{id}/skus', 'API\V4\Admin\SkusController@userSkus');
Route::post('users/{id}/suspend', 'API\V4\Admin\UsersController@suspend');
@@ -165,7 +165,6 @@
Route::apiResource('wallets', API\V4\Admin\WalletsController::class);
Route::post('wallets/{id}/one-off', 'API\V4\Admin\WalletsController@oneOff');
Route::get('wallets/{id}/transactions', 'API\V4\Admin\WalletsController@transactions');
- Route::apiResource('discounts', API\V4\Admin\DiscountsController::class);
Route::get('stats/chart/{chart}', 'API\V4\Admin\StatsController@chart');
}
@@ -188,7 +187,6 @@
Route::apiResource('invitations', API\V4\Reseller\InvitationsController::class);
Route::post('invitations/{id}/resend', 'API\V4\Reseller\InvitationsController@resend');
- Route::apiResource('packages', API\V4\Reseller\PackagesController::class);
Route::post('payments', 'API\V4\Reseller\PaymentsController@store');
Route::get('payments/mandate', 'API\V4\Reseller\PaymentsController@mandate');
@@ -201,6 +199,7 @@
Route::apiResource('skus', API\V4\Reseller\SkusController::class);
Route::apiResource('users', API\V4\Reseller\UsersController::class);
+ Route::get('users/{id}/discounts', 'API\V4\Reseller\DiscountsController@userDiscounts');
Route::post('users/{id}/reset2FA', 'API\V4\Reseller\UsersController@reset2FA');
Route::get('users/{id}/skus', 'API\V4\Reseller\SkusController@userSkus');
Route::post('users/{id}/suspend', 'API\V4\Reseller\UsersController@suspend');
@@ -210,7 +209,6 @@
Route::get('wallets/{id}/receipts', 'API\V4\Reseller\WalletsController@receipts');
Route::get('wallets/{id}/receipts/{receipt}', 'API\V4\Reseller\WalletsController@receiptDownload');
Route::get('wallets/{id}/transactions', 'API\V4\Reseller\WalletsController@transactions');
- Route::apiResource('discounts', API\V4\Reseller\DiscountsController::class);
Route::get('stats/chart/{chart}', 'API\V4\Reseller\StatsController@chart');
}
diff --git a/src/tests/Browser/Admin/DashboardTest.php b/src/tests/Browser/Admin/DashboardTest.php
--- a/src/tests/Browser/Admin/DashboardTest.php
+++ b/src/tests/Browser/Admin/DashboardTest.php
@@ -47,7 +47,7 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('jeroen@jeroen.jeroen', 'jeroen', true)
+ ->submitLogon('jeroen@jeroen.jeroen', \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->assertFocused('@search input')
->assertMissing('@search table');
@@ -105,7 +105,7 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('jeroen@jeroen.jeroen', 'jeroen', true)
+ ->submitLogon('jeroen@jeroen.jeroen', \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->assertFocused('@search input')
->assertMissing('@search table');
diff --git a/src/tests/Browser/Admin/DistlistTest.php b/src/tests/Browser/Admin/DistlistTest.php
--- a/src/tests/Browser/Admin/DistlistTest.php
+++ b/src/tests/Browser/Admin/DistlistTest.php
@@ -69,7 +69,7 @@
// Goto the distlist page
$browser->visit(new Home())
- ->submitLogon('jeroen@jeroen.jeroen', 'jeroen', true)
+ ->submitLogon('jeroen@jeroen.jeroen', \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->visit($user_page)
->on($user_page)
diff --git a/src/tests/Browser/Admin/DomainTest.php b/src/tests/Browser/Admin/DomainTest.php
--- a/src/tests/Browser/Admin/DomainTest.php
+++ b/src/tests/Browser/Admin/DomainTest.php
@@ -56,7 +56,7 @@
// Goto the domain page
$browser->visit(new Home())
- ->submitLogon('jeroen@jeroen.jeroen', 'jeroen', true)
+ ->submitLogon('jeroen@jeroen.jeroen', \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->visit($user_page)
->on($user_page)
diff --git a/src/tests/Browser/Admin/LogonTest.php b/src/tests/Browser/Admin/LogonTest.php
--- a/src/tests/Browser/Admin/LogonTest.php
+++ b/src/tests/Browser/Admin/LogonTest.php
@@ -72,7 +72,7 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('jeroen@jeroen.jeroen', 'jeroen', true);
+ ->submitLogon('jeroen@jeroen.jeroen', \App\Utils::generatePassphrase(), true);
// Checks if we're really on Dashboard page
$browser->on(new Dashboard())
@@ -123,7 +123,7 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('jeroen@jeroen.jeroen', 'jeroen', true);
+ ->submitLogon('jeroen@jeroen.jeroen', \App\Utils::generatePassphrase(), true);
// Checks if we're really on Dashboard page
$browser->on(new Dashboard());
diff --git a/src/tests/Browser/Admin/StatsTest.php b/src/tests/Browser/Admin/StatsTest.php
--- a/src/tests/Browser/Admin/StatsTest.php
+++ b/src/tests/Browser/Admin/StatsTest.php
@@ -26,7 +26,7 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('jeroen@jeroen.jeroen', 'jeroen', true)
+ ->submitLogon('jeroen@jeroen.jeroen', \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->assertSeeIn('@links .link-stats', 'Stats')
->click('@links .link-stats')
diff --git a/src/tests/Browser/Admin/UserFinancesTest.php b/src/tests/Browser/Admin/UserFinancesTest.php
--- a/src/tests/Browser/Admin/UserFinancesTest.php
+++ b/src/tests/Browser/Admin/UserFinancesTest.php
@@ -47,7 +47,7 @@
$page = new UserPage($jack->id);
$browser->visit(new Home())
- ->submitLogon('jeroen@jeroen.jeroen', 'jeroen', true)
+ ->submitLogon('jeroen@jeroen.jeroen', \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->visit($page)
->on($page)
@@ -184,9 +184,9 @@
->assertSeeIn('#discount span', '10% - Test voucher')
->click('@nav #tab-subscriptions')
->with('@user-subscriptions', function (Browser $browser) {
- $browser->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '3,99 CHF/month¹')
+ $browser->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,50 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month¹')
- ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,99 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,41 CHF/month¹')
->assertSeeIn('table + .hint', '¹ applied discount: 10% - Test voucher');
})
// Change back to 'none'
@@ -201,9 +201,9 @@
->assertSeeIn('#discount span', 'none')
->click('@nav #tab-subscriptions')
->with('@user-subscriptions', function (Browser $browser) {
- $browser->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,44 CHF/month')
+ $browser->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '5,00 CHF/month')
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month')
- ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '5,55 CHF/month')
+ ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,90 CHF/month')
->assertMissing('table + .hint');
});
});
diff --git a/src/tests/Browser/Admin/UserTest.php b/src/tests/Browser/Admin/UserTest.php
--- a/src/tests/Browser/Admin/UserTest.php
+++ b/src/tests/Browser/Admin/UserTest.php
@@ -89,7 +89,7 @@
$page = new UserPage($jack->id);
$browser->visit(new Home())
- ->submitLogon('jeroen@jeroen.jeroen', 'jeroen', true)
+ ->submitLogon('jeroen@jeroen.jeroen', \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->visit($page)
->on($page);
@@ -136,11 +136,11 @@
->with('@user-subscriptions', function (Browser $browser) {
$browser->assertElementsCount('table tbody tr', 3)
->assertSeeIn('table tbody tr:nth-child(1) td:first-child', 'User Mailbox')
- ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,44 CHF')
- ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 2 GB')
+ ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '5,00 CHF')
+ ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 5 GB')
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF')
->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features')
- ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '5,55 CHF')
+ ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,90 CHF')
->assertMissing('table tfoot')
->assertMissing('#reset2fa');
});
@@ -242,11 +242,11 @@
->with('@user-subscriptions', function (Browser $browser) {
$browser->assertElementsCount('table tbody tr', 3)
->assertSeeIn('table tbody tr:nth-child(1) td:first-child', 'User Mailbox')
- ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '3,99 CHF/month¹')
- ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 2 GB')
+ ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,50 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 5 GB')
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features')
- ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,99 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,41 CHF/month¹')
->assertMissing('table tfoot')
->assertSeeIn('table + .hint', '¹ applied discount: 10% - Test voucher');
});
@@ -291,8 +291,8 @@
// Now we go to Ned's info page, he's a controller on John's wallet
$this->browse(function (Browser $browser) {
$ned = $this->getTestUser('ned@kolab.org');
- $beta_sku = Sku::where('title', 'beta')->first();
- $storage_sku = Sku::where('title', 'storage')->first();
+ $beta_sku = Sku::withEnvTenantContext()->where('title', 'beta')->first();
+ $storage_sku = Sku::withEnvTenantContext()->where('title', 'storage')->first();
$wallet = $ned->wallet();
// Add an extra storage and beta entitlement with different prices
@@ -344,13 +344,13 @@
->with('@user-subscriptions', function (Browser $browser) {
$browser->assertElementsCount('table tbody tr', 6)
->assertSeeIn('table tbody tr:nth-child(1) td:first-child', 'User Mailbox')
- ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '3,99 CHF/month¹')
- ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 3 GB')
+ ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,50 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 6 GB')
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '45,00 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features')
- ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,99 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,41 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(4) td:first-child', 'Activesync')
- ->assertSeeIn('table tbody tr:nth-child(4) td:last-child', '0,90 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(4) td:last-child', '0,00 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(5) td:first-child', '2-Factor Authentication')
->assertSeeIn('table tbody tr:nth-child(5) td:last-child', '0,00 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(6) td:first-child', 'Private Beta (invitation only)')
@@ -472,7 +472,7 @@
$this->browse(function (Browser $browser) {
$this->deleteTestUser('userstest1@kolabnow.com');
$user = $this->getTestUser('userstest1@kolabnow.com');
- $sku2fa = Sku::firstOrCreate(['title' => '2fa']);
+ $sku2fa = Sku::withEnvTenantContext()->where('title', '2fa')->first();
$user->assignSku($sku2fa);
SecondFactor::seed('userstest1@kolabnow.com');
diff --git a/src/tests/Browser/Components/QuotaInput.php b/src/tests/Browser/Components/QuotaInput.php
--- a/src/tests/Browser/Components/QuotaInput.php
+++ b/src/tests/Browser/Components/QuotaInput.php
@@ -77,7 +77,7 @@
// Use keyboard because ->value() does not work here
$browser->click('@input')->keys('@input', '{home}');
- $num = $value - 2;
+ $num = $value - 5;
while ($num > 0) {
$browser->keys('@input', '{arrow_right}');
$num--;
diff --git a/src/tests/Browser/Reseller/DashboardTest.php b/src/tests/Browser/Reseller/DashboardTest.php
--- a/src/tests/Browser/Reseller/DashboardTest.php
+++ b/src/tests/Browser/Reseller/DashboardTest.php
@@ -47,7 +47,7 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->assertFocused('@search input')
->assertMissing('@search table');
@@ -105,7 +105,7 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->assertFocused('@search input')
->assertMissing('@search table');
diff --git a/src/tests/Browser/Reseller/DistlistTest.php b/src/tests/Browser/Reseller/DistlistTest.php
--- a/src/tests/Browser/Reseller/DistlistTest.php
+++ b/src/tests/Browser/Reseller/DistlistTest.php
@@ -69,7 +69,7 @@
// Goto the distlist page
$browser->visit(new Home())
- ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->visit($user_page)
->on($user_page)
diff --git a/src/tests/Browser/Reseller/DomainTest.php b/src/tests/Browser/Reseller/DomainTest.php
--- a/src/tests/Browser/Reseller/DomainTest.php
+++ b/src/tests/Browser/Reseller/DomainTest.php
@@ -51,13 +51,13 @@
$this->browse(function (Browser $browser) {
$domain = $this->getTestDomain('kolab.org');
$domain_page = new DomainPage($domain->id);
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
$user = $this->getTestUser('john@kolab.org');
$user_page = new UserPage($user->id);
// Goto the domain page
$browser->visit(new Home())
- ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->visit($user_page)
->on($user_page)
diff --git a/src/tests/Browser/Reseller/InvitationsTest.php b/src/tests/Browser/Reseller/InvitationsTest.php
--- a/src/tests/Browser/Reseller/InvitationsTest.php
+++ b/src/tests/Browser/Reseller/InvitationsTest.php
@@ -45,7 +45,7 @@
$date_regexp = '/^20[0-9]{2}-/';
$browser->visit(new Home())
- ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->assertSeeIn('@links .link-invitations', 'Invitations')
->click('@links .link-invitations')
@@ -129,7 +129,7 @@
// Test deleting
$browser->visit(new Invitations())
- // ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ // ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->assertElementsCount('@table tbody tr', 2)
->click('@table tbody tr:first-child button.button-delete')
->assertToast(Toast::TYPE_SUCCESS, "Invitation deleted successfully.")
@@ -172,7 +172,7 @@
// Test paging (load more) feature
$browser->visit(new Invitations())
- // ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ // ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->assertElementsCount('@table tbody tr', 10)
->assertSeeIn('#more-loader button', 'Load more')
->with('@table tbody', function ($browser) use ($i1, $i2, $i3) {
diff --git a/src/tests/Browser/Reseller/LogonTest.php b/src/tests/Browser/Reseller/LogonTest.php
--- a/src/tests/Browser/Reseller/LogonTest.php
+++ b/src/tests/Browser/Reseller/LogonTest.php
@@ -56,7 +56,7 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('reseller@reseller.com', 'wrong')
+ ->submitLogon('reseller@' . \config('app.domain'), 'wrong')
// Error message
->assertToast(Toast::TYPE_ERROR, 'Invalid username or password.')
// Checks if we're still on the logon page
@@ -71,14 +71,14 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('reseller@reseller.com', 'reseller', true);
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true);
// Checks if we're really on Dashboard page
$browser->on(new Dashboard())
->within(new Menu(), function ($browser) {
$browser->assertMenuItems(['explore', 'blog', 'support', 'dashboard', 'logout', 'lang']);
})
- ->assertUser('reseller@reseller.com');
+ ->assertUser('reseller@' . \config('app.domain'));
// Test that visiting '/' with logged in user does not open logon form
// but "redirects" to the dashboard
@@ -122,7 +122,7 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('reseller@reseller.com', 'reseller', true);
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true);
// Checks if we're really on Dashboard page
$browser->on(new Dashboard());
diff --git a/src/tests/Browser/Reseller/PaymentMollieTest.php b/src/tests/Browser/Reseller/PaymentMollieTest.php
--- a/src/tests/Browser/Reseller/PaymentMollieTest.php
+++ b/src/tests/Browser/Reseller/PaymentMollieTest.php
@@ -29,7 +29,7 @@
*/
public function tearDown(): void
{
- $user = $this->getTestUser('reseller@kolabnow.com');
+ $user = $this->getTestUser('reseller@' . \config('app.domain'));
$wallet = $user->wallets()->first();
$wallet->payments()->delete();
$wallet->balance = 0;
@@ -46,14 +46,14 @@
public function testPayment(): void
{
$this->browse(function (Browser $browser) {
- $user = $this->getTestUser('reseller@kolabnow.com');
+ $user = $this->getTestUser('reseller@' . \config('app.domain'));
$wallet = $user->wallets()->first();
$wallet->payments()->delete();
$wallet->balance = 0;
$wallet->save();
$browser->visit(new Home())
- ->submitLogon($user->email, 'reseller', true, ['paymentProvider' => 'mollie'])
+ ->submitLogon($user->email, \App\Utils::generatePassphrase(), true, ['paymentProvider' => 'mollie'])
->on(new Dashboard())
->click('@links .link-wallet')
->on(new WalletPage())
@@ -63,7 +63,7 @@
$browser->assertSeeIn('@title', 'Top up your wallet')
->waitFor('#payment-method-selection #creditcard')
->waitFor('#payment-method-selection #paypal')
- ->assertMissing('#payment-method-selection #banktransfer')
+ ->waitFor('#payment-method-selection #banktransfer')
->click('#creditcard');
})
->with(new Dialog('@payment-dialog'), function (Browser $browser) {
diff --git a/src/tests/Browser/Reseller/StatsTest.php b/src/tests/Browser/Reseller/StatsTest.php
--- a/src/tests/Browser/Reseller/StatsTest.php
+++ b/src/tests/Browser/Reseller/StatsTest.php
@@ -37,7 +37,7 @@
{
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->assertSeeIn('@links .link-stats', 'Stats')
->click('@links .link-stats')
diff --git a/src/tests/Browser/Reseller/UserFinancesTest.php b/src/tests/Browser/Reseller/UserFinancesTest.php
--- a/src/tests/Browser/Reseller/UserFinancesTest.php
+++ b/src/tests/Browser/Reseller/UserFinancesTest.php
@@ -47,7 +47,7 @@
$page = new UserPage($jack->id);
$browser->visit(new Home())
- ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->visit($page)
->on($page)
@@ -184,9 +184,9 @@
->assertSeeIn('#discount span', '10% - Test voucher')
->click('@nav #tab-subscriptions')
->with('@user-subscriptions', function (Browser $browser) {
- $browser->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '3,99 CHF/month¹')
+ $browser->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,50 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month¹')
- ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,99 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,41 CHF/month¹')
->assertSeeIn('table + .hint', '¹ applied discount: 10% - Test voucher');
})
// Change back to 'none'
@@ -201,9 +201,9 @@
->assertSeeIn('#discount span', 'none')
->click('@nav #tab-subscriptions')
->with('@user-subscriptions', function (Browser $browser) {
- $browser->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,44 CHF/month')
+ $browser->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '5,00 CHF/month')
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month')
- ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '5,55 CHF/month')
+ ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,90 CHF/month')
->assertMissing('table + .hint');
});
});
@@ -271,7 +271,7 @@
->assertSeeIn('tbody tr:first-child td.price', '12,34 CHF');
if (!$browser->isPhone()) {
- $browser->assertSeeIn('tbody tr:first-child td.email', 'reseller@kolabnow.com');
+ $browser->assertSeeIn('tbody tr:first-child td.email', 'reseller@' . \config('app.domain'));
}
});
diff --git a/src/tests/Browser/Reseller/UserTest.php b/src/tests/Browser/Reseller/UserTest.php
--- a/src/tests/Browser/Reseller/UserTest.php
+++ b/src/tests/Browser/Reseller/UserTest.php
@@ -86,7 +86,7 @@
$page = new UserPage($jack->id);
$browser->visit(new Home())
- ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->visit($page)
->on($page);
@@ -133,11 +133,11 @@
->with('@user-subscriptions', function (Browser $browser) {
$browser->assertElementsCount('table tbody tr', 3)
->assertSeeIn('table tbody tr:nth-child(1) td:first-child', 'User Mailbox')
- ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,44 CHF')
- ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 2 GB')
- ->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF')
+ ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '5,00 CHF/month')
+ ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 5 GB')
+ ->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month')
->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features')
- ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '5,55 CHF')
+ ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,90 CHF/month')
->assertMissing('table tfoot')
->assertMissing('#reset2fa');
});
@@ -239,11 +239,11 @@
->with('@user-subscriptions', function (Browser $browser) {
$browser->assertElementsCount('table tbody tr', 3)
->assertSeeIn('table tbody tr:nth-child(1) td:first-child', 'User Mailbox')
- ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '3,99 CHF/month¹')
- ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 2 GB')
+ ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,50 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 5 GB')
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features')
- ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,99 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,41 CHF/month¹')
->assertMissing('table tfoot')
->assertSeeIn('table + .hint', '¹ applied discount: 10% - Test voucher');
});
@@ -321,13 +321,13 @@
->with('@user-subscriptions', function (Browser $browser) {
$browser->assertElementsCount('table tbody tr', 5)
->assertSeeIn('table tbody tr:nth-child(1) td:first-child', 'User Mailbox')
- ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '3,99 CHF/month¹')
- ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 2 GB')
+ ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,50 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 5 GB')
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features')
- ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,99 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,41 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(4) td:first-child', 'Activesync')
- ->assertSeeIn('table tbody tr:nth-child(4) td:last-child', '0,90 CHF/month¹')
+ ->assertSeeIn('table tbody tr:nth-child(4) td:last-child', '0,00 CHF/month¹')
->assertSeeIn('table tbody tr:nth-child(5) td:first-child', '2-Factor Authentication')
->assertSeeIn('table tbody tr:nth-child(5) td:last-child', '0,00 CHF/month¹')
->assertMissing('table tfoot')
diff --git a/src/tests/Browser/Reseller/WalletTest.php b/src/tests/Browser/Reseller/WalletTest.php
--- a/src/tests/Browser/Reseller/WalletTest.php
+++ b/src/tests/Browser/Reseller/WalletTest.php
@@ -29,7 +29,7 @@
*/
public function tearDown(): void
{
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
$wallet = $reseller->wallets()->first();
$wallet->balance = 0;
$wallet->save();
@@ -55,13 +55,13 @@
*/
public function testDashboard(): void
{
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
Wallet::where('user_id', $reseller->id)->update(['balance' => 125]);
// Positive balance
$this->browse(function (Browser $browser) {
$browser->visit(new Home())
- ->submitLogon('reseller@kolabnow.com', 'reseller', true)
+ ->submitLogon('reseller@' . \config('app.domain'), \App\Utils::generatePassphrase(), true)
->on(new Dashboard())
->assertSeeIn('@links .link-wallet .name', 'Wallet')
->assertSeeIn('@links .link-wallet .badge-success', '1,25 CHF');
@@ -84,7 +84,7 @@
*/
public function testWallet(): void
{
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
Wallet::where('user_id', $reseller->id)->update(['balance' => -1234]);
$this->browse(function (Browser $browser) {
@@ -103,7 +103,7 @@
*/
public function testReceipts(): void
{
- $user = $this->getTestUser('reseller@kolabnow.com');
+ $user = $this->getTestUser('reseller@' . \config('app.domain'));
$wallet = $user->wallets()->first();
$wallet->payments()->delete();
@@ -196,7 +196,7 @@
*/
public function testHistory(): void
{
- $user = $this->getTestUser('reseller@kolabnow.com');
+ $user = $this->getTestUser('reseller@' . \config('app.domain'));
$wallet = $user->wallets()->first();
$wallet->transactions()->delete();
diff --git a/src/tests/Browser/UsersTest.php b/src/tests/Browser/UsersTest.php
--- a/src/tests/Browser/UsersTest.php
+++ b/src/tests/Browser/UsersTest.php
@@ -41,8 +41,12 @@
UserAlias::where('user_id', $john->id)
->where('alias', 'john.test@kolab.org')->delete();
- Entitlement::where('entitleable_id', $john->id)->whereIn('cost', [25, 100])->delete();
+ $activesync_sku = Sku::withEnvTenantContext()->where('title', 'activesync')->first();
+ $storage_sku = Sku::withEnvTenantContext()->where('title', 'storage')->first();
+
+ Entitlement::where('entitleable_id', $john->id)->where('sku_id', $activesync_sku->id)->delete();
Entitlement::where('cost', '>=', 5000)->delete();
+ Entitlement::where('cost', '=', 25)->where('sku_id', $storage_sku->id)->delete();
$wallet = $john->wallets()->first();
$wallet->discount()->dissociate();
@@ -64,8 +68,12 @@
UserAlias::where('user_id', $john->id)
->where('alias', 'john.test@kolab.org')->delete();
- Entitlement::where('entitleable_id', $john->id)->whereIn('cost', [25, 100])->delete();
+ $activesync_sku = Sku::withEnvTenantContext()->where('title', 'activesync')->first();
+ $storage_sku = Sku::withEnvTenantContext()->where('title', 'storage')->first();
+
+ Entitlement::where('entitleable_id', $john->id)->where('sku_id', $activesync_sku->id)->delete();
Entitlement::where('cost', '>=', 5000)->delete();
+ Entitlement::where('cost', '=', 25)->where('sku_id', $storage_sku->id)->delete();
$wallet = $john->wallets()->first();
$wallet->discount()->dissociate();
@@ -222,7 +230,7 @@
$browser->assertElementsCount('tbody tr', 6)
// Mailbox SKU
->assertSeeIn('tbody tr:nth-child(1) td.name', 'User Mailbox')
- ->assertSeeIn('tbody tr:nth-child(1) td.price', '4,44 CHF/month')
+ ->assertSeeIn('tbody tr:nth-child(1) td.price', '5,00 CHF/month')
->assertChecked('tbody tr:nth-child(1) td.selection input')
->assertDisabled('tbody tr:nth-child(1) td.selection input')
->assertTip(
@@ -239,12 +247,12 @@
'Some wiggle room'
)
->with(new QuotaInput('tbody tr:nth-child(2) .range-input'), function ($browser) {
- $browser->assertQuotaValue(2)->setQuotaValue(3);
+ $browser->assertQuotaValue(5)->setQuotaValue(6);
})
->assertSeeIn('tr:nth-child(2) td.price', '0,25 CHF/month')
// groupware SKU
->assertSeeIn('tbody tr:nth-child(3) td.name', 'Groupware Features')
- ->assertSeeIn('tbody tr:nth-child(3) td.price', '5,55 CHF/month')
+ ->assertSeeIn('tbody tr:nth-child(3) td.price', '4,90 CHF/month')
->assertChecked('tbody tr:nth-child(3) td.selection input')
->assertEnabled('tbody tr:nth-child(3) td.selection input')
->assertTip(
@@ -253,7 +261,7 @@
)
// ActiveSync SKU
->assertSeeIn('tbody tr:nth-child(4) td.name', 'Activesync')
- ->assertSeeIn('tbody tr:nth-child(4) td.price', '1,00 CHF/month')
+ ->assertSeeIn('tbody tr:nth-child(4) td.price', '0,00 CHF/month')
->assertNotChecked('tbody tr:nth-child(4) td.selection input')
->assertEnabled('tbody tr:nth-child(4) td.selection input')
->assertTip(
@@ -288,7 +296,8 @@
->click('@table tr:nth-child(3) a')
->on(new UserInfo());
- $expected = ['activesync', 'groupware', 'mailbox', 'storage', 'storage', 'storage'];
+ $expected = ['activesync', 'groupware', 'mailbox',
+ 'storage', 'storage', 'storage', 'storage', 'storage', 'storage'];
$this->assertUserEntitlements($john, $expected);
// Test subscriptions interaction
@@ -365,8 +374,8 @@
$browser->assertElementsCount('tbody tr', 2)
->assertSeeIn('tbody tr:nth-child(1)', 'Groupware Account')
->assertSeeIn('tbody tr:nth-child(2)', 'Lite Account')
- ->assertSeeIn('tbody tr:nth-child(1) .price', '9,99 CHF/month')
- ->assertSeeIn('tbody tr:nth-child(2) .price', '4,44 CHF/month')
+ ->assertSeeIn('tbody tr:nth-child(1) .price', '9,90 CHF/month')
+ ->assertSeeIn('tbody tr:nth-child(2) .price', '5,00 CHF/month')
->assertChecked('tbody tr:nth-child(1) input')
->click('tbody tr:nth-child(2) input')
->assertNotChecked('tbody tr:nth-child(1) input')
@@ -427,7 +436,7 @@
$julia = User::where('email', 'julia.roberts@kolab.org')->first();
$alias = UserAlias::where('user_id', $julia->id)->where('alias', 'julia.roberts2@kolab.org')->first();
$this->assertTrue(!empty($alias));
- $this->assertUserEntitlements($julia, ['mailbox', 'storage', 'storage']);
+ $this->assertUserEntitlements($julia, ['mailbox', 'storage', 'storage', 'storage', 'storage', 'storage']);
$this->assertSame('Julia', $julia->getSetting('first_name'));
$this->assertSame('Roberts', $julia->getSetting('last_name'));
$this->assertSame('Test Org', $julia->getSetting('organization'));
@@ -555,17 +564,17 @@
$browser->waitFor('tbody tr')
->assertElementsCount('tbody tr', 6)
// Mailbox SKU
- ->assertSeeIn('tbody tr:nth-child(1) td.price', '3,99 CHF/month¹')
+ ->assertSeeIn('tbody tr:nth-child(1) td.price', '4,50 CHF/month¹')
// Storage SKU
->assertSeeIn('tr:nth-child(2) td.price', '0,00 CHF/month¹')
->with($quota_input, function (Browser $browser) {
$browser->setQuotaValue(100);
})
- ->assertSeeIn('tr:nth-child(2) td.price', '22,05 CHF/month¹')
+ ->assertSeeIn('tr:nth-child(2) td.price', '21,37 CHF/month¹')
// groupware SKU
- ->assertSeeIn('tbody tr:nth-child(3) td.price', '4,99 CHF/month¹')
+ ->assertSeeIn('tbody tr:nth-child(3) td.price', '4,41 CHF/month¹')
// ActiveSync SKU
- ->assertSeeIn('tbody tr:nth-child(4) td.price', '0,90 CHF/month¹')
+ ->assertSeeIn('tbody tr:nth-child(4) td.price', '0,00 CHF/month¹')
// 2FA SKU
->assertSeeIn('tbody tr:nth-child(5) td.price', '0,00 CHF/month¹');
})
@@ -581,8 +590,8 @@
->with('@form', function (Browser $browser) {
$browser->whenAvailable('@packages', function (Browser $browser) {
$browser->assertElementsCount('tbody tr', 2)
- ->assertSeeIn('tbody tr:nth-child(1) .price', '8,99 CHF/month¹') // Groupware
- ->assertSeeIn('tbody tr:nth-child(2) .price', '3,99 CHF/month¹'); // Lite
+ ->assertSeeIn('tbody tr:nth-child(1) .price', '8,91 CHF/month¹') // Groupware
+ ->assertSeeIn('tbody tr:nth-child(2) .price', '4,50 CHF/month¹'); // Lite
})
->assertSeeIn('@packages table + .hint', '¹ applied discount: 10% - Test voucher');
});
@@ -591,8 +600,8 @@
// Test using entitlement cost instead of the SKU cost
$this->browse(function (Browser $browser) use ($wallet) {
$joe = User::where('email', 'joe@kolab.org')->first();
- $beta_sku = Sku::where('title', 'beta')->first();
- $storage_sku = Sku::where('title', 'storage')->first();
+ $beta_sku = Sku::withEnvTenantContext()->where('title', 'beta')->first();
+ $storage_sku = Sku::withEnvTenantContext()->where('title', 'storage')->first();
// Add an extra storage and beta entitlement with different prices
Entitlement::create([
@@ -621,11 +630,11 @@
// Storage SKU
->assertSeeIn('tr:nth-child(2) td.price', '45,00 CHF/month¹')
->with($quota_input, function (Browser $browser) {
- $browser->setQuotaValue(4);
+ $browser->setQuotaValue(7);
})
->assertSeeIn('tr:nth-child(2) td.price', '45,22 CHF/month¹')
->with($quota_input, function (Browser $browser) {
- $browser->setQuotaValue(2);
+ $browser->setQuotaValue(5);
})
->assertSeeIn('tr:nth-child(2) td.price', '0,00 CHF/month¹');
})
@@ -643,7 +652,7 @@
{
$this->browse(function (Browser $browser) {
$john = User::where('email', 'john@kolab.org')->first();
- $sku = Sku::where('title', 'beta')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'beta')->first();
$john->assignSku($sku);
$browser->visit('/user/' . $john->id)
@@ -693,7 +702,14 @@
->click('button[type=submit]')
->assertToast(Toast::TYPE_SUCCESS, 'User data updated successfully.');
- $expected = ['beta', 'distlist', 'groupware', 'mailbox', 'storage', 'storage'];
+ $expected = [
+ 'beta',
+ 'distlist',
+ 'groupware',
+ 'mailbox',
+ 'storage', 'storage', 'storage', 'storage', 'storage'
+ ];
+
$this->assertUserEntitlements($john, $expected);
$browser->visit('/user/' . $john->id)
@@ -702,7 +718,12 @@
->click('button[type=submit]')
->assertToast(Toast::TYPE_SUCCESS, 'User data updated successfully.');
- $expected = ['groupware', 'mailbox', 'storage', 'storage'];
+ $expected = [
+ 'groupware',
+ 'mailbox',
+ 'storage', 'storage', 'storage', 'storage', 'storage'
+ ];
+
$this->assertUserEntitlements($john, $expected);
});
diff --git a/src/tests/Feature/Backends/LDAPTest.php b/src/tests/Feature/Backends/LDAPTest.php
--- a/src/tests/Feature/Backends/LDAPTest.php
+++ b/src/tests/Feature/Backends/LDAPTest.php
@@ -251,7 +251,7 @@
$user->save();
$aliases = ['t1-' . $user->email, 't2-' . $user->email];
$user->setAliases($aliases);
- $package_kolab = \App\Package::where('title', 'kolab')->first();
+ $package_kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
$user->assignPackage($package_kolab);
LDAP::updateUser($user->fresh());
@@ -263,7 +263,7 @@
$expected['cn'] = 'Firstname Lastname';
$expected['sn'] = 'Lastname';
$expected['inetuserstatus'] = $user->status;
- $expected['mailquota'] = 2097152;
+ $expected['mailquota'] = 5242880;
$expected['nsroledn'] = null;
$ldap_user = LDAP::getUser($user->email);
@@ -273,8 +273,8 @@
}
// Update entitlements
- $sku_activesync = \App\Sku::where('title', 'activesync')->first();
- $sku_groupware = \App\Sku::where('title', 'groupware')->first();
+ $sku_activesync = \App\Sku::withEnvTenantContext()->where('title', 'activesync')->first();
+ $sku_groupware = \App\Sku::withEnvTenantContext()->where('title', 'groupware')->first();
$user->assignSku($sku_activesync, 1);
Entitlement::where(['sku_id' => $sku_groupware->id, 'entitleable_id' => $user->id])->delete();
diff --git a/src/tests/Feature/BillingTest.php b/src/tests/Feature/BillingTest.php
--- a/src/tests/Feature/BillingTest.php
+++ b/src/tests/Feature/BillingTest.php
@@ -27,10 +27,10 @@
$this->deleteTestUser('jane@kolabnow.com');
$this->deleteTestUser('jack@kolabnow.com');
- \App\Package::where('title', 'kolab-kube')->delete();
+ \App\Package::withEnvTenantContext()->where('title', 'kolab-kube')->delete();
$this->user = $this->getTestUser('jane@kolabnow.com');
- $this->package = \App\Package::where('title', 'kolab')->first();
+ $this->package = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
$this->user->assignPackage($this->package);
$this->wallet = $this->user->wallets->first();
@@ -43,7 +43,7 @@
$this->deleteTestUser('jane@kolabnow.com');
$this->deleteTestUser('jack@kolabnow.com');
- \App\Package::where('title', 'kolab-kube')->delete();
+ \App\Package::withEnvTenantContext()->where('title', 'kolab-kube')->delete();
parent::tearDown();
}
@@ -53,7 +53,7 @@
*/
public function testTouchAndGo(): void
{
- $this->assertCount(4, $this->wallet->entitlements);
+ $this->assertCount(7, $this->wallet->entitlements);
$this->assertEquals(0, $this->wallet->expectedCharges());
@@ -61,7 +61,7 @@
$this->assertCount(0, $this->wallet->fresh()->entitlements->where('deleted_at', null));
- $this->assertCount(4, $this->wallet->entitlements);
+ $this->assertCount(7, $this->wallet->entitlements);
}
/**
@@ -87,7 +87,7 @@
Carbon::now()->subMonthsWithoutOverflow(1)
);
- $this->assertEquals(999, $this->wallet->expectedCharges());
+ $this->assertEquals(990, $this->wallet->expectedCharges());
}
/**
@@ -100,7 +100,7 @@
Carbon::now()->subMonthsWithoutOverflow(1)->subDays(1)
);
- $this->assertEquals(999, $this->wallet->expectedCharges());
+ $this->assertEquals(990, $this->wallet->expectedCharges());
}
/**
@@ -114,9 +114,9 @@
Carbon::now()->subMonthsWithoutOverflow(1)->subDays(1)
);
- $this->assertEquals(999, $this->wallet->expectedCharges());
+ $this->assertEquals(990, $this->wallet->expectedCharges());
- $sku = \App\Sku::where(['title' => 'storage'])->first();
+ $sku = \App\Sku::withEnvTenantContext()->where('title', 'storage')->first();
$entitlement = \App\Entitlement::create(
[
@@ -133,7 +133,7 @@
Carbon::now()->subMonthsWithoutOverflow(1)->subDays(1)
);
- $this->assertEquals(1024, $this->wallet->expectedCharges());
+ $this->assertEquals(1015, $this->wallet->expectedCharges());
}
/**
@@ -144,9 +144,9 @@
{
$this->backdateEntitlements($this->wallet->entitlements, Carbon::now()->subMonthsWithoutOverflow(1));
- $this->assertEquals(999, $this->wallet->expectedCharges());
+ $this->assertEquals(990, $this->wallet->expectedCharges());
- $sku = \App\Sku::where(['title' => 'storage'])->first();
+ $sku = \App\Sku::withEnvTenantContext()->where(['title' => 'storage'])->first();
$entitlement = \App\Entitlement::create(
[
@@ -160,7 +160,7 @@
$this->backdateEntitlements([$entitlement], Carbon::now()->subDays(14));
- $this->assertEquals(999, $this->wallet->expectedCharges());
+ $this->assertEquals(990, $this->wallet->expectedCharges());
}
public function testFifthWeek(): void
@@ -170,11 +170,11 @@
$this->backdateEntitlements($this->wallet->entitlements, $targetDateA);
- $this->assertEquals(999, $this->wallet->expectedCharges());
+ $this->assertEquals(990, $this->wallet->expectedCharges());
$this->wallet->chargeEntitlements();
- $this->assertEquals(-999, $this->wallet->balance);
+ $this->assertEquals(-990, $this->wallet->balance);
foreach ($this->wallet->entitlements()->get() as $entitlement) {
$this->assertTrue($entitlement->created_at->isSameSecond($targetDateA));
@@ -186,11 +186,11 @@
{
$this->backdateEntitlements($this->wallet->entitlements, Carbon::now()->subMonthsWithoutOverflow(2));
- $this->assertCount(4, $this->wallet->entitlements);
+ $this->assertCount(7, $this->wallet->entitlements);
- $this->assertEquals(1998, $this->wallet->expectedCharges());
+ $this->assertEquals(1980, $this->wallet->expectedCharges());
- $sku = \App\Sku::where(['title' => 'storage'])->first();
+ $sku = \App\Sku::withEnvTenantContext()->where('title', 'storage')->first();
$entitlement = \App\Entitlement::create(
[
@@ -204,7 +204,7 @@
$this->backdateEntitlements([$entitlement], Carbon::now()->subMonthsWithoutOverflow(1));
- $this->assertEquals(2023, $this->wallet->expectedCharges());
+ $this->assertEquals(2005, $this->wallet->expectedCharges());
}
public function testWithDiscountRate(): void
@@ -219,16 +219,16 @@
);
$skus = [
- \App\Sku::firstOrCreate(['title' => 'mailbox']),
- \App\Sku::firstOrCreate(['title' => 'storage']),
- \App\Sku::firstOrCreate(['title' => 'groupware'])
+ \App\Sku::withEnvTenantContext()->where('title', 'mailbox')->first(),
+ \App\Sku::withEnvTenantContext()->where('title', 'storage')->first(),
+ \App\Sku::withEnvTenantContext()->where('title', 'groupware')->first()
];
$package->skus()->saveMany($skus);
$package->skus()->updateExistingPivot(
- \App\Sku::firstOrCreate(['title' => 'storage']),
- ['qty' => 2],
+ \App\Sku::withEnvTenantContext()->where('title', 'storage')->first(),
+ ['qty' => 5],
false
);
@@ -242,7 +242,7 @@
$this->backdateEntitlements($wallet->entitlements, Carbon::now()->subMonthsWithoutOverflow(1));
- $this->assertEquals(500, $wallet->expectedCharges());
+ $this->assertEquals(495, $wallet->expectedCharges());
}
/**
@@ -250,13 +250,13 @@
*/
public function testWithWalletDiscount(): void
{
- $discount = \App\Discount::where('code', 'TEST')->first();
+ $discount = \App\Discount::withEnvTenantContext()->where('code', 'TEST')->first();
$wallet = $this->user->wallets()->first();
$wallet->discount()->associate($discount);
$this->backdateEntitlements($wallet->entitlements, Carbon::now()->subMonthsWithoutOverflow(1));
- $this->assertEquals(898, $wallet->expectedCharges());
+ $this->assertEquals(891, $wallet->expectedCharges());
}
}
diff --git a/src/tests/Feature/Console/DomainRestoreTest.php b/src/tests/Feature/Console/DomainRestoreTest.php
--- a/src/tests/Feature/Console/DomainRestoreTest.php
+++ b/src/tests/Feature/Console/DomainRestoreTest.php
@@ -55,7 +55,7 @@
$wallet = $user->wallets()->first();
$entitlements = $wallet->entitlements->pluck('id')->all();
- $this->assertCount(5, $entitlements);
+ $this->assertCount(8, $entitlements);
// Non-deleted domain
$code = \Artisan::call("domain:restore force-delete.com");
diff --git a/src/tests/Feature/Console/Sku/ListUsersTest.php b/src/tests/Feature/Console/Sku/ListUsersTest.php
--- a/src/tests/Feature/Console/Sku/ListUsersTest.php
+++ b/src/tests/Feature/Console/Sku/ListUsersTest.php
@@ -52,7 +52,16 @@
$code = \Artisan::call('sku:list-users mailbox');
$output = trim(\Artisan::output());
$this->assertSame(0, $code);
- $this->assertSame("jack@kolab.org\njoe@kolab.org\njohn@kolab.org\nned@kolab.org", $output);
+
+ $expected = [
+ "jack@kolab.org",
+ "joe@kolab.org",
+ "john@kolab.org",
+ "ned@kolab.org",
+ "reseller@" . \config('app.domain')
+ ];
+
+ $this->assertSame(implode("\n", $expected), $output);
$code = \Artisan::call('sku:list-users domain-hosting');
$output = trim(\Artisan::output());
diff --git a/src/tests/Feature/Console/UserForceDeleteTest.php b/src/tests/Feature/Console/UserForceDeleteTest.php
--- a/src/tests/Feature/Console/UserForceDeleteTest.php
+++ b/src/tests/Feature/Console/UserForceDeleteTest.php
@@ -44,14 +44,14 @@
'status' => \App\Domain::STATUS_NEW,
'type' => \App\Domain::TYPE_HOSTED,
]);
- $package_kolab = \App\Package::where('title', 'kolab')->first();
- $package_domain = \App\Package::where('title', 'domain-hosting')->first();
+ $package_kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $package_domain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$user->assignPackage($package_kolab);
$domain->assignPackage($package_domain, $user);
$wallet = $user->wallets()->first();
$entitlements = $wallet->entitlements->pluck('id')->all();
- $this->assertCount(5, $entitlements);
+ $this->assertCount(8, $entitlements);
// Non-deleted user
$this->artisan('user:force-delete user@force-delete.com')
diff --git a/src/tests/Feature/Console/UserRestoreTest.php b/src/tests/Feature/Console/UserRestoreTest.php
--- a/src/tests/Feature/Console/UserRestoreTest.php
+++ b/src/tests/Feature/Console/UserRestoreTest.php
@@ -48,14 +48,14 @@
'status' => \App\Domain::STATUS_NEW,
'type' => \App\Domain::TYPE_HOSTED,
]);
- $package_kolab = \App\Package::where('title', 'kolab')->first();
- $package_domain = \App\Package::where('title', 'domain-hosting')->first();
+ $package_kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $package_domain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$user->assignPackage($package_kolab);
$domain->assignPackage($package_domain, $user);
$wallet = $user->wallets()->first();
$entitlements = $wallet->entitlements->pluck('id')->all();
- $this->assertCount(5, $entitlements);
+ $this->assertCount(8, $entitlements);
// Non-deleted user
$code = \Artisan::call("user:restore {$user->email}");
diff --git a/src/tests/Feature/Controller/Admin/DiscountsTest.php b/src/tests/Feature/Controller/Admin/DiscountsTest.php
--- a/src/tests/Feature/Controller/Admin/DiscountsTest.php
+++ b/src/tests/Feature/Controller/Admin/DiscountsTest.php
@@ -25,19 +25,19 @@
}
/**
- * Test listing discounts (/api/v4/discounts)
+ * Test listing discounts (GET /api/v4/users/{user}/discounts)
*/
- public function testIndex(): void
+ public function testuserDiscounts(): void
{
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
// Non-admin user
- $response = $this->actingAs($user)->get("api/v4/discounts");
+ $response = $this->actingAs($user)->get("api/v4/users/{$user->id}/discounts");
$response->assertStatus(403);
// Admin user
- $response = $this->actingAs($admin)->get("api/v4/discounts");
+ $response = $this->actingAs($admin)->get("api/v4/users/{$user->id}/discounts");
$response->assertStatus(200);
$json = $response->json();
@@ -57,5 +57,21 @@
$this->assertSame($discount_free->code, $json['list'][2]['code']);
$this->assertSame($discount_free->description, $json['list'][2]['description']);
$this->assertSame('100% - Free Account', $json['list'][2]['label']);
+
+ // A user in another tenant
+ $user = $this->getTestUser('user@sample-tenant.dev-local');
+ $response = $this->actingAs($admin)->get("api/v4/users/{$user->id}/discounts");
+ $response->assertStatus(200);
+
+ $json = $response->json();
+
+ $discount = Discount::withObjectTenantContext($user)->where('discount', 10)->first();
+
+ $this->assertSame(1, $json['count']);
+ $this->assertSame($discount->id, $json['list'][0]['id']);
+ $this->assertSame($discount->discount, $json['list'][0]['discount']);
+ $this->assertSame($discount->code, $json['list'][0]['code']);
+ $this->assertSame($discount->description, $json['list'][0]['description']);
+ $this->assertSame('10% - ' . $discount->description, $json['list'][0]['label']);
}
}
diff --git a/src/tests/Feature/Controller/Admin/SkusTest.php b/src/tests/Feature/Controller/Admin/SkusTest.php
--- a/src/tests/Feature/Controller/Admin/SkusTest.php
+++ b/src/tests/Feature/Controller/Admin/SkusTest.php
@@ -15,6 +15,8 @@
parent::setUp();
self::useAdminUrl();
+ Sku::where('title', 'test')->delete();
+
$this->clearBetaEntitlements();
$this->clearMeetEntitlements();
}
@@ -24,6 +26,8 @@
*/
public function tearDown(): void
{
+ Sku::where('title', 'test')->delete();
+
$this->clearBetaEntitlements();
$this->clearMeetEntitlements();
@@ -37,7 +41,7 @@
{
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
$user = $this->getTestUser('john@kolab.org');
- $sku = Sku::where('title', 'mailbox')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
// Unauth access not allowed
$response = $this->get("api/v4/skus");
diff --git a/src/tests/Feature/Controller/Admin/WalletsTest.php b/src/tests/Feature/Controller/Admin/WalletsTest.php
--- a/src/tests/Feature/Controller/Admin/WalletsTest.php
+++ b/src/tests/Feature/Controller/Admin/WalletsTest.php
@@ -76,7 +76,7 @@
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
$wallet = $user->wallets()->first();
$balance = $wallet->balance;
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
$wallet = $user->wallets()->first();
$reseller_wallet = $reseller->wallets()->first();
$reseller_balance = $reseller_wallet->balance;
diff --git a/src/tests/Feature/Controller/DomainsTest.php b/src/tests/Feature/Controller/DomainsTest.php
--- a/src/tests/Feature/Controller/DomainsTest.php
+++ b/src/tests/Feature/Controller/DomainsTest.php
@@ -36,7 +36,7 @@
*/
public function testConfirm(): void
{
- $sku_domain = Sku::where('title', 'domain-hosting')->first();
+ $sku_domain = Sku::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$john = $this->getTestUser('john@kolab.org');
$ned = $this->getTestUser('ned@kolab.org');
$user = $this->getTestUser('test1@domainscontroller.com');
@@ -129,7 +129,7 @@
*/
public function testShow(): void
{
- $sku_domain = Sku::where('title', 'domain-hosting')->first();
+ $sku_domain = Sku::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$user = $this->getTestUser('test1@domainscontroller.com');
$domain = $this->getTestDomain('domainscontroller.com', [
'status' => Domain::STATUS_NEW,
diff --git a/src/tests/Feature/Controller/PackagesTest.php b/src/tests/Feature/Controller/PackagesTest.php
--- a/src/tests/Feature/Controller/PackagesTest.php
+++ b/src/tests/Feature/Controller/PackagesTest.php
@@ -17,9 +17,10 @@
$response->assertStatus(401);
$user = $this->getTestUser('john@kolab.org');
- $package_domain = Package::where('title', 'domain-hosting')->first();
- $package_kolab = Package::where('title', 'kolab')->first();
- $package_lite = Package::where('title', 'lite')->first();
+
+ $packageDomain = Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
+ $packageKolab = Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $packageLite = Package::withEnvTenantContext()->where('title', 'lite')->first();
$response = $this->actingAs($user)->get("api/v4/packages");
$response->assertStatus(200);
@@ -28,25 +29,25 @@
$this->assertCount(3, $json);
- $this->assertSame($package_domain->id, $json[0]['id']);
- $this->assertSame($package_domain->title, $json[0]['title']);
- $this->assertSame($package_domain->name, $json[0]['name']);
- $this->assertSame($package_domain->description, $json[0]['description']);
- $this->assertSame($package_domain->isDomain(), $json[0]['isDomain']);
- $this->assertSame($package_domain->cost(), $json[0]['cost']);
-
- $this->assertSame($package_kolab->id, $json[1]['id']);
- $this->assertSame($package_kolab->title, $json[1]['title']);
- $this->assertSame($package_kolab->name, $json[1]['name']);
- $this->assertSame($package_kolab->description, $json[1]['description']);
- $this->assertSame($package_kolab->isDomain(), $json[1]['isDomain']);
- $this->assertSame($package_kolab->cost(), $json[1]['cost']);
-
- $this->assertSame($package_lite->id, $json[2]['id']);
- $this->assertSame($package_lite->title, $json[2]['title']);
- $this->assertSame($package_lite->name, $json[2]['name']);
- $this->assertSame($package_lite->description, $json[2]['description']);
- $this->assertSame($package_lite->isDomain(), $json[2]['isDomain']);
- $this->assertSame($package_lite->cost(), $json[2]['cost']);
+ $this->assertSame($packageDomain->id, $json[0]['id']);
+ $this->assertSame($packageDomain->title, $json[0]['title']);
+ $this->assertSame($packageDomain->name, $json[0]['name']);
+ $this->assertSame($packageDomain->description, $json[0]['description']);
+ $this->assertSame($packageDomain->isDomain(), $json[0]['isDomain']);
+ $this->assertSame($packageDomain->cost(), $json[0]['cost']);
+
+ $this->assertSame($packageKolab->id, $json[1]['id']);
+ $this->assertSame($packageKolab->title, $json[1]['title']);
+ $this->assertSame($packageKolab->name, $json[1]['name']);
+ $this->assertSame($packageKolab->description, $json[1]['description']);
+ $this->assertSame($packageKolab->isDomain(), $json[1]['isDomain']);
+ $this->assertSame($packageKolab->cost(), $json[1]['cost']);
+
+ $this->assertSame($packageLite->id, $json[2]['id']);
+ $this->assertSame($packageLite->title, $json[2]['title']);
+ $this->assertSame($packageLite->name, $json[2]['name']);
+ $this->assertSame($packageLite->description, $json[2]['description']);
+ $this->assertSame($packageLite->isDomain(), $json[2]['isDomain']);
+ $this->assertSame($packageLite->cost(), $json[2]['cost']);
}
}
diff --git a/src/tests/Feature/Controller/PaymentsMollieTest.php b/src/tests/Feature/Controller/PaymentsMollieTest.php
--- a/src/tests/Feature/Controller/PaymentsMollieTest.php
+++ b/src/tests/Feature/Controller/PaymentsMollieTest.php
@@ -928,12 +928,14 @@
$wallet->refresh();
- $this->assertEquals(-112, $wallet->balance);
+ $this->assertTrue($wallet->balance <= -108);
+ $this->assertTrue($wallet->balance >= -114);
$payments = $wallet->payments()->where('id', 're_123456')->get();
$this->assertCount(1, $payments);
- $this->assertSame(-112, $payments[0]->amount);
+ $this->assertTrue($payments[0]->amount <= -108);
+ $this->assertTrue($payments[0]->amount >= -114);
$this->assertSame(-101, $payments[0]->currency_amount);
$this->assertSame('EUR', $payments[0]->currency);
diff --git a/src/tests/Feature/Controller/Reseller/DiscountsTest.php b/src/tests/Feature/Controller/Reseller/DiscountsTest.php
--- a/src/tests/Feature/Controller/Reseller/DiscountsTest.php
+++ b/src/tests/Feature/Controller/Reseller/DiscountsTest.php
@@ -14,10 +14,6 @@
public function setUp(): void
{
parent::setUp();
-
- $tenant = Tenant::where('title', 'Sample Tenant')->first();
- $tenant->discounts()->delete();
-
self::useResellerUrl();
}
@@ -26,82 +22,71 @@
*/
public function tearDown(): void
{
- \config(['app.tenant_id' => 1]);
-
- $tenant = Tenant::where('title', 'Sample Tenant')->first();
- $tenant->discounts()->delete();
-
parent::tearDown();
}
/**
- * Test listing discounts (/api/v4/discounts)
+ * Test listing discounts (GET /api/v4/users/{id}/discounts)
*/
- public function testIndex(): void
+ public function testUserDiscounts(): void
{
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller = $this->getTestUser('reseller@reseller.com');
- $reseller2 = $this->getTestUser('reseller@kolabnow.com');
- $tenant = Tenant::where('title', 'Sample Tenant')->first();
-
- \config(['app.tenant_id' => $tenant->id]);
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
// Non-admin user
- $response = $this->actingAs($user)->get("api/v4/discounts");
+ $response = $this->actingAs($user)->get("api/v4/users/{$user->id}/discounts");
$response->assertStatus(403);
// Admin user
- $response = $this->actingAs($admin)->get("api/v4/discounts");
+ $response = $this->actingAs($admin)->get("api/v4/users/{$user->id}/discounts");
$response->assertStatus(403);
// Reseller user, but different tenant
- $response = $this->actingAs($reseller2)->get("api/v4/discounts");
- $response->assertStatus(403);
+ $response = $this->actingAs($reseller2)->get("api/v4/users/{$user->id}/discounts");
+ $response->assertStatus(404);
- // Reseller (empty list)
- $response = $this->actingAs($reseller)->get("api/v4/discounts");
+ // Reseller
+ $response = $this->actingAs($reseller1)->get("api/v4/users/{$user->id}/discounts");
$response->assertStatus(200);
$json = $response->json();
- $this->assertSame(0, $json['count']);
+ $discount_test = Discount::where('code', 'TEST')->first();
+ $discount_free = Discount::where('discount', 100)->first();
- // Add some discounts
- $discount_test = Discount::create([
- 'description' => 'Test reseller voucher',
- 'code' => 'RESELLER-TEST',
- 'discount' => 10,
- 'active' => true,
- ]);
+ $this->assertSame(3, $json['count']);
+ $this->assertSame($discount_test->id, $json['list'][0]['id']);
+ $this->assertSame($discount_test->discount, $json['list'][0]['discount']);
+ $this->assertSame($discount_test->code, $json['list'][0]['code']);
+ $this->assertSame($discount_test->description, $json['list'][0]['description']);
+ $this->assertSame('10% - Test voucher [TEST]', $json['list'][0]['label']);
- $discount_free = Discount::create([
- 'description' => 'Free account',
- 'discount' => 100,
- 'active' => true,
- ]);
+ $this->assertSame($discount_free->id, $json['list'][2]['id']);
+ $this->assertSame($discount_free->discount, $json['list'][2]['discount']);
+ $this->assertSame($discount_free->code, $json['list'][2]['code']);
+ $this->assertSame($discount_free->description, $json['list'][2]['description']);
+ $this->assertSame('100% - Free Account', $json['list'][2]['label']);
- $discount_test->tenant_id = $tenant->id;
- $discount_test->save();
- $discount_free->tenant_id = $tenant->id;
- $discount_free->save();
+ // A user in another tenant's user
+ $user = $this->getTestUser('user@sample-tenant.dev-local');
- $response = $this->actingAs($reseller)->get("api/v4/discounts");
+ $response = $this->actingAs($reseller1)->get("api/v4/users/{$user->id}/discounts");
+ $response->assertStatus(404);
+
+ $response = $this->actingAs($reseller2)->get("api/v4/users/{$user->id}/discounts");
$response->assertStatus(200);
$json = $response->json();
- $this->assertSame(2, $json['count']);
- $this->assertSame($discount_test->id, $json['list'][0]['id']);
- $this->assertSame($discount_test->discount, $json['list'][0]['discount']);
- $this->assertSame($discount_test->code, $json['list'][0]['code']);
- $this->assertSame($discount_test->description, $json['list'][0]['description']);
- $this->assertSame('10% - Test reseller voucher [RESELLER-TEST]', $json['list'][0]['label']);
+ $discount = Discount::withObjectTenantContext($user)->where('discount', 10)->first();
- $this->assertSame($discount_free->id, $json['list'][1]['id']);
- $this->assertSame($discount_free->discount, $json['list'][1]['discount']);
- $this->assertSame($discount_free->code, $json['list'][1]['code']);
- $this->assertSame($discount_free->description, $json['list'][1]['description']);
- $this->assertSame('100% - Free account', $json['list'][1]['label']);
+ $this->assertSame(1, $json['count']);
+ $this->assertSame($discount->id, $json['list'][0]['id']);
+ $this->assertSame($discount->discount, $json['list'][0]['discount']);
+ $this->assertSame($discount->code, $json['list'][0]['code']);
+ $this->assertSame($discount->description, $json['list'][0]['description']);
+ $this->assertSame('10% - ' . $discount->description, $json['list'][0]['label']);
}
}
diff --git a/src/tests/Feature/Controller/Reseller/DomainsTest.php b/src/tests/Feature/Controller/Reseller/DomainsTest.php
--- a/src/tests/Feature/Controller/Reseller/DomainsTest.php
+++ b/src/tests/Feature/Controller/Reseller/DomainsTest.php
@@ -18,7 +18,6 @@
{
parent::setUp();
self::useResellerUrl();
- \config(['app.tenant_id' => 1]);
$this->deleteTestDomain('domainscontroller.com');
}
@@ -28,7 +27,6 @@
*/
public function tearDown(): void
{
- \config(['app.tenant_id' => 1]);
$this->deleteTestDomain('domainscontroller.com');
parent::tearDown();
@@ -39,7 +37,7 @@
*/
public function testConfirm(): void
{
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
$domain = $this->getTestDomain('domainscontroller.com', [
'status' => Domain::STATUS_NEW,
'type' => Domain::TYPE_EXTERNAL,
@@ -57,8 +55,8 @@
{
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
// Non-admin user
$response = $this->actingAs($user)->get("api/v4/domains");
@@ -68,10 +66,6 @@
$response = $this->actingAs($admin)->get("api/v4/domains");
$response->assertStatus(403);
- // Reseller from a different tenant
- $response = $this->actingAs($reseller2)->get("api/v4/domains");
- $response->assertStatus(403);
-
// Search with no matches expected
$response = $this->actingAs($reseller1)->get("api/v4/domains?search=abcd12.org");
$response->assertStatus(200);
@@ -92,7 +86,6 @@
$this->assertSame('kolab.org', $json['list'][0]['namespace']);
// Search by owner
-
$response = $this->actingAs($reseller1)->get("api/v4/domains?owner={$user->id}");
$response->assertStatus(200);
@@ -115,8 +108,6 @@
$this->assertCount(0, $json['list']);
// Test unauth access to other tenant's domains
- \config(['app.tenant_id' => 2]);
-
$response = $this->actingAs($reseller2)->get("api/v4/domains?search=kolab.org");
$response->assertStatus(200);
@@ -139,11 +130,11 @@
*/
public function testShow(): void
{
- $sku_domain = Sku::where('title', 'domain-hosting')->first();
+ $sku_domain = Sku::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
$user = $this->getTestUser('test1@domainscontroller.com');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$domain = $this->getTestDomain('domainscontroller.com', [
'status' => Domain::STATUS_NEW,
'type' => Domain::TYPE_EXTERNAL,
@@ -166,7 +157,7 @@
// Unauthorized access (tenant != env-tenant)
$response = $this->actingAs($reseller2)->get("api/v4/domains/{$domain->id}");
- $response->assertStatus(403);
+ $response->assertStatus(404);
$response = $this->actingAs($reseller1)->get("api/v4/domains/{$domain->id}");
$response->assertStatus(200);
@@ -178,11 +169,6 @@
$this->assertEquals($domain->status, $json['status']);
$this->assertEquals($domain->type, $json['type']);
// Note: Other properties are being tested in the user controller tests
-
- // Unauthorized access (other domain's tenant)
- \config(['app.tenant_id' => 2]);
- $response = $this->actingAs($reseller2)->get("api/v4/domains/{$domain->id}");
- $response->assertStatus(404);
}
/**
@@ -190,7 +176,7 @@
*/
public function testStatus(): void
{
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
$domain = $this->getTestDomain('kolab.org');
// This end-point does not exist for resellers
@@ -206,8 +192,8 @@
Queue::fake(); // disable jobs
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
\config(['app.tenant_id' => 2]);
@@ -231,7 +217,7 @@
// Test unauthorized access to the reseller API (reseller in another tenant)
$response = $this->actingAs($reseller1)->post("/api/v4/domains/{$domain->id}/suspend", []);
- $response->assertStatus(403);
+ $response->assertStatus(404);
$this->assertFalse($domain->fresh()->isSuspended());
@@ -246,11 +232,6 @@
$this->assertCount(2, $json);
$this->assertTrue($domain->fresh()->isSuspended());
-
- // Test authenticated reseller, but domain belongs to another tenant
- \config(['app.tenant_id' => 1]);
- $response = $this->actingAs($reseller1)->post("/api/v4/domains/{$domain->id}/suspend", []);
- $response->assertStatus(404);
}
/**
@@ -261,8 +242,8 @@
Queue::fake(); // disable jobs
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
\config(['app.tenant_id' => 2]);
@@ -286,7 +267,7 @@
// Test unauthorized access to reseller API (another tenant)
$response = $this->actingAs($reseller1)->post("/api/v4/domains/{$domain->id}/unsuspend", []);
- $response->assertStatus(403);
+ $response->assertStatus(404);
$this->assertTrue($domain->fresh()->isSuspended());
@@ -301,10 +282,5 @@
$this->assertCount(2, $json);
$this->assertFalse($domain->fresh()->isSuspended());
-
- // Test unauthorized access to reseller API (another tenant)
- \config(['app.tenant_id' => 1]);
- $response = $this->actingAs($reseller1)->post("/api/v4/domains/{$domain->id}/unsuspend", []);
- $response->assertStatus(404);
}
}
diff --git a/src/tests/Feature/Controller/Reseller/GroupsTest.php b/src/tests/Feature/Controller/Reseller/GroupsTest.php
--- a/src/tests/Feature/Controller/Reseller/GroupsTest.php
+++ b/src/tests/Feature/Controller/Reseller/GroupsTest.php
@@ -36,8 +36,8 @@
{
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$group = $this->getTestGroup('group-test@kolab.org');
$group->assignToWallet($user->wallets->first());
@@ -49,10 +49,6 @@
$response = $this->actingAs($admin)->get("api/v4/groups");
$response->assertStatus(403);
- // Reseller from a different tenant
- $response = $this->actingAs($reseller2)->get("api/v4/groups");
- $response->assertStatus(403);
-
// Search with no search criteria
$response = $this->actingAs($reseller1)->get("api/v4/groups");
$response->assertStatus(200);
@@ -102,9 +98,6 @@
$this->assertSame(0, $json['count']);
$this->assertCount(0, $json['list']);
- // Test unauth access to other tenant's groups
- \config(['app.tenant_id' => 2]);
-
$response = $this->actingAs($reseller2)->get("api/v4/groups?search=kolab.org");
$response->assertStatus(200);
@@ -129,8 +122,8 @@
{
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
$user = $this->getTestUser('test1@domainscontroller.com');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$group = $this->getTestGroup('group-test@kolab.org');
$group->assignToWallet($user->wallets->first());
@@ -142,7 +135,7 @@
$response->assertStatus(403);
$response = $this->actingAs($reseller2)->get("api/v4/groups/{$group->id}");
- $response->assertStatus(403);
+ $response->assertStatus(404);
$response = $this->actingAs($reseller1)->get("api/v4/groups/{$group->id}");
$response->assertStatus(200);
@@ -163,7 +156,7 @@
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
$group = $this->getTestGroup('group-test@kolab.org');
$group->assignToWallet($user->wallets->first());
@@ -179,7 +172,7 @@
{
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
// Test unauthorized access to reseller API
$response = $this->actingAs($user)->post("/api/v4/groups", []);
@@ -202,8 +195,8 @@
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$group = $this->getTestGroup('group-test@kolab.org');
$group->assignToWallet($user->wallets->first());
@@ -233,9 +226,6 @@
$this->assertTrue($group->fresh()->isSuspended());
- // Test unauth access to other tenant's groups
- \config(['app.tenant_id' => 2]);
-
$response = $this->actingAs($reseller2)->post("/api/v4/groups/{$group->id}/suspend", []);
$response->assertStatus(404);
}
@@ -249,8 +239,8 @@
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$group = $this->getTestGroup('group-test@kolab.org');
$group->assignToWallet($user->wallets->first());
$group->status |= Group::STATUS_SUSPENDED;
@@ -282,9 +272,6 @@
$this->assertFalse($group->fresh()->isSuspended());
- // Test unauth access to other tenant's groups
- \config(['app.tenant_id' => 2]);
-
$response = $this->actingAs($reseller2)->post("/api/v4/groups/{$group->id}/unsuspend", []);
$response->assertStatus(404);
}
diff --git a/src/tests/Feature/Controller/Reseller/InvitationsTest.php b/src/tests/Feature/Controller/Reseller/InvitationsTest.php
--- a/src/tests/Feature/Controller/Reseller/InvitationsTest.php
+++ b/src/tests/Feature/Controller/Reseller/InvitationsTest.php
@@ -19,8 +19,6 @@
SignupInvitation::truncate();
- \config(['app.tenant_id' => 1]);
-
self::useResellerUrl();
}
@@ -31,8 +29,6 @@
{
SignupInvitation::truncate();
- \config(['app.tenant_id' => 1]);
-
parent::tearDown();
}
@@ -45,13 +41,12 @@
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller = $this->getTestUser('reseller@reseller.com');
- $reseller2 = $this->getTestUser('reseller@kolabnow.com');
- $tenant = Tenant::where('title', 'Sample Tenant')->first();
-
- \config(['app.tenant_id' => $tenant->id]);
+ $reseller = $this->getTestUser('reseller@sample-tenant.dev-local');
+ $reseller2 = $this->getTestUser('reseller@' . \config('app.domain'));
$inv = SignupInvitation::create(['email' => 'email1@ext.com']);
+ $inv->tenant_id = $reseller->tenant_id;
+ $inv->save();
// Non-admin user
$response = $this->actingAs($user)->delete("api/v4/invitations/{$inv->id}");
@@ -63,7 +58,7 @@
// Reseller user, but different tenant
$response = $this->actingAs($reseller2)->delete("api/v4/invitations/{$inv->id}");
- $response->assertStatus(403);
+ $response->assertStatus(404);
// Reseller - non-existing invitation identifier
$response = $this->actingAs($reseller)->delete("api/v4/invitations/abd");
@@ -89,12 +84,10 @@
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller = $this->getTestUser('reseller@reseller.com');
- $reseller2 = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$tenant = Tenant::where('title', 'Sample Tenant')->first();
- \config(['app.tenant_id' => $tenant->id]);
-
// Non-admin user
$response = $this->actingAs($user)->get("api/v4/invitations");
$response->assertStatus(403);
@@ -103,10 +96,6 @@
$response = $this->actingAs($admin)->get("api/v4/invitations");
$response->assertStatus(403);
- // Reseller user, but different tenant
- $response = $this->actingAs($reseller2)->get("api/v4/invitations");
- $response->assertStatus(403);
-
// Reseller (empty list)
$response = $this->actingAs($reseller)->get("api/v4/invitations");
$response->assertStatus(200);
@@ -134,13 +123,16 @@
$i13 = SignupInvitation::create(['email' => 'email13@ext.com']);
SignupInvitation::query()->update(['created_at' => now()->subDays('1')]);
+
SignupInvitation::where('id', $i1->id)
->update(['created_at' => now()->subHours('2'), 'status' => SignupInvitation::STATUS_FAILED]);
+
SignupInvitation::where('id', $i2->id)
->update(['created_at' => now()->subHours('3'), 'status' => SignupInvitation::STATUS_SENT]);
+
SignupInvitation::where('id', $i11->id)->update(['created_at' => now()->subDays('3')]);
- SignupInvitation::where('id', $i12->id)->update(['tenant_id' => 1]);
- SignupInvitation::where('id', $i13->id)->update(['tenant_id' => 1]);
+ SignupInvitation::where('id', $i12->id)->update(['tenant_id' => $reseller2->tenant_id]);
+ SignupInvitation::where('id', $i13->id)->update(['tenant_id' => $reseller2->tenant_id]);
$response = $this->actingAs($reseller)->get("api/v4/invitations");
$response->assertStatus(200);
@@ -192,6 +184,14 @@
$this->assertSame(1, $json['page']);
$this->assertFalse($json['hasMore']);
$this->assertSame($i1->id, $json['list'][0]['id']);
+
+ // Reseller user, but different tenant
+ $response = $this->actingAs($reseller2)->get("api/v4/invitations");
+ $response->assertStatus(200);
+
+ $json = $response->json();
+
+ $this->assertSame(2, $json['count']);
}
/**
@@ -203,13 +203,14 @@
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller = $this->getTestUser('reseller@reseller.com');
- $reseller2 = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@sample-tenant.dev-local');
+ $reseller2 = $this->getTestUser('reseller@' . \config('app.domain'));
$tenant = Tenant::where('title', 'Sample Tenant')->first();
- \config(['app.tenant_id' => $tenant->id]);
-
$inv = SignupInvitation::create(['email' => 'email1@ext.com']);
+ $inv->tenant_id = $reseller->tenant_id;
+ $inv->save();
+
SignupInvitation::where('id', $inv->id)->update(['status' => SignupInvitation::STATUS_FAILED]);
// Non-admin user
@@ -222,7 +223,7 @@
// Reseller user, but different tenant
$response = $this->actingAs($reseller2)->post("api/v4/invitations/{$inv->id}/resend");
- $response->assertStatus(403);
+ $response->assertStatus(404);
// Reseller - non-existing invitation identifier
$response = $this->actingAs($reseller)->post("api/v4/invitations/abd/resend");
@@ -248,12 +249,10 @@
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller = $this->getTestUser('reseller@reseller.com');
- $reseller2 = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@sample-tenant.dev-local');
+ $reseller2 = $this->getTestUser('reseller@' . \config('app.domain'));
$tenant = Tenant::where('title', 'Sample Tenant')->first();
- \config(['app.tenant_id' => $tenant->id]);
-
// Non-admin user
$response = $this->actingAs($user)->post("api/v4/invitations", []);
$response->assertStatus(403);
@@ -262,10 +261,6 @@
$response = $this->actingAs($admin)->post("api/v4/invitations", []);
$response->assertStatus(403);
- // Reseller user, but different tenant
- $response = $this->actingAs($reseller2)->post("api/v4/invitations", []);
- $response->assertStatus(403);
-
// Reseller (empty post)
$response = $this->actingAs($reseller)->post("api/v4/invitations", []);
$response->assertStatus(422);
@@ -299,6 +294,10 @@
$this->assertSame(1, $json['count']);
$this->assertSame(1, SignupInvitation::count());
+ $invitation = SignupInvitation::first();
+ $this->assertSame($reseller->tenant_id, $invitation->tenant_id);
+ $this->assertSame($post['email'], $invitation->email);
+
// Test file input (empty file)
$tmpfile = tmpfile();
fwrite($tmpfile, "");
@@ -346,5 +345,13 @@
$this->assertSame('success', $json['status']);
$this->assertSame("2 invitations has been created.", $json['message']);
$this->assertSame(2, $json['count']);
+
+ // Reseller user, but different tenant
+ $post = ['email' => 'test-reseller2@external.org'];
+ $response = $this->actingAs($reseller2)->post("api/v4/invitations", $post);
+ $response->assertStatus(200);
+
+ $invitation = SignupInvitation::where('email', $post['email'])->first();
+ $this->assertSame($reseller2->tenant_id, $invitation->tenant_id);
}
}
diff --git a/src/tests/Feature/Controller/Reseller/PaymentsMollieTest.php b/src/tests/Feature/Controller/Reseller/PaymentsMollieTest.php
--- a/src/tests/Feature/Controller/Reseller/PaymentsMollieTest.php
+++ b/src/tests/Feature/Controller/Reseller/PaymentsMollieTest.php
@@ -29,7 +29,7 @@
// All tests in this file use Mollie
\config(['services.payment_provider' => 'mollie']);
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
$wallet = $reseller->wallets()->first();
Payment::where('wallet_id', $wallet->id)->delete();
Wallet::where('id', $wallet->id)->update(['balance' => 0]);
@@ -42,7 +42,7 @@
*/
public function tearDown(): void
{
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
$wallet = $reseller->wallets()->first();
Payment::where('wallet_id', $wallet->id)->delete();
Wallet::where('id', $wallet->id)->update(['balance' => 0]);
@@ -69,7 +69,7 @@
$response = $this->delete("api/v4/payments/mandate");
$response->assertStatus(401);
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
$wallet = $reseller->wallets()->first();
$wallet->balance = -10;
$wallet->save();
@@ -191,7 +191,7 @@
$response = $this->post("api/v4/payments", []);
$response->assertStatus(401);
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
// Successful payment
$post = ['amount' => '12.34', 'currency' => 'CHF', 'methodId' => 'creditcard'];
@@ -213,7 +213,7 @@
{
Bus::fake();
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
// Empty response
$response = $this->actingAs($reseller)->get("api/v4/payments/pending");
@@ -244,14 +244,15 @@
{
Bus::fake();
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
$response = $this->actingAs($reseller)->get('api/v4/payments/methods?type=' . PaymentProvider::TYPE_ONEOFF);
$response->assertStatus(200);
$json = $response->json();
- $this->assertCount(2, $json);
+ $this->assertCount(3, $json);
$this->assertSame('creditcard', $json[0]['id']);
$this->assertSame('paypal', $json[1]['id']);
+ $this->assertSame('banktransfer', $json[2]['id']);
}
}
diff --git a/src/tests/Feature/Controller/Reseller/SkusTest.php b/src/tests/Feature/Controller/Reseller/SkusTest.php
--- a/src/tests/Feature/Controller/Reseller/SkusTest.php
+++ b/src/tests/Feature/Controller/Reseller/SkusTest.php
@@ -15,7 +15,7 @@
parent::setUp();
self::useResellerUrl();
- \config(['app.tenant_id' => 1]);
+ Sku::where('title', 'test')->delete();
$this->clearBetaEntitlements();
$this->clearMeetEntitlements();
@@ -26,7 +26,7 @@
*/
public function tearDown(): void
{
- \config(['app.tenant_id' => 1]);
+ Sku::where('title', 'test')->delete();
$this->clearBetaEntitlements();
$this->clearMeetEntitlements();
@@ -39,17 +39,17 @@
*/
public function testIndex(): void
{
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
$user = $this->getTestUser('john@kolab.org');
- $sku = Sku::where('title', 'mailbox')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
// Unauth access not allowed
$response = $this->get("api/v4/skus");
$response->assertStatus(401);
- // User access not allowed on admin API
+ // User access not allowed
$response = $this->actingAs($user)->get("api/v4/skus");
$response->assertStatus(403);
@@ -76,7 +76,26 @@
$this->assertSame('user', $json[0]['type']);
$this->assertSame('mailbox', $json[0]['handler']);
- // TODO: Test limiting SKUs to the tenant's SKUs
+ // Test with another tenant
+ $sku = Sku::where('title', 'mailbox')->where('tenant_id', $reseller2->tenant_id)->first();
+ $response = $this->actingAs($reseller2)->get("api/v4/skus");
+ $response->assertStatus(200);
+
+ $json = $response->json();
+
+ $this->assertCount(6, $json);
+
+ $this->assertSame(100, $json[0]['prio']);
+ $this->assertSame($sku->id, $json[0]['id']);
+ $this->assertSame($sku->title, $json[0]['title']);
+ $this->assertSame($sku->name, $json[0]['name']);
+ $this->assertSame($sku->description, $json[0]['description']);
+ $this->assertSame($sku->cost, $json[0]['cost']);
+ $this->assertSame($sku->units_free, $json[0]['units_free']);
+ $this->assertSame($sku->period, $json[0]['period']);
+ $this->assertSame($sku->active, $json[0]['active']);
+ $this->assertSame('user', $json[0]['type']);
+ $this->assertSame('mailbox', $json[0]['handler']);
}
/**
@@ -84,8 +103,8 @@
*/
public function testUserSkus(): void
{
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
$user = $this->getTestUser('john@kolab.org');
@@ -101,9 +120,9 @@
$response = $this->actingAs($admin)->get("api/v4/users/{$user->id}/skus");
$response->assertStatus(403);
- // Reseller from another tenant not allowed
+ // Reseller from another tenant
$response = $this->actingAs($reseller2)->get("api/v4/users/{$user->id}/skus");
- $response->assertStatus(403);
+ $response->assertStatus(404);
// Reseller access
$response = $this->actingAs($reseller1)->get("api/v4/users/{$user->id}/skus");
@@ -113,10 +132,5 @@
$this->assertCount(8, $json);
// Note: Details are tested where we test API\V4\SkusController
-
- // Reseller from another tenant not allowed
- \config(['app.tenant_id' => 2]);
- $response = $this->actingAs($reseller2)->get("api/v4/users/{$user->id}/skus");
- $response->assertStatus(404);
}
}
diff --git a/src/tests/Feature/Controller/Reseller/StatsTest.php b/src/tests/Feature/Controller/Reseller/StatsTest.php
--- a/src/tests/Feature/Controller/Reseller/StatsTest.php
+++ b/src/tests/Feature/Controller/Reseller/StatsTest.php
@@ -30,7 +30,7 @@
{
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller = $this->getTestUser('reseller@kolabnow.com');
+ $reseller = $this->getTestUser('reseller@' . \config('app.domain'));
// Unauth access
$response = $this->get("api/v4/stats/chart/discounts");
diff --git a/src/tests/Feature/Controller/Reseller/UsersTest.php b/src/tests/Feature/Controller/Reseller/UsersTest.php
--- a/src/tests/Feature/Controller/Reseller/UsersTest.php
+++ b/src/tests/Feature/Controller/Reseller/UsersTest.php
@@ -17,7 +17,6 @@
{
parent::setUp();
self::useResellerUrl();
- \config(['app.tenant_id' => 1]);
$this->deleteTestUser('UsersControllerTest1@userscontroller.com');
$this->deleteTestUser('test@testsearch.com');
@@ -33,8 +32,6 @@
$this->deleteTestUser('test@testsearch.com');
$this->deleteTestDomain('testsearch.com');
- \config(['app.tenant_id' => 1]);
-
parent::tearDown();
}
@@ -43,7 +40,7 @@
*/
public function testDestroy(): void
{
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com');
// Test unauth access
@@ -64,10 +61,8 @@
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
-
- \config(['app.tenant_id' => 2]);
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
// Guess access
$response = $this->get("api/v4/users");
@@ -81,10 +76,6 @@
$response = $this->actingAs($admin)->get("api/v4/users");
$response->assertStatus(403);
- // Reseller from another tenant
- $response = $this->actingAs($reseller1)->get("api/v4/users");
- $response->assertStatus(403);
-
// Search with no search criteria
$response = $this->actingAs($reseller2)->get("api/v4/users");
$response->assertStatus(200);
@@ -141,10 +132,10 @@
// Create a domain with some users in the Sample Tenant so we have anything to search for
$domain = $this->getTestDomain('testsearch.com', ['type' => \App\Domain::TYPE_EXTERNAL]);
- $domain->tenant_id = 2;
+ $domain->tenant_id = $reseller2->tenant_id;
$domain->save();
$user = $this->getTestUser('test@testsearch.com');
- $user->tenant_id = 2;
+ $user->tenant_id = $reseller2->tenant_id;
$user->save();
$plan = \App\Plan::where('title', 'group')->first();
$user->assignPlan($plan, $domain);
@@ -260,12 +251,14 @@
*/
public function testReset2FA(): void
{
+ Queue::fake(); // disable jobs
+
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
- $sku2fa = \App\Sku::firstOrCreate(['title' => '2fa']);
+ $sku2fa = \App\Sku::withEnvTenantContext()->where('title', '2fa')->first();
$user->assignSku($sku2fa);
\App\Auth\SecondFactor::seed('userscontrollertest1@userscontroller.com');
@@ -277,11 +270,11 @@
$response->assertStatus(403);
$response = $this->actingAs($reseller2)->post("/api/v4/users/{$user->id}/reset2FA", []);
- $response->assertStatus(403);
+ $response->assertStatus(404);
// Touching admins is forbidden
$response = $this->actingAs($reseller1)->post("/api/v4/users/{$admin->id}/reset2FA", []);
- $response->assertStatus(404);
+ $response->assertStatus(403);
$entitlements = $user->fresh()->entitlements()->where('sku_id', $sku2fa->id)->get();
$this->assertCount(1, $entitlements);
@@ -304,11 +297,6 @@
$sf = new \App\Auth\SecondFactor($user);
$this->assertCount(0, $sf->factors());
-
- // Other tenant's user
- \config(['app.tenant_id' => 2]);
- $response = $this->actingAs($reseller2)->post("/api/v4/users/{$user->id}/reset2FA", []);
- $response->assertStatus(404);
}
/**
@@ -316,7 +304,7 @@
*/
public function testStore(): void
{
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
// The end-point does not exist
$response = $this->actingAs($reseller1)->post("/api/v4/users", []);
@@ -332,8 +320,8 @@
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
// Test unauthorized access
$response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/suspend", []);
@@ -343,10 +331,10 @@
$response->assertStatus(403);
$response = $this->actingAs($reseller2)->post("/api/v4/users/{$user->id}/suspend", []);
- $response->assertStatus(403);
+ $response->assertStatus(404);
$response = $this->actingAs($reseller1)->post("/api/v4/users/{$admin->id}/suspend", []);
- $response->assertStatus(404);
+ $response->assertStatus(403);
$this->assertFalse($user->isSuspended());
@@ -361,11 +349,6 @@
$this->assertCount(2, $json);
$this->assertTrue($user->fresh()->isSuspended());
-
- // Access to other tenant's users
- \config(['app.tenant_id' => 2]);
- $response = $this->actingAs($reseller2)->post("/api/v4/users/{$user->id}/suspend", []);
- $response->assertStatus(404);
}
/**
@@ -377,8 +360,8 @@
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
// Test unauthorized access to admin API
$response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/unsuspend", []);
@@ -388,10 +371,10 @@
$response->assertStatus(403);
$response = $this->actingAs($reseller2)->post("/api/v4/users/{$user->id}/unsuspend", []);
- $response->assertStatus(403);
+ $response->assertStatus(404);
$response = $this->actingAs($reseller1)->post("/api/v4/users/{$admin->id}/unsuspend", []);
- $response->assertStatus(404);
+ $response->assertStatus(403);
$this->assertFalse($user->isSuspended());
$user->suspend();
@@ -408,11 +391,6 @@
$this->assertCount(2, $json);
$this->assertFalse($user->fresh()->isSuspended());
-
- // Access to other tenant's users
- \config(['app.tenant_id' => 2]);
- $response = $this->actingAs($reseller2)->post("/api/v4/users/{$user->id}/unsuspend", []);
- $response->assertStatus(404);
}
/**
@@ -422,8 +400,8 @@
{
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
// Test unauthorized access
$response = $this->actingAs($user)->put("/api/v4/users/{$user->id}", []);
@@ -433,10 +411,10 @@
$response->assertStatus(403);
$response = $this->actingAs($reseller2)->put("/api/v4/users/{$user->id}", []);
- $response->assertStatus(403);
+ $response->assertStatus(404);
$response = $this->actingAs($reseller1)->put("/api/v4/users/{$admin->id}", []);
- $response->assertStatus(404);
+ $response->assertStatus(403);
// Test updatig the user data (empty data)
$response = $this->actingAs($reseller1)->put("/api/v4/users/{$user->id}", []);
@@ -470,10 +448,5 @@
$this->assertSame("User data updated successfully.", $json['message']);
$this->assertCount(2, $json);
$this->assertSame('modified@test.com', $user->getSetting('external_email'));
-
- // Access to other tenant's users
- \config(['app.tenant_id' => 2]);
- $response = $this->actingAs($reseller2)->put("/api/v4/users/{$user->id}", $post);
- $response->assertStatus(404);
}
}
diff --git a/src/tests/Feature/Controller/Reseller/WalletsTest.php b/src/tests/Feature/Controller/Reseller/WalletsTest.php
--- a/src/tests/Feature/Controller/Reseller/WalletsTest.php
+++ b/src/tests/Feature/Controller/Reseller/WalletsTest.php
@@ -15,7 +15,6 @@
{
parent::setUp();
self::useResellerUrl();
- \config(['app.tenant_id' => 1]);
}
/**
@@ -23,7 +22,6 @@
*/
public function tearDown(): void
{
- \config(['app.tenant_id' => 1]);
parent::tearDown();
}
@@ -38,8 +36,8 @@
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$wallet = $user->wallets()->first();
$wallet->discount_id = null;
$wallet->save();
@@ -60,7 +58,7 @@
// Reseller from a different tenant
$response = $this->actingAs($reseller2)->get("api/v4/wallets/{$wallet->id}");
- $response->assertStatus(403);
+ $response->assertStatus(404);
// Reseller
$response = $this->actingAs($reseller1)->get("api/v4/wallets/{$wallet->id}");
@@ -80,9 +78,14 @@
$this->assertTrue(!empty($json['notice']));
// Reseller from a different tenant
- \config(['app.tenant_id' => 2]);
- $response = $this->actingAs($reseller2)->get("api/v4/wallets/{$wallet->id}");
- $response->assertStatus(404);
+ $user2 = $this->getTestUser('user@sample-tenant.dev-local');
+ $wallet2 = $user2->wallets()->first();
+ $response = $this->actingAs($reseller2)->get("api/v4/wallets/{$wallet2->id}");
+ $response->assertStatus(200);
+
+ $json = $response->json();
+
+ $this->assertSame($wallet2->id, $json['id']);
}
/**
@@ -92,8 +95,8 @@
{
$user = $this->getTestUser('john@kolab.org');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$wallet = $user->wallets()->first();
$reseller1_wallet = $reseller1->wallets()->first();
$balance = $wallet->balance;
@@ -114,7 +117,7 @@
// Reseller from a different tenant
$response = $this->actingAs($reseller2)->post("api/v4/wallets/{$wallet->id}/one-off", []);
- $response->assertStatus(403);
+ $response->assertStatus(404);
// Admin user - invalid input
$post = ['amount' => 'aaaa'];
@@ -182,11 +185,6 @@
$this->assertSame("Penalized user {$user->email}", $transaction->description);
$this->assertSame(4000, $transaction->amount);
$this->assertSame($reseller1->email, $transaction->user_email);
-
- // Reseller from a different tenant
- \config(['app.tenant_id' => 2]);
- $response = $this->actingAs($reseller2)->post("api/v4/wallets/{$wallet->id}/one-off", []);
- $response->assertStatus(404);
}
/**
@@ -202,8 +200,8 @@
$user = $this->getTestUser('wallets-controller@kolabnow.com');
$wallet = $user->wallets()->first();
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
// Non-admin
$response = $this->actingAs($user)->get("api/v4/wallets/{$wallet->id}/transactions");
@@ -215,7 +213,7 @@
// Reseller from a different tenant
$response = $this->actingAs($reseller2)->get("api/v4/wallets/{$wallet->id}/transactions");
- $response->assertStatus(403);
+ $response->assertStatus(404);
// Create some sample transactions
$transactions = $this->createTestTransactions($wallet);
@@ -245,10 +243,12 @@
// FIXME: Should we hide this for resellers?
$this->assertSame('jeroen@jeroen.jeroen', $json['list'][1]['user']);
- // Reseller from a different tenant
- \config(['app.tenant_id' => 2]);
- $response = $this->actingAs($reseller2)->get("api/v4/wallets/{$wallet->id}/transactions");
- $response->assertStatus(403);
+ // Test another tenant
+ $user2 = $this->getTestUser('user@sample-tenant.dev-local');
+ $wallet2 = $user2->wallets()->first();
+
+ $response = $this->actingAs($reseller2)->get("api/v4/wallets/{$wallet2->id}/transactions");
+ $response->assertStatus(200);
}
/**
@@ -257,8 +257,8 @@
public function testUpdate(): void
{
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$user = $this->getTestUser('john@kolab.org');
$wallet = $user->wallets()->first();
$discount = Discount::where('code', 'TEST')->first();
@@ -273,9 +273,9 @@
// Reseller from another tenant
$response = $this->actingAs($reseller2)->put("api/v4/wallets/{$wallet->id}", []);
- $response->assertStatus(403);
+ $response->assertStatus(404);
- // Admin user - setting a discount
+ // Setting a discount
$post = ['discount' => $discount->id];
$response = $this->actingAs($reseller1)->put("api/v4/wallets/{$wallet->id}", $post);
$response->assertStatus(200);
@@ -290,7 +290,7 @@
$this->assertSame($discount->description, $json['discount_description']);
$this->assertSame($discount->id, $wallet->fresh()->discount->id);
- // Admin user - removing a discount
+ // Removing a discount
$post = ['discount' => null];
$response = $this->actingAs($reseller1)->put("api/v4/wallets/{$wallet->id}", $post);
$response->assertStatus(200);
@@ -303,10 +303,5 @@
$this->assertSame(null, $json['discount_id']);
$this->assertTrue(empty($json['discount_description']));
$this->assertSame(null, $wallet->fresh()->discount);
-
- // Reseller from a different tenant
- \config(['app.tenant_id' => 2]);
- $response = $this->actingAs($reseller2)->put("api/v4/wallets/{$wallet->id}", []);
- $response->assertStatus(404);
}
}
diff --git a/src/tests/Feature/Controller/SkusTest.php b/src/tests/Feature/Controller/SkusTest.php
--- a/src/tests/Feature/Controller/SkusTest.php
+++ b/src/tests/Feature/Controller/SkusTest.php
@@ -44,7 +44,7 @@
$response->assertStatus(401);
$user = $this->getTestUser('john@kolab.org');
- $sku = Sku::where('title', 'mailbox')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
// Create an sku for another tenant, to make sure it is not included in the result
$nsku = Sku::create([
@@ -123,7 +123,7 @@
'enabled' => true,
'readonly' => true,
'range' => [
- 'min' => 2,
+ 'min' => 5,
'max' => 100,
'unit' => 'GB',
]
@@ -190,7 +190,7 @@
$this->assertSame('domain', $json[0]['type']);
// Test inclusion of beta SKUs
- $sku = Sku::where('title', 'beta')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'beta')->first();
$user->assignSku($sku);
$response = $this->actingAs($user)->get("api/v4/users/{$user->id}/skus?type=user");
$response->assertStatus(200);
@@ -226,7 +226,7 @@
*/
protected function assertSkuElement($sku_title, $result, $other = []): void
{
- $sku = Sku::where('title', $sku_title)->first();
+ $sku = Sku::withEnvTenantContext()->where('title', $sku_title)->first();
$this->assertSame($sku->id, $result['id']);
$this->assertSame($sku->title, $result['title']);
diff --git a/src/tests/Feature/Controller/UsersTest.php b/src/tests/Feature/Controller/UsersTest.php
--- a/src/tests/Feature/Controller/UsersTest.php
+++ b/src/tests/Feature/Controller/UsersTest.php
@@ -275,19 +275,19 @@
$json = $response->json();
- $storage_sku = Sku::where('title', 'storage')->first();
- $groupware_sku = Sku::where('title', 'groupware')->first();
- $mailbox_sku = Sku::where('title', 'mailbox')->first();
- $secondfactor_sku = Sku::where('title', '2fa')->first();
+ $storage_sku = Sku::withEnvTenantContext()->where('title', 'storage')->first();
+ $groupware_sku = Sku::withEnvTenantContext()->where('title', 'groupware')->first();
+ $mailbox_sku = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
+ $secondfactor_sku = Sku::withEnvTenantContext()->where('title', '2fa')->first();
$this->assertCount(5, $json['skus']);
- $this->assertSame(2, $json['skus'][$storage_sku->id]['count']);
- $this->assertSame([0,0], $json['skus'][$storage_sku->id]['costs']);
+ $this->assertSame(5, $json['skus'][$storage_sku->id]['count']);
+ $this->assertSame([0,0,0,0,0], $json['skus'][$storage_sku->id]['costs']);
$this->assertSame(1, $json['skus'][$groupware_sku->id]['count']);
- $this->assertSame([555], $json['skus'][$groupware_sku->id]['costs']);
+ $this->assertSame([490], $json['skus'][$groupware_sku->id]['costs']);
$this->assertSame(1, $json['skus'][$mailbox_sku->id]['count']);
- $this->assertSame([444], $json['skus'][$mailbox_sku->id]['costs']);
+ $this->assertSame([500], $json['skus'][$mailbox_sku->id]['costs']);
$this->assertSame(1, $json['skus'][$secondfactor_sku->id]['count']);
$this->assertSame([0], $json['skus'][$secondfactor_sku->id]['costs']);
}
@@ -446,19 +446,19 @@
$this->assertSame(false, $result['process'][6]['state']);
// Test 'skus' property
- $user->assignSku(Sku::where('title', 'beta')->first());
+ $user->assignSku(Sku::withEnvTenantContext()->where('title', 'beta')->first());
$result = UsersController::statusInfo($user);
$this->assertSame(['beta'], $result['skus']);
- $user->assignSku(Sku::where('title', 'meet')->first());
+ $user->assignSku(Sku::withEnvTenantContext()->where('title', 'meet')->first());
$result = UsersController::statusInfo($user);
$this->assertSame(['beta', 'meet'], $result['skus']);
- $user->assignSku(Sku::where('title', 'meet')->first());
+ $user->assignSku(Sku::withEnvTenantContext()->where('title', 'meet')->first());
$result = UsersController::statusInfo($user);
@@ -529,8 +529,8 @@
$this->assertCount(2, $json);
$this->assertSame('The specified email is not available.', $json['errors']['email']);
- $package_kolab = \App\Package::where('title', 'kolab')->first();
- $package_domain = \App\Package::where('title', 'domain-hosting')->first();
+ $package_kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $package_domain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$post = [
'password' => 'simple',
@@ -584,7 +584,8 @@
$this->assertSame('deleted@kolab.org', $aliases[0]->alias);
$this->assertSame('useralias1@kolab.org', $aliases[1]->alias);
// Assert the new user entitlements
- $this->assertUserEntitlements($user, ['groupware', 'mailbox', 'storage', 'storage']);
+ $this->assertUserEntitlements($user, ['groupware', 'mailbox',
+ 'storage', 'storage', 'storage', 'storage', 'storage']);
// Assert the wallet to which the new user should be assigned to
$wallet = $user->wallet();
$this->assertSame($john->wallets()->first()->id, $wallet->id);
@@ -609,7 +610,8 @@
$this->assertSame('Doe2', $user->getSetting('last_name'));
$this->assertSame('TestOrg', $user->getSetting('organization'));
$this->assertCount(0, $user->aliases()->get());
- $this->assertUserEntitlements($user, ['groupware', 'mailbox', 'storage', 'storage']);
+ $this->assertUserEntitlements($user, ['groupware', 'mailbox',
+ 'storage', 'storage', 'storage', 'storage', 'storage']);
// Test acting as account controller (not owner)
@@ -760,12 +762,12 @@
// Create entitlements and additional user for following tests
$owner = $this->getTestUser('UsersControllerTest1@userscontroller.com');
$user = $this->getTestUser('UsersControllerTest2@userscontroller.com');
- $package_domain = Package::where('title', 'domain-hosting')->first();
- $package_kolab = Package::where('title', 'kolab')->first();
- $package_lite = Package::where('title', 'lite')->first();
- $sku_mailbox = Sku::where('title', 'mailbox')->first();
- $sku_storage = Sku::where('title', 'storage')->first();
- $sku_groupware = Sku::where('title', 'groupware')->first();
+ $package_domain = Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
+ $package_kolab = Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $package_lite = Package::withEnvTenantContext()->where('title', 'lite')->first();
+ $sku_mailbox = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
+ $sku_storage = Sku::withEnvTenantContext()->where('title', 'storage')->first();
+ $sku_groupware = Sku::withEnvTenantContext()->where('title', 'groupware')->first();
$domain = $this->getTestDomain(
'userscontroller.com',
@@ -788,7 +790,7 @@
$post = [
'skus' => [
$sku_mailbox->id => 1,
- $sku_storage->id => 3,
+ $sku_storage->id => 6,
$sku_groupware->id => 1,
],
];
@@ -805,10 +807,10 @@
$this->assertUserEntitlements(
$user,
- ['groupware', 'mailbox', 'storage', 'storage', 'storage']
+ ['groupware', 'mailbox', 'storage', 'storage', 'storage', 'storage', 'storage', 'storage']
);
- $this->assertSame([0, 0, 25], $storage_cost);
+ $this->assertSame([0, 0, 0, 0, 0, 25], $storage_cost);
$this->assertTrue(empty($json['statusInfo']));
}
@@ -819,11 +821,11 @@
{
$jane = $this->getTestUser('jane@kolabnow.com');
- $kolab = \App\Package::where('title', 'kolab')->first();
- $storage = \App\Sku::where('title', 'storage')->first();
- $activesync = \App\Sku::where('title', 'activesync')->first();
- $groupware = \App\Sku::where('title', 'groupware')->first();
- $mailbox = \App\Sku::where('title', 'mailbox')->first();
+ $kolab = Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $storage = Sku::withEnvTenantContext()->where('title', 'storage')->first();
+ $activesync = Sku::withEnvTenantContext()->where('title', 'activesync')->first();
+ $groupware = Sku::withEnvTenantContext()->where('title', 'groupware')->first();
+ $mailbox = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
// standard package, 1 mailbox, 1 groupware, 2 storage
$jane->assignPackage($kolab);
@@ -833,7 +835,7 @@
'skus' => [
$mailbox->id => 1,
$groupware->id => 1,
- $storage->id => 4,
+ $storage->id => 7,
$activesync->id => 1
]
];
@@ -850,6 +852,9 @@
'storage',
'storage',
'storage',
+ 'storage',
+ 'storage',
+ 'storage',
'storage'
]
);
@@ -859,7 +864,7 @@
'skus' => [
$mailbox->id => 1,
$groupware->id => 1,
- $storage->id => 6,
+ $storage->id => 9,
$activesync->id => 0
]
];
@@ -877,6 +882,9 @@
'storage',
'storage',
'storage',
+ 'storage',
+ 'storage',
+ 'storage',
'storage'
]
);
@@ -886,7 +894,7 @@
'skus' => [
$mailbox->id => 2,
$groupware->id => 1,
- $storage->id => 6,
+ $storage->id => 9,
$activesync->id => 0
]
];
@@ -904,6 +912,9 @@
'storage',
'storage',
'storage',
+ 'storage',
+ 'storage',
+ 'storage',
'storage'
]
);
@@ -913,7 +924,7 @@
'skus' => [
$mailbox->id => 0,
$groupware->id => 1,
- $storage->id => 6,
+ $storage->id => 9,
$activesync->id => 0
]
];
@@ -931,6 +942,9 @@
'storage',
'storage',
'storage',
+ 'storage',
+ 'storage',
+ 'storage',
'storage'
]
);
@@ -954,6 +968,9 @@
'groupware',
'mailbox',
'storage',
+ 'storage',
+ 'storage',
+ 'storage',
'storage'
]
);
diff --git a/src/tests/Feature/Controller/WalletsTest.php b/src/tests/Feature/Controller/WalletsTest.php
--- a/src/tests/Feature/Controller/WalletsTest.php
+++ b/src/tests/Feature/Controller/WalletsTest.php
@@ -31,7 +31,6 @@
parent::tearDown();
}
-
/**
* Test for getWalletNotice() method
*/
@@ -69,13 +68,13 @@
$wallet->owner->save();
// test "1 month"
- $wallet->balance = 999;
+ $wallet->balance = 990;
$notice = $method->invoke($controller, $wallet);
$this->assertRegExp('/\((1 month|4 weeks)\)/', $notice);
// test "2 months"
- $wallet->balance = 999 * 2.6;
+ $wallet->balance = 990 * 2.6;
$notice = $method->invoke($controller, $wallet);
$this->assertRegExp('/\(2 months 2 weeks\)/', $notice);
@@ -84,7 +83,7 @@
\app()->setLocale('de');
// test "almost 2 years"
- $wallet->balance = 999 * 23.5;
+ $wallet->balance = 990 * 23.5;
$notice = $method->invoke($controller, $wallet);
$this->assertRegExp('/\(1 Jahr 11 Monate\)/', $notice);
diff --git a/src/tests/Feature/Documents/ReceiptTest.php b/src/tests/Feature/Documents/ReceiptTest.php
--- a/src/tests/Feature/Documents/ReceiptTest.php
+++ b/src/tests/Feature/Documents/ReceiptTest.php
@@ -267,9 +267,9 @@
'description' => 'Payment not yet paid',
'wallet_id' => $wallet->id,
'provider' => 'stripe',
- 'amount' => 999,
+ 'amount' => 990,
'currency' => 'CHF',
- 'currency_amount' => 999,
+ 'currency_amount' => 990,
]);
$payment->updated_at = Carbon::create(2020, 5, 1, 0, 0, 0);
$payment->save();
diff --git a/src/tests/Feature/DomainOwnerTest.php b/src/tests/Feature/DomainOwnerTest.php
--- a/src/tests/Feature/DomainOwnerTest.php
+++ b/src/tests/Feature/DomainOwnerTest.php
@@ -2,7 +2,6 @@
namespace Tests\Feature;
-use App\Package;
use App\User;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -42,11 +41,13 @@
]
);
- $package = Package::where('title', 'kolab')->first();
+ $package = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $mailbox_sku = \App\Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
$john->assignPackage($package, $jane);
// assert jane has a mailbox entitlement
- $this->assertTrue($jane->entitlements->count() == 4);
+ $this->assertCount(7, $jane->entitlements);
+ $this->assertCount(1, $jane->entitlements()->where('sku_id', $mailbox_sku->id)->get());
}
}
diff --git a/src/tests/Feature/EntitlementTest.php b/src/tests/Feature/EntitlementTest.php
--- a/src/tests/Feature/EntitlementTest.php
+++ b/src/tests/Feature/EntitlementTest.php
@@ -43,12 +43,12 @@
*/
public function testCostsPerDay(): void
{
- // 444
- // 28 days: 15.86
- // 31 days: 14.32
+ // 500
+ // 28 days: 17.86
+ // 31 days: 16.13
$user = $this->getTestUser('entitlement-test@kolabnow.com');
- $package = Package::where('title', 'kolab')->first();
- $mailbox = Sku::where('title', 'mailbox')->first();
+ $package = Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $mailbox = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
$user->assignPackage($package);
@@ -56,8 +56,8 @@
$costsPerDay = $entitlement->costsPerDay();
- $this->assertTrue($costsPerDay < 15.86);
- $this->assertTrue($costsPerDay > 14.32);
+ $this->assertTrue($costsPerDay < 17.86);
+ $this->assertTrue($costsPerDay > 16.31);
}
/**
@@ -66,11 +66,11 @@
*/
public function testEntitlements(): void
{
- $packageDomain = Package::where('title', 'domain-hosting')->first();
- $packageKolab = Package::where('title', 'kolab')->first();
+ $packageDomain = Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
+ $packageKolab = Package::withEnvTenantContext()->where('title', 'kolab')->first();
- $skuDomain = Sku::where('title', 'domain-hosting')->first();
- $skuMailbox = Sku::where('title', 'mailbox')->first();
+ $skuDomain = Sku::withEnvTenantContext()->where('title', 'domain-hosting')->first();
+ $skuMailbox = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
$owner = $this->getTestUser('entitlement-test@kolabnow.com');
$user = $this->getTestUser('entitled-user@custom-domain.com');
@@ -89,10 +89,10 @@
$wallet = $owner->wallets->first();
- $this->assertCount(4, $owner->entitlements()->get());
+ $this->assertCount(7, $owner->entitlements()->get());
$this->assertCount(1, $skuDomain->entitlements()->where('wallet_id', $wallet->id)->get());
$this->assertCount(2, $skuMailbox->entitlements()->where('wallet_id', $wallet->id)->get());
- $this->assertCount(9, $wallet->entitlements);
+ $this->assertCount(15, $wallet->entitlements);
$this->backdateEntitlements(
$owner->entitlements,
@@ -111,14 +111,14 @@
{
$user = $this->getTestUser('entitlement-test@kolabnow.com');
- $package = \App\Package::where('title', 'kolab')->first();
+ $package = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
$user->assignPackage($package);
$wallet = $user->wallets()->first();
$this->assertNotNull($wallet);
- $sku = \App\Sku::where('title', 'mailbox')->first();
+ $sku = \App\Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
$entitlement = Entitlement::where('wallet_id', $wallet->id)
->where('sku_id', $sku->id)->first();
@@ -135,8 +135,8 @@
*/
public function testEntitlementTitle(): void
{
- $packageDomain = Package::where('title', 'domain-hosting')->first();
- $packageKolab = Package::where('title', 'kolab')->first();
+ $packageDomain = Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
+ $packageKolab = Package::withEnvTenantContext()->where('title', 'kolab')->first();
$user = $this->getTestUser('entitled-user@custom-domain.com');
$group = $this->getTestGroup('test-group@custom-domain.com');
@@ -153,9 +153,9 @@
$user->assignPackage($packageKolab);
$group->assignToWallet($wallet);
- $sku_mailbox = \App\Sku::where('title', 'mailbox')->first();
- $sku_group = \App\Sku::where('title', 'group')->first();
- $sku_domain = \App\Sku::where('title', 'domain-hosting')->first();
+ $sku_mailbox = \App\Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
+ $sku_group = \App\Sku::withEnvTenantContext()->where('title', 'group')->first();
+ $sku_domain = \App\Sku::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$entitlement = Entitlement::where('wallet_id', $wallet->id)
->where('sku_id', $sku_mailbox->id)->first();
diff --git a/src/tests/Feature/Jobs/WalletCheckTest.php b/src/tests/Feature/Jobs/WalletCheckTest.php
--- a/src/tests/Feature/Jobs/WalletCheckTest.php
+++ b/src/tests/Feature/Jobs/WalletCheckTest.php
@@ -304,11 +304,11 @@
$wallet->save();
$now = Carbon::now();
- $package = \App\Package::where('title', 'kolab')->first();
+ $package = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
$user->assignPackage($package);
$this->assertFalse($user->isDeleted());
- $this->assertCount(4, $user->entitlements()->get());
+ $this->assertCount(7, $user->entitlements()->get());
// Balance turned negative 7+14+21+1 days ago, expect mail sent
$days = 7 + 14 + 21 + 1;
diff --git a/src/tests/Feature/PlanTest.php b/src/tests/Feature/PlanTest.php
--- a/src/tests/Feature/PlanTest.php
+++ b/src/tests/Feature/PlanTest.php
@@ -95,13 +95,13 @@
}
$this->assertTrue(
- $package_costs == 999,
- "The total costs of all packages for this plan is not 9.99"
+ $package_costs == 990,
+ "The total costs of all packages for this plan is not 9.90"
);
$this->assertTrue(
- $plan->cost() == 999,
- "The total costs for this plan is not 9.99"
+ $plan->cost() == 990,
+ "The total costs for this plan is not 9.90"
);
$this->assertTrue($plan->cost() == $package_costs);
@@ -109,16 +109,16 @@
public function testTenant(): void
{
- $plan = Plan::where('title', 'individual')->first();
+ $plan = Plan::withEnvTenantContext()->where('title', 'individual')->first();
$tenant = $plan->tenant()->first();
$this->assertInstanceof(\App\Tenant::class, $tenant);
- $this->assertSame(1, $tenant->id);
+ $this->assertSame((int) \config('app.tenant_id'), $tenant->id);
$tenant = $plan->tenant;
$this->assertInstanceof(\App\Tenant::class, $tenant);
- $this->assertSame(1, $tenant->id);
+ $this->assertSame((int) \config('app.tenant_id'), $tenant->id);
}
}
diff --git a/src/tests/Feature/SkuTest.php b/src/tests/Feature/SkuTest.php
--- a/src/tests/Feature/SkuTest.php
+++ b/src/tests/Feature/SkuTest.php
@@ -32,10 +32,7 @@
$wallet = $user->wallets()->first();
- $package = Package::where('title', 'lite')->first();
-
- $sku_mailbox = Sku::where('title', 'mailbox')->first();
- $sku_storage = Sku::where('title', 'storage')->first();
+ $package = Package::withEnvTenantContext()->where('title', 'lite')->first();
$user = $user->assignPackage($package);
@@ -48,17 +45,17 @@
public function testSkuEntitlements(): void
{
- $this->assertCount(4, Sku::where('title', 'mailbox')->first()->entitlements);
+ $this->assertCount(5, Sku::withEnvTenantContext()->where('title', 'mailbox')->first()->entitlements);
}
public function testSkuPackages(): void
{
- $this->assertCount(2, Sku::where('title', 'mailbox')->first()->packages);
+ $this->assertCount(2, Sku::withEnvTenantContext()->where('title', 'mailbox')->first()->packages);
}
public function testSkuHandlerDomainHosting(): void
{
- $sku = Sku::where('title', 'domain-hosting')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$entitlement = $sku->entitlements->first();
@@ -70,7 +67,7 @@
public function testSkuHandlerMailbox(): void
{
- $sku = Sku::where('title', 'mailbox')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
$entitlement = $sku->entitlements->first();
@@ -82,7 +79,7 @@
public function testSkuHandlerStorage(): void
{
- $sku = Sku::where('title', 'storage')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'storage')->first();
$entitlement = $sku->entitlements->first();
@@ -94,16 +91,14 @@
public function testSkuTenant(): void
{
- $sku = Sku::where('title', 'storage')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'storage')->first();
$tenant = $sku->tenant()->first();
$this->assertInstanceof(\App\Tenant::class, $tenant);
- $this->assertSame(1, $tenant->id);
$tenant = $sku->tenant;
$this->assertInstanceof(\App\Tenant::class, $tenant);
- $this->assertSame(1, $tenant->id);
}
}
diff --git a/src/tests/Feature/TenantTest.php b/src/tests/Feature/TenantTest.php
--- a/src/tests/Feature/TenantTest.php
+++ b/src/tests/Feature/TenantTest.php
@@ -30,7 +30,7 @@
public function testWallet(): void
{
$tenant = Tenant::find(1);
- $user = \App\User::where('email', 'reseller@kolabnow.com')->first();
+ $user = \App\User::where('email', 'reseller@' . \config('app.domain'))->first();
$wallet = $tenant->wallet();
diff --git a/src/tests/Feature/UserTest.php b/src/tests/Feature/UserTest.php
--- a/src/tests/Feature/UserTest.php
+++ b/src/tests/Feature/UserTest.php
@@ -92,8 +92,8 @@
$john = $this->getTestUser('john@kolab.org');
$ned = $this->getTestUser('ned@kolab.org');
$jack = $this->getTestUser('jack@kolab.org');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
$domain = $this->getTestDomain('kolab.org');
@@ -162,8 +162,8 @@
$john = $this->getTestUser('john@kolab.org');
$ned = $this->getTestUser('ned@kolab.org');
$jack = $this->getTestUser('jack@kolab.org');
- $reseller1 = $this->getTestUser('reseller@kolabnow.com');
- $reseller2 = $this->getTestUser('reseller@reseller.com');
+ $reseller1 = $this->getTestUser('reseller@' . \config('app.domain'));
+ $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local');
$admin = $this->getTestUser('jeroen@jeroen.jeroen');
$domain = $this->getTestDomain('kolab.org');
@@ -297,6 +297,7 @@
public function testDomains(): void
{
$user = $this->getTestUser('john@kolab.org');
+
$domain = $this->getTestDomain('useraccount.com', [
'status' => Domain::STATUS_NEW | Domain::STATUS_ACTIVE,
'type' => Domain::TYPE_PUBLIC,
@@ -317,7 +318,8 @@
$this->assertNotContains('kolab.org', $domains);
// Public domains of other tenants should not be returned
- $domain->tenant_id = 2;
+ $tenant = \App\Tenant::where('id', '!=', \config('app.tenant_id'))->first();
+ $domain->tenant_id = $tenant->id;
$domain->save();
$domains = collect($user->domains())->pluck('namespace')->all();
@@ -325,6 +327,19 @@
$this->assertNotContains($domain->namespace, $domains);
}
+ /**
+ * Test User::hasSku() method
+ */
+ public function testHasSku(): void
+ {
+ $john = $this->getTestUser('john@kolab.org');
+
+ $this->assertTrue($john->hasSku('mailbox'));
+ $this->assertTrue($john->hasSku('storage'));
+ $this->assertFalse($john->hasSku('beta'));
+ $this->assertFalse($john->hasSku('unknown'));
+ }
+
public function testUserQuota(): void
{
// TODO: This test does not test much, probably could be removed
@@ -332,7 +347,7 @@
// other entitlements() related cases.
$user = $this->getTestUser('john@kolab.org');
- $storage_sku = \App\Sku::where('title', 'storage')->first();
+ $storage_sku = \App\Sku::withEnvTenantContext()->where('title', 'storage')->first();
$count = 0;
@@ -342,7 +357,7 @@
}
}
- $this->assertTrue($count == 2);
+ $this->assertTrue($count == 5);
}
/**
@@ -353,12 +368,12 @@
Queue::fake();
$user = $this->getTestUser('user-test@' . \config('app.domain'));
- $package = \App\Package::where('title', 'kolab')->first();
+ $package = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
$user->assignPackage($package);
$id = $user->id;
- $this->assertCount(4, $user->entitlements()->get());
+ $this->assertCount(7, $user->entitlements()->get());
$user->delete();
@@ -380,8 +395,8 @@
$userA = $this->getTestUser('UserAccountA@UserAccount.com');
$userB = $this->getTestUser('UserAccountB@UserAccount.com');
$userC = $this->getTestUser('UserAccountC@UserAccount.com');
- $package_kolab = \App\Package::where('title', 'kolab')->first();
- $package_domain = \App\Package::where('title', 'domain-hosting')->first();
+ $package_kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $package_domain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$domain = $this->getTestDomain('UserAccount.com', [
'status' => Domain::STATUS_NEW,
'type' => Domain::TYPE_HOSTED,
@@ -399,9 +414,9 @@
$entitlementsDomain = \App\Entitlement::where('entitleable_id', $domain->id);
$entitlementsGroup = \App\Entitlement::where('entitleable_id', $group->id);
- $this->assertSame(4, $entitlementsA->count());
- $this->assertSame(4, $entitlementsB->count());
- $this->assertSame(4, $entitlementsC->count());
+ $this->assertSame(7, $entitlementsA->count());
+ $this->assertSame(7, $entitlementsB->count());
+ $this->assertSame(7, $entitlementsC->count());
$this->assertSame(1, $entitlementsDomain->count());
$this->assertSame(1, $entitlementsGroup->count());
@@ -447,7 +462,7 @@
{
Queue::fake();
- $package_kolab = \App\Package::where('title', 'kolab')->first();
+ $package_kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
$userA = $this->getTestUser('UserAccountA@UserAccount.com');
$userB = $this->getTestUser('UserAccountB@UserAccount.com');
$userA->assignPackage($package_kolab, $userB);
@@ -607,8 +622,8 @@
'status' => User::STATUS_LDAP_READY | User::STATUS_IMAP_READY | User::STATUS_SUSPENDED,
]);
$userB = $this->getTestUser('UserAccountB@UserAccount.com');
- $package_kolab = \App\Package::where('title', 'kolab')->first();
- $package_domain = \App\Package::where('title', 'domain-hosting')->first();
+ $package_kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $package_domain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$domainA = $this->getTestDomain('UserAccount.com', [
'status' => Domain::STATUS_NEW,
'type' => Domain::TYPE_HOSTED,
@@ -622,7 +637,7 @@
$domainB->assignPackage($package_domain, $userA);
$userA->assignPackage($package_kolab, $userB);
- $storage_sku = \App\Sku::where('title', 'storage')->first();
+ $storage_sku = \App\Sku::withEnvTenantContext()->where('title', 'storage')->first();
$now = \Carbon\Carbon::now();
$wallet_id = $userA->wallets->first()->id;
@@ -679,7 +694,7 @@
$this->assertFalse($domainA->fresh()->trashed());
// Assert entitlements
- $this->assertSame(4, $entitlementsA->count()); // mailbox + groupware + 2 x storage
+ $this->assertSame(7, $entitlementsA->count()); // mailbox + groupware + 5 x storage
$this->assertTrue($ent1->fresh()->trashed());
$entitlementsA->get()->each(function ($ent) {
$this->assertTrue($ent->updated_at->greaterThan(\Carbon\Carbon::now()->subSeconds(5)));
diff --git a/src/tests/Feature/WalletTest.php b/src/tests/Feature/WalletTest.php
--- a/src/tests/Feature/WalletTest.php
+++ b/src/tests/Feature/WalletTest.php
@@ -76,12 +76,12 @@
*/
public function testBalanceLastsUntil(): void
{
- // Monthly cost of all entitlements: 999
- // 28 days: 35.68 per day
- // 31 days: 32.22 per day
+ // Monthly cost of all entitlements: 990
+ // 28 days: 35.36 per day
+ // 31 days: 31.93 per day
$user = $this->getTestUser('jane@kolabnow.com');
- $package = Package::where('title', 'kolab')->first();
+ $package = Package::withEnvTenantContext()->where('title', 'kolab')->first();
$user->assignPackage($package);
$wallet = $user->wallets()->first();
@@ -100,19 +100,19 @@
$this->assertSame(null, $until);
// User/entitlements created today, balance=-9,99 CHF (monthly cost)
- $wallet->balance = 999;
+ $wallet->balance = 990;
$until = $wallet->balanceLastsUntil();
$daysInLastMonth = \App\Utils::daysInLastMonth();
- $this->assertSame(
- Carbon::now()->addMonthsWithoutOverflow(1)->addDays($daysInLastMonth)->toDateString(),
- $until->toDateString()
- );
+ $delta = Carbon::now()->addMonthsWithoutOverflow(1)->addDays($daysInLastMonth)->diff($until)->days;
+
+ $this->assertTrue($delta <= 1);
+ $this->assertTrue($delta >= -1);
// Old entitlements, 100% discount
$this->backdateEntitlements($wallet->entitlements, Carbon::now()->subDays(40));
- $discount = \App\Discount::where('discount', 100)->first();
+ $discount = \App\Discount::withEnvTenantContext()->where('discount', 100)->first();
$wallet->discount()->associate($discount);
$until = $wallet->refresh()->balanceLastsUntil();
@@ -133,13 +133,13 @@
*/
public function testCostsPerDay(): void
{
- // 999
- // 28 days: 35.68
- // 31 days: 32.22
+ // 990
+ // 28 days: 35.36
+ // 31 days: 31.93
$user = $this->getTestUser('jane@kolabnow.com');
- $package = Package::where('title', 'kolab')->first();
- $mailbox = Sku::where('title', 'mailbox')->first();
+ $package = Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $mailbox = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
$user->assignPackage($package);
@@ -147,8 +147,8 @@
$costsPerDay = $wallet->costsPerDay();
- $this->assertTrue($costsPerDay < 35.68);
- $this->assertTrue($costsPerDay > 32.22);
+ $this->assertTrue($costsPerDay < 35.38);
+ $this->assertTrue($costsPerDay > 31.93);
}
/**
@@ -291,17 +291,17 @@
{
$user = $this->getTestUser('jane@kolabnow.com');
$wallet = $user->wallets()->first();
- $discount = \App\Discount::where('discount', 30)->first();
+ $discount = \App\Discount::withEnvTenantContext()->where('discount', 30)->first();
$wallet->discount()->associate($discount);
$wallet->save();
// Add 40% fee to all SKUs
Sku::select()->update(['fee' => DB::raw("`cost` * 0.4")]);
- $package = Package::where('title', 'kolab')->first();
- $storage = Sku::where('title', 'storage')->first();
+ $package = Package::withEnvTenantContext()->where('title', 'kolab')->first();
+ $storage = Sku::withEnvTenantContext()->where('title', 'storage')->first();
$user->assignPackage($package);
- $user->assignSku($storage, 2);
+ $user->assignSku($storage, 5);
$user->refresh();
// Reset reseller's wallet balance and transactions
@@ -314,7 +314,7 @@
// Test normal charging of entitlements
// ------------------------------------
- // Backdate and chanrge entitlements, we're expecting one month to be charged
+ // Backdate and charge entitlements, we're expecting one month to be charged
// Set fake NOW date to make simpler asserting results that depend on number of days in current/last month
Carbon::setTestNow(Carbon::create(2021, 5, 21, 12));
$backdate = Carbon::now()->subWeeks(7);
@@ -323,26 +323,28 @@
$wallet->refresh();
$reseller_wallet->refresh();
+ // TODO: Update these comments with what is actually being used to calculate these numbers
// 388 + 310 + 17 + 17 = 732
- $this->assertSame(-732, $wallet->balance);
+ $this->assertSame(-778, $wallet->balance);
// 388 - 555 x 40% + 310 - 444 x 40% + 34 - 50 x 40% = 312
- $this->assertSame(312, $reseller_wallet->balance);
+ $this->assertSame(332, $reseller_wallet->balance);
$transactions = Transaction::where('object_id', $wallet->id)
->where('object_type', \App\Wallet::class)->get();
+
$reseller_transactions = Transaction::where('object_id', $reseller_wallet->id)
->where('object_type', \App\Wallet::class)->get();
$this->assertCount(1, $reseller_transactions);
$trans = $reseller_transactions[0];
$this->assertSame("Charged user jane@kolabnow.com", $trans->description);
- $this->assertSame(312, $trans->amount);
+ $this->assertSame(332, $trans->amount);
$this->assertSame(Transaction::WALLET_CREDIT, $trans->type);
$this->assertCount(1, $transactions);
$trans = $transactions[0];
$this->assertSame('', $trans->description);
- $this->assertSame(-732, $trans->amount);
+ $this->assertSame(-778, $trans->amount);
$this->assertSame(Transaction::WALLET_DEBIT, $trans->type);
// TODO: Test entitlement transaction records
@@ -351,8 +353,12 @@
// Test charging on entitlement delete
// -----------------------------------
+ $reseller_wallet->balance = 0;
+ $reseller_wallet->save();
+
$transactions = Transaction::where('object_id', $wallet->id)
->where('object_type', \App\Wallet::class)->delete();
+
$reseller_transactions = Transaction::where('object_id', $reseller_wallet->id)
->where('object_type', \App\Wallet::class)->delete();
@@ -364,12 +370,13 @@
$reseller_wallet->refresh();
// 2 x round(25 / 31 * 19 * 0.7) = 22
- $this->assertSame(-(732 + 22), $wallet->balance);
+ $this->assertSame(-(778 + 22), $wallet->balance);
// 22 - 2 x round(25 * 0.4 / 31 * 19) = 10
- $this->assertSame(312 + 10, $reseller_wallet->balance);
+ $this->assertSame(10, $reseller_wallet->balance);
$transactions = Transaction::where('object_id', $wallet->id)
->where('object_type', \App\Wallet::class)->get();
+
$reseller_transactions = Transaction::where('object_id', $reseller_wallet->id)
->where('object_type', \App\Wallet::class)->get();
@@ -378,6 +385,7 @@
$this->assertSame("Charged user jane@kolabnow.com", $trans->description);
$this->assertSame(5, $trans->amount);
$this->assertSame(Transaction::WALLET_CREDIT, $trans->type);
+
$trans = $reseller_transactions[1];
$this->assertSame("Charged user jane@kolabnow.com", $trans->description);
$this->assertSame(5, $trans->amount);
diff --git a/src/tests/Functional/HorizonTest.php b/src/tests/Functional/HorizonTest.php
--- a/src/tests/Functional/HorizonTest.php
+++ b/src/tests/Functional/HorizonTest.php
@@ -15,10 +15,14 @@
$response->assertStatus(200);
}
+ /*
public function testRegularAccess()
{
+ $this->useRegularUrl();
+
$response = $this->get('horizon/dashboard');
$response->assertStatus(404);
}
+ */
}
diff --git a/src/tests/Functional/Methods/DomainTest.php b/src/tests/Functional/Methods/DomainTest.php
--- a/src/tests/Functional/Methods/DomainTest.php
+++ b/src/tests/Functional/Methods/DomainTest.php
@@ -13,6 +13,8 @@
{
parent::setUp();
+ $this->deleteTestDomain('test.domain');
+
$this->domain = $this->getTestDomain(
'test.domain',
[
diff --git a/src/tests/TestCase.php b/src/tests/TestCase.php
--- a/src/tests/TestCase.php
+++ b/src/tests/TestCase.php
@@ -45,6 +45,27 @@
}
/**
+ * Set baseURL to the regular UI location
+ */
+ protected static function useRegularUrl(): void
+ {
+ // This will set base URL for all tests in a file.
+ // If we wanted to access both user and admin in one test
+ // we can also just call post/get/whatever with full url
+ \config(
+ [
+ 'app.url' => str_replace(
+ ['//admin.', '//reseller.'],
+ ['//', '//'],
+ \config('app.url')
+ )
+ ]
+ );
+
+ url()->forceRootUrl(config('app.url'));
+ }
+
+ /**
* Set baseURL to the admin UI location
*/
protected static function useAdminUrl(): void
diff --git a/src/tests/Unit/TransactionTest.php b/src/tests/Unit/TransactionTest.php
--- a/src/tests/Unit/TransactionTest.php
+++ b/src/tests/Unit/TransactionTest.php
@@ -52,7 +52,7 @@
'description' => "A test award"
]);
- $sku = Sku::where('title', 'mailbox')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'mailbox')->first();
$entitlement = Entitlement::where('sku_id', $sku->id)->first();
$transaction = Transaction::create([
'user_email' => 'test@test.com',
@@ -62,7 +62,7 @@
'amount' => 13
]);
- $sku = Sku::where('title', 'domain-hosting')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$entitlement = Entitlement::where('sku_id', $sku->id)->first();
$transaction = Transaction::create([
'user_email' => 'test@test.com',
@@ -72,7 +72,7 @@
'amount' => 14
]);
- $sku = Sku::where('title', 'storage')->first();
+ $sku = Sku::withEnvTenantContext()->where('title', 'storage')->first();
$entitlement = Entitlement::where('sku_id', $sku->id)->first();
$transaction = Transaction::create([
'user_email' => 'test@test.com',
diff --git a/src/tests/Unit/UtilsTest.php b/src/tests/Unit/UtilsTest.php
--- a/src/tests/Unit/UtilsTest.php
+++ b/src/tests/Unit/UtilsTest.php
@@ -108,8 +108,15 @@
public function testExchangeRate(): void
{
$this->assertSame(1.0, Utils::exchangeRate("DUMMY", "dummy"));
- $this->assertEqualsWithDelta(0.90503424978382, Utils::exchangeRate("CHF", "EUR"), PHP_FLOAT_EPSILON);
- $this->assertEqualsWithDelta(1.1049305595217682, Utils::exchangeRate("EUR", "CHF"), PHP_FLOAT_EPSILON);
+
+ // Exchange rates are volatile, can't test with high accuracy.
+
+ $this->assertTrue(Utils::exchangeRate("CHF", "EUR") >= 0.88);
+ //$this->assertEqualsWithDelta(0.90503424978382, Utils::exchangeRate("CHF", "EUR"), PHP_FLOAT_EPSILON);
+
+ $this->assertTrue(Utils::exchangeRate("EUR", "CHF") <= 1.12);
+ //$this->assertEqualsWithDelta(1.1049305595217682, Utils::exchangeRate("EUR", "CHF"), PHP_FLOAT_EPSILON);
+
$this->expectException(\Exception::class);
$this->assertSame(1.0, Utils::exchangeRate("CHF", "FOO"));
$this->expectException(\Exception::class);