1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 20:54:04 +00:00
Commit graph

1100 commits

Author SHA1 Message Date
Samuel Štancl
00a00a2aff
Pass BroadcastManager to override closures (#23)
* pass BroadcastManager to override closures

* Improve the broadcaster override syntax in the bootstrapper test

* remove unnecessary return

---------

Co-authored-by: lukinovec <lukinovec@gmail.com>
2023-12-20 12:23:37 +01:00
lukinovec
d9b63cdf59
Stop setting $prefixRouteNames to true in path ID MW (#22)
* Stop setting $prefixRouteNames in path ID MW

* Fix code style (php-cs-fixer)

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
2023-12-19 17:44:06 +01:00
lukinovec
ea5a7463b8
Allow mapping nested tenant properties to mail config (#20)
* Use data_get() to allow mapping nested tenant attributes to mail config

* Fix code style (php-cs-fixer)

* Test the data_get() change

* Improve code, add info to docblock

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
2023-12-18 12:42:03 +01:00
lukinovec
ca400b51d2 Fix global/central channel terminology 2023-12-13 19:11:18 +01:00
Samuel Štancl
6c60a834d5
update larastan include 2023-12-12 11:06:43 +01:00
Samuel Štancl
1acdd1bdb6
remove --xdebug from phpstan job 2023-12-12 11:03:53 +01:00
a5800452ac update larastan dependency 2023-12-12 10:53:23 +01:00
lukinovec
e4df597d81
Make providing identification middleware statically to controllers work (#18)
* Test identification with universal flag with statically provided MW

* Include statically provided controller MW in `tenancy()->getRouteMiddleware()`

* Fix code style (php-cs-fixer)

* Fix PHPStan error

* Test path ID MW and route cloning with statically provided MW

* Create validate.yml

* set continue-on-error to true

* change continue-on-error to fail-fast

* add job name and use if: always()

* update todo

* Update path identification and Fortify integration-related logic (#13)

* Add commented UrlBinding + FortifyRouteTenancy bootstrappers to the config

* Improve FortifyRoute bootstrapper docblock

* Rename bootstrappers

* Complete renaming

* Pass defaults of the original URL generator to the new one

* Fix URL generator-related test (query string id test WIP)

* Fix code style (php-cs-fixer)

* Make Fortify bootstrapper not depend on the UrlGenerator bootstrapper, update comments

* Fix testing UrlGenerator bootstrapper

* Update TenancyUrlGenerator annotations

* Pass tenant parameter manually in Fortify bootstrapper

* Properly test TenancyUrlGenerator functionality

* Get rid of query string in Fortify bootstrapper

* Fix code style (php-cs-fixer)

* Delete outdated comment

* Improve comment

* Improve before/afterEach

* Encourage passing parameters using TenancyUrlGenerator instead of URL::defaults()

* Delete rest of defaulting logic

* Fix code style (php-cs-fixer)

* Delete test group

* Update ForgetTenantParameter docblock

* Update passTenantParameterToRoutes annotation

* Complete todo in test

* Improve test

* Update comment

* Improve comment

* Add keepQueryParameters bool to Fortify bootstrapper

* Test keepQueryParameters

* minor docblock update

* minor docblock changes

* Delete extra import

* Update src/Overrides/TenancyUrlGenerator.php

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>

* Improve comment

* Rename test

* Update bypass parameter-related test comments

* Fix merge

* Rename $keepQueryParameters

* Add docblock

* Add comment

* Refactor Fortify bootstrapper

* Fix code style (php-cs-fixer)

* Fix comment

* Skip Fortify bootstrapper test

* minor code improvements

* Improve fortify bootstrapper test

* Add Fortify bootstrapper annotation, improve code

* Fix code style (php-cs-fixer)

* Add commenet

* Complete resource syncing todo (cleanup not needed)

* Delete incorrect namespace

* Complete route context trait name todo

* Fix code style (php-cs-fixer)

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>

* Include statically provided controller MW in `tenancy()->getRouteMiddleware()`

* Fix code style (php-cs-fixer)

* Improve PHPStan error fix

* Include statically provided controller MW in `tenancy()->getRouteMiddleware()`

* Fix PHPStan error

* Fix code style (php-cs-fixer)

* Include statically provided controller MW in `tenancy()->getRouteMiddleware()`

* Fix code style (php-cs-fixer)

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-12-01 09:38:43 +01:00
lukinovec
4953c69fd8
Update path identification and Fortify integration-related logic (#13)
* Add commented UrlBinding + FortifyRouteTenancy bootstrappers to the config

* Improve FortifyRoute bootstrapper docblock

* Rename bootstrappers

* Complete renaming

* Pass defaults of the original URL generator to the new one

* Fix URL generator-related test (query string id test WIP)

* Fix code style (php-cs-fixer)

* Make Fortify bootstrapper not depend on the UrlGenerator bootstrapper, update comments

* Fix testing UrlGenerator bootstrapper

* Update TenancyUrlGenerator annotations

* Pass tenant parameter manually in Fortify bootstrapper

* Properly test TenancyUrlGenerator functionality

* Get rid of query string in Fortify bootstrapper

* Fix code style (php-cs-fixer)

* Delete outdated comment

* Improve comment

* Improve before/afterEach

* Encourage passing parameters using TenancyUrlGenerator instead of URL::defaults()

* Delete rest of defaulting logic

* Fix code style (php-cs-fixer)

* Delete test group

* Update ForgetTenantParameter docblock

* Update passTenantParameterToRoutes annotation

* Complete todo in test

* Improve test

* Update comment

* Improve comment

* Add keepQueryParameters bool to Fortify bootstrapper

* Test keepQueryParameters

* minor docblock update

* minor docblock changes

* Delete extra import

* Update src/Overrides/TenancyUrlGenerator.php

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>

* Improve comment

* Rename test

* Update bypass parameter-related test comments

* Fix merge

* Rename $keepQueryParameters

* Add docblock

* Add comment

* Refactor Fortify bootstrapper

* Fix code style (php-cs-fixer)

* Fix comment

* Skip Fortify bootstrapper test

* minor code improvements

* Improve fortify bootstrapper test

* Add Fortify bootstrapper annotation, improve code

* Fix code style (php-cs-fixer)

* Add commenet

* Complete resource syncing todo (cleanup not needed)

* Delete incorrect namespace

* Complete route context trait name todo

* Fix code style (php-cs-fixer)

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-11-26 21:08:41 +01:00
Samuel Štancl
c043661318
update todo 2023-11-21 02:11:33 +01:00
Samuel Štancl
c6e6964e24
add job name and use if: always() 2023-11-21 02:10:35 +01:00
Samuel Štancl
ce1585ed71
change continue-on-error to fail-fast 2023-11-21 02:07:33 +01:00
Samuel Štancl
d182df4458
set continue-on-error to true 2023-11-21 02:03:00 +01:00
Samuel Štancl
9512886306
Create validate.yml 2023-11-21 01:59:36 +01:00
lukinovec
8b0bdd42ed Make getCustomColumns() static in SingleDomainTenant 2023-11-09 09:35:06 +01:00
lukinovec
e25e7b7961
Single-domain tenants (#16)
* Add SingleDomainTenant

* Add logic for single domain tenants

* Test that the single domain approach works (wip)

* Fix code style (php-cs-fixer)

* Simplify SubdomainTest tests

* Add single domain tenant conditions to DomainTenantResolver

* Test single domain tenants in resolver test

* Fix test name typo

* Improve runUsingBothDomainApproaches()

* Delete extra tenancy()->end()

* Test early identification with both domain approaches

* Test that things work with both domain approaches in the rest of the tests

* Fix falsely passing test

* Fix PHPStan errors

* Change SingleDomainTenant to a contract, add SingleDomainTenant test model

* Fix TenantList domainsCLI()

* Improve setCurrentDomain() check

* Fix code style (php-cs-fixer)

* Add annotation

* Revert getCustomColumns() change

* Add comments

* Use the domain returned by the closure in runUsingBoth..()

* Delete `migrate` from test

* Improve test names

* Use variable instead of repeating the same string multiple times

* Update comment

* Add comment

* Clean up PreventAccess test

* Don't assign domain to a single-use variable

* Update comments

* Uncomment datasets

* Add todo

* Fix user impersonation test

* Don't specify tenant key when creating tenant in runUsingBoth..()

* Improve universal route test

* Improve `runUsingBothDomainApproaches()`

* Add tests specific to single domain tenants

* Get rid of the runUsingBothDomainApproaches method

* Add test file specific for the single domain tenant feature

* Rename test

* Make getCustomColumns() function static

* Positiopn datasets differently

* Fix early id test

* Add prevent MW to route MW in test

* Fix single domain tenant tests

* Delete SingleDomainTenantTest (CI testing)

* Add the test file back

* TUrn APP_DEBUG on temporarily

* Turn debug off

* Try creating tenant with non-unique domain (CI testing)

* dd duplicate tenant records

* Revert testing change

* Make SingleDomainTenant not extend base tenant (VirtualColumn issues)

* Fix early id test

* add todo

* Use dev-master stancl/virtualcolumn

* Make SingleDomainTenant extend the tenant base model

* remove todo

* Clean up EarlyIdentificationTest changes

* Finish test file cleanup

* Fix test

* improve test

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-11-08 11:38:26 +01:00
lukinovec
c34952f328
Add broadcasting channel prefixing bootstrapper (#12)
* Rename old broadcast bootstrapper, add new one

* Add broadcast tenancy bootstrapper + tests

* Fix code style (php-cs-fixer)

* Fix prefixing

* Work on th bootstrapper's tests (wip – problem with events)

* Fix bootstrapper

* Test that auth closures of channels work correctly

* Fix bootstrapper

* Fix code style (php-cs-fixer)

* Delete channel cloning bootstrapper

* Add bootstrapper that prefixes broadcastOn channels under the hood

* Add broadcast channel registering helpers

* Update prefixing tests (WIP)

* Fix code style (php-cs-fixer)

* Improve comment

* Fix code style (php-cs-fixer)

* Allow customization of Pusher/Ably broadcaster extension

* Fix code style (php-cs-fixer)

* Implement prefix bootstrapper logic, test channel prefixing using a closure

* Work on the prefixing bootstrapper and tests

* Fix code style (php-cs-fixer)

* Add optional $options param to broadcasting helpers

* Test broadcasting helpers

* Fix code style (php-cs-fixer)

* Broadcasting channel prefixing + testing progress

* Improve helper methods

* Fix and improve test

* Fix extending in bootstrap()

* Fix code style (php-cs-fixer)

* Add docblocks, name things more accurately

* Fix code style (php-cs-fixer)

* Delete redundant method from testing broadcaster

* Test Pusher channel prefixing (probabaly redundant?)

* Test if channels get prefixed correctly when switching tenants

* Work with the current broadcast manager instead of overriding it

* Give the original channels to the overriden broadcasters

* Fix code style (php-cs-fixer)

* Simplify channel prefix bootstrapper

* Fix code style (php-cs-fixer)

* Fix comment

* Fix test

* Delete annotation

* Delete unused classes from test

* Delete outdated test

* Move broadcasting bootstrapper test to BootstrapperTest

* Improve bootstrapper test, delete unused event

* Add annotations to the bootstrapper

* Fix code style (php-cs-fixer)

* Improve wording

* Improve comment

* Update src/Bootstrappers/BroadcastChannelPrefixBootstrapper.php

* Apply suggestions from code review

* Optionally skip prefixing of specific channels

* Add and test central channel helper, update formatChannels overrides and tests

* Fix code style (php-cs-fixer)

* minor fixes

* Improve annotation

* Use "global__" prefix instead of "central__", add comments

* Correct tests

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-11-06 22:09:01 +01:00
lukinovec
b503dbf33d
Fix rollback command (#14)
* Add and use setParameterDefaults()

* Correct rollback test

* Check ignored parameters instead of directly checking the command's options

* Delete --path setting from the test

* Revert test changes

* Delete new lines
2023-10-16 01:50:59 +02:00
lukinovec
ab240fb675
Correct variable name (#15) 2023-10-12 22:45:52 +02:00
lukinovec
8d38f42cd0
Correct asset helpers, make asset helpers work with path identification (#6)
* Make asset_helper_tenancy false by default

* Make tenant_asset() respect ASSET_URL

* Set asset helper tenancy to true in tests where needed

* If the `asset_helper_tenancy` key is missing, default to false in filesystem bootstrapper

* Make temporary clone action changes

* Make tenancy asset route universal

* Make the asset controller's asset method behave differently if path ID MW is the default

* Test that asset helper works with path identification

* Fix code style (php-cs-fixer)

* Delete path traversal attack prevention

* Fix code style (php-cs-fixer)

* Skip cloning of stancl.tenancy.asset route in some tests

* Fix code style (php-cs-fixer)

* Clone asset route in TSP stub

* Add cloning only the passed route

* Clone asset route in tenant asset test beforeEach

* Skip asset route cloning by default

* Fix typo

* Change public method back to protected

* Remove cloning of specific routes, skip cloning routes flagged as tenant

* Delete constructor from asset controiler, change asset method to invoke

* Update asset route registration, add prefixed asest route for path identification

* Use default middleware from config instead of `tenancy()->defaultMiddleware()`

* Delete old code from TSP stub

* Revert TSP stub change

* Revert FilesystemTenancyBootstrapper changes

* Suffix asset url in tenant_asset()

* Simplify `tenant_asset()`

* Ensure the base asset url is always suffixed with '/'

* remove unnecessary ?? false

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-08-31 15:44:26 +02:00
lukinovec
f7d9f02fd4
Improve route cloning action (#8)
* Allow cloning routes when only kernel identification is used, explicitly enable specific cloning modes

* Explicitly enable needed clone modes in tests, use "clone" instead of "reregister"

* Fix code style (php-cs-fixer)

* Use  "cloning" instead of "re-registration" in UniversalRouteTest

* Only clone routes using path identification

* Revert clone mode changes

* Fix code style (php-cs-fixer)

* Update comment

* Skip cloning 'stancl.tenancy.asset' by default

* Decide which routes should get cloned in the filtering step, improve method organization

* Return `RouteMode::UNIVERSAL` in getMiddlewareContext if route is universal

* Give universal route the path ID MW so that it gets cloned

* Fix code style (php-cs-fixer)

* Simplify UsableWithEarlyIdentification code

* Handle universal route mode in ForgetTenantParameter

* Fix code style (php-cs-fixer)

* Rename getMiddlewareContext to getRouteMode

* Append '/' to the route prefix

* Rename variable

* Wrap part of condition in parentheses

* Refresh name lookups after cloning routes

* Test giving tenant flag to cloned routes

* Add routeIsUniversal method

* Correct ForgetTenantParameter condition

* Improve tenant flag giving logic

* Improve test name

* Delete leftover testing code

* Put part of condition into `()`

* Improve CloneRoutesAsTenant code + comments

* Extract route mode-related code into methods, refactor and improve code

* Improve ForgetTenantParameter, test tenant parameter removing in universal routes

* Fix code style (php-cs-fixer)

* Fix test

* Simplify adding tenant flag

* Don't skip stancl.tenancy.asset route cloning

* clean up comment

* fix in_array() argument

* Fix code style (php-cs-fixer)

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-08-28 13:17:17 +02:00
lukinovec
4d4639450e
Use randomly generated tenant key instead of 'acme' in failing test (#10) 2023-08-25 17:01:47 +02:00
Samuel Štancl
2d500f9780
Fix #1112 - throw an exception if DATABASE_URL is set (#9)
* fix #1112 - throw an exception when DATABASE_URL is defined, minor test changes

* Fix code style (php-cs-fixer)

* fix typo

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
2023-08-18 20:21:00 +02:00
lukinovec
af3812e788
Fix filesystem bootstrapper (#7)
* Test if Storage::url() works correctly after reverting to central context

* Fix typo in code

* Access originalPaths using dot notation using `data_get()`
2023-08-16 09:03:25 +02:00
lukinovec
948754cadc
Clone routes action improvements (#4)
* Use "clone" instead of "re-register" in UniversalRouteTest

* Fix `$shouldCloneRoute` condition, improve tenant flagging logic

* Use clone instead of reregister in stub
2023-08-07 18:32:13 +02:00
lukinovec
e3b59ae2b5
Improve file structure (#5)
* Add Enums and Overrides folders

* Fix code style (php-cs-fixer)

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
2023-08-03 17:51:53 +02:00
Abrar Ahmad
1d0ca27bc8
Central routes without Route::domain(), configurable tenant/central routes by default for domain/subdomain identification, allow accessing central routes in early identification for path & request data middleware (#3)
* Update url binding bootstrapper test

* Fix parent::temporarySignedRoute() call

* Add universal route tests for all identification types

* Improve determineContextFromRequest()

* Add setting `TenancyUrlGenerator::$prefixRouteNames` to true in TSP stub

* Delete seemingly redundant test (making one route universal won't make all routes universal in any case)

* Use collection syntax in ReregisterUniversalRoutes

* Improve comments

* Add domain identification MW annotation

* Update condition in GloballyUsable

* Set `tenancy.bootstrappers` instead of adding the bootstrappers using `tenancy.bootstrappers.x`, move test

* Revert GloballyUsable condition change

* Delete assigning bootstrappers to tenancy.bootstrappers.x

* Exclude cache prefixing bootstrapper from the initial configuration

* Fix test

* Unset bypass parameter

* Set static kernel identification-related properties in TestCase

* Update bootstrapper name in annotation

* Move unset() into a condition

* Update TenancyUrlGenerator condition

* Set static properties without instantiating Tenancy

* Fix unsetting bypass parameter

* formatting changes

* add a comment

* improve docblock

* add docblock to TenancyUrlGenerator [ci skip]

* docblock changes [ci skip]

* Update TenancyUrlGenerator (rename variable, allow bypassing prefixing temporarySignedRoute name)

* Improve determineContextFromRequest

* Only return the new url generator instance when extending 'url' in UrlBindingBootstrapper

* Check route's MW groups for the path ID MW

* Remove extra imports from config

* Rename MiddlewareContext to Context, add condition for skipping ID MW

* Set only the needed bootstrappers in TestCase

* Fix code style (php-cs-fixer)

* Remove condition

* Use correct return type

* Fix PHPStan issue

* Update comment

* Check for tenant parameter instead of prefix

* Update shouldBeSkipped condition for universal routes

* Don't remove the 'universal' MW group after route re-registration, update test

* Fix code style (php-cs-fixer)

* Fix typo

* Add test for mixing placement of access prevention and identification MW

* Add test for mixing placement of access prevention and identification MW

* Update docblock

* Add setting the session and key resolvers in UrlBindingBootstrapper (required with LW file uploads)

* Update stub

* Update variable name in route reregistering action

* Add trailing comma

* Fix code style (php-cs-fixer)

* Require routes using path identification to be flagged as tenant in order to be recognized as tenant routes

* Add tenant flag while re-registering routes

* Update determineContextFromRequest condition (wip)

* Fix code style (php-cs-fixer)

* Update the middleware context logic so that universal routes have to be flagged as tenant instead of just having ID MW

* Update path identification condition

* Fix re-registering the LW localized route (add 'tenant' MW)

* Update docblock

* Simplify LW route re-registration

* Add comment

* Update comment

* Simplify determineContextFromRequest, add comment

* Improve stub

* Add skipRoute method + test

* Fix typo

* Update assets/TenancyServiceProvider.stub.php

* Update src/Concerns/DealsWithEarlyIdentification.php

* Fix typo

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>

* Improve comment

* Update test structure

* Restructure Fortify test

* code style

* Fix typo

* Update ReregisterUniversalRoutes annotation

* Only prefix route  name if it wasn't already prefixed

* Add todo@docs

* Delete `Tenancy::$kernelAccessPreventionSkipped` and related logic

* Delete test tenant cleanup

* Test MW group unpacking, restructure and improve test

* Test that tenancy isn't initialized after visiting a central route with the tenant parameter

* Delete "in both central and tenant contexts" from test names

* Test that re-registering works with controllers too

* Set misc route properties during re-registering

* Determine context instead of guessing, update universal route tests

* Use randomly generated tenant ID instead of hardcoding `acme`

* Remove setting route validators

* Rename and update determine context method, add comments

* Update ForgetTenantParameter annotation

* Add comment

* Delete comment, delete variable assignment

* Update early domain identification test

* Improve domain identification tests (test defaulting accurately)

* Improve readability

* Simplify domain early ID test

* Use randomly generated tenant instead of 'acme'

* Simplify request data ID test, use random tenant instead of 'acme'

* Simplify defaulting domain identification test

* Use RouteFacade alias for the Route facade, improve test code

* Add defaulting to the request data and path ID tests

* Merge path identification tenant parameter removal tests, clean up

* Correct wording

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>

* Delete debugging things from UniversalRouteTest

* Update annotation

* Add `// Creates a matrix`

* Improve comment wording

* Add MiddlewareUsableWithUniversalRoutes, refactor code accordingly

* Fix code style (php-cs-fixer)

* Delete debugging leftovers

* Delete unused import

* Update universal route GloballyUsable condition

* Don't implement the universal route interface in access prevention MW

* Check if request host is in the central domains in domain ID MW

* Test universal routes with domain identification without access prevent MW

* Test that universal routes work only with identification MW implementing the universal route interface

* Fix code style (php-cs-fixer)

* Rename GloballyUsable to UsableWithEarlyIdentification

* Fix annotation

* Update requestHasTenant annotations

* Update comment

* Add `with()` comments

* Add with() comments where missing

* Rename interface, update/add comments

* Rename exception, update its default message

* Fix code style (php-cs-fixer)

* Fix interface name

* Delete redundant code from subdomain ID MW

* Change domainOrSubdomain ID MW so that instead of passing the identification to other MWs, it happens in the domainOrSubdomain MW

* Test domainOrSubdomain identification with universal routes

* Fix code style (php-cs-fixer)

* Rename universal routes interface

* Fix code style (php-cs-fixer)

* Try explaining forgetting the tenant parameter better

* update interface name reference

* uncouple example from query parameters

* Update ForgetTenantParameter.php

* Update ForgetTenantParameter annotation

* Check both routeHasMiddleware and routeHasIdentificationMiddleware in the route MW detection test

* Hardcode tenant subdomain

* Delete redundant event listening code

* Delete unused imports

* Delete misuse of `tenancy()->getMiddlewareContext()` from conditions

* Delete unused variable

* Update comment

* Correct request data identification test (defaulting)

* Fix defaulting in path id test

* Move default route context configuration in domian id test

* Rename and update the tenant parameter test

* Delete extra tenant parameter test

* Use `tenant-domain.test` instead of `127.0.0.2`

* Add `default_to_universal_routes` config key

* Deal with defaulting to universal routes in the reregistering action

* Update logic to make defaulting to universal routes possible

* Test defaulting to universal routes

* Fix code style (php-cs-fixer)

* Delete extra tests

* Delete "without access prevention" from datasets

* Add defaulting to universal routes to datasets

* Override universal flag by central/tenant flag

* Add universal flag overriding test

* Update "a route can be universal in both route modes" so that the name corresponds with the tested thing

* Ignore the PHPStan error

* Reset `InitializeTenancyByPath::$onFail` in PathIdentificationTest

* Simplify expression

* Use 'Tenancy (not) initialized.' in instead of `tenant()?->getTenantKey()` for better assertions

* Properly test removing tenant parameter

* Reset static properties in tests

* Correct comments in EarlyIdentificationTest

* Add comment

* Add detail to annotation

* Throw exception if payload isn't string or null in request data ID MW

* Fix code style (php-cs-fixer)

* Delete static `$kernelIdentificationSkipped` property, use `$request->attributes` instead

* Use 'default_route_mode' instead of 'default_to_tenant/universal_routes'

* Fix code style (php-cs-fixer)

* Make path identification MW, tenantParameterName and tenantRouteNamePrefix configurable in ReregisterUniversalRoutes

* Delete unused import

* Add `$passTenantParameterToRoute` to TenancyUrlGenerator

* Use `$passTenantParameterToRoute` in BootstrapperTest

* Bypass tenant parameter passing

* Improve TenancyUrlGenerator so that both ID methods work

* Fix code style (php-cs-fixer)

* Improve TenancyUrlGenerator readability

* Add modifyBehavior() to TenancyUrlGenerator

* Fix code style (php-cs-fixer)

* Improve comment

* Toggle route name prefixing in path/request data ID MW (route-level identification)

* Fix code style (php-cs-fixer)

* Add path identification MW config key, add `getTenantParameterName()` to ForgetTenantParameter

* Fix code style (php-cs-fixer)

* Fix modifyBehavior and routeBehaviorModificationBypassed

* Add type to `$parameters` parameter

* Split modifyBehavior into two methods, don't pass name and parameters by reference

* Update UrlBindingBootstrapper annotation

* Correct naming in tests (request data -> query string identification)

* Add info to annotation

* Pass arrays to the behavior modification methods instead of `mixed`

* Fix default value of static property in Fortify bootstrapper

* Fix code style (php-cs-fixer)

* Correct annotation

* Enable prefixing routes directly using path identification MW

* Test re-registration of routes with path ID MW

* Prefix names of routes directly using path ID MW

* Fix code style (php-cs-fixer)

* Add Livewire v3 integration example to TSP stub

* Prefix route name only if it's not prefixed already

* Rename ReregisterUniversalRoutes to ReregisterRoutesAsTenant

* Fix code style (php-cs-fixer)

* Improve ReregisterRoutesAsTenant

* Add/update TenancyUrlGenerator docblocks

* Update action name in comments/test names

* Update reregister action annotation

* Delete unused imports

* Improve comments

* Make method protected

* Improve TenancyUrlGenerator code

* Test bypass parameter removal

* Fix comment

* Update annotation

* Improve shouldReregisterRoute

* Fix typo, delete redundant comment

* Improve skipRoute

* Improve shouldBeSkipped

* Add and test `$passTenantParameterToRoutes`

* add a comment

* Fix typo in comment

* Pass array as $parameters in prepareRouteInputs

* Make path_identification_middleware an array

* Fix code style (php-cs-fixer)

* Fix ReregisterRouteAsTenant

* Move tenantParameterName and tenantRouteNamePrefix getting to PathIdentificationManager

* Make PathIdentificationManager properties `Closure|null`

* Fix code style (php-cs-fixer)

* Fix PathIdentificationManager

* Update comments

* Use foreach for dataset definition

* Extract repetitive inGlobalStack and routeHasMiddleware calls

* Refactor PathIdentificationManager

* Update TenancyUrlGenerator annotation

* Add $skippedRoutes, refactor ReregisterRoutesAsTenant

* Improve reregisterRoute

* Update re-register action annotation

* update test name

* Make PathIdentificationManager methods static again, update comments

* Add test comment

* Update ForgetTenantParameter annotation

* Improve route re-registration condition, add comment

* Change "re-register" to "clone"

* minor code improvements

---------

Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
2023-08-03 00:23:26 +02:00
Abrar Ahmad
bd9bbe8b41
Cache prefix mode for separating tenant caches (#1014)
* cache prefix

* prefix cache bootstrapper and tests

* remove comment

* DI app

* cache prefix base from config

* Create PrefixCacheBootstrapperTest.php

* remove `null` check

* fix phpstan error

* Update PrefixCacheTenancyBootstrapper.php

* Update PrefixCacheBootstrapperTest.php

* add comments

* Update PrefixCacheTenancyBootstrapper.php

* Update PrefixCacheBootstrapperTest.php

* Update config.php

* test names grammar

* user `getTenantKey` method

* assert tenants' data is accessible using the prefix from the central context

* remove unused line

* use proper DI

* build prefix using original prefix

* fix prefix test according to prefix changes

* fix test

* CacheManager dependency injection test

* CacheService class as singleton

* introduce second tenant in test

* use Repository in service class DI

* Update CacheAction.php

* Rename CacheAction to CacheService

* Update prefix bootstrapper and test (`setStore()` in CacheManager and Repository needed)

* Add macro

* Fix code style (php-cs-fixer)

* Simplify cache store refreshing

* Make Tenancy override CacheManager

* Update CacheManager, add refreshStore()

* Fix code style (php-cs-fixer)

* Uncomment cache tagging

* Revert condition in CacheManager to avoid excessive nesting

* Move `Cache::macro()` to a slightly more appropriate place

* Fix code style (php-cs-fixer)

* Use better class for the macro

* Toggle cache tags

* Make CacheManager::$addTags default to `true`

* Add changes to PR to Laravel

* Fix code style (php-cs-fixer)

* Revert changes, add comment

* Add test

* Make `$cache` non-nullable

Co-authored-by: Samuel Štancl <samuel@archte.ch>

* Add and test `nonTenantCacheDrivers`

* Add nonTenantCacheDrivers check

* Test that the prefix stays the same

* Change nonTenantCacheDrivers to tenantCacheStores

* Remove redundant CacheManager extend() call

* Make 'redis' the only tenant cache store in beforeEach, test that tenantCacheStores works

* Remove unused import, change word

* Make CacheService a singleton in a test

* Update test name

* Remove group('prefix')

* Rename CacheManagerService

* Improve specific cache store in a service test

* Improve comment

* Improve tests

* Use my Laravel fork

* Fix code style (php-cs-fixer)

* Downgrade Laravel

* Upgrade Laravel

* Hint Repository implementation instead of contract

* Fix types

* Fix code style (php-cs-fixer)

* Fix test

* Use Laravel fork in ci.yml

* use dev-master before our changes are released in L10

* remove laravel fork from repositories

* use 10.x-dev instead of master

* remove L9 support

* 10.x-dev (fix conflict resolution)

* use the laravel version from the ci matrix for the phpstan job as well

* Revert "use the laravel version from the ci matrix for the phpstan job as well"

This reverts commit 5f3079d2ff.

* Test that non-default stores get prefixed too

* Use new Laravel release, remove L9 support

* Complete L9 support removal

* Specify 10.1.1 as the minimal Laravel version in ci.yml

* Use 10.x-dev

* Prefix all cache stores specified in `$tenantCacheStores`

* Update Laravel

* Use tmpfs in docker-compose

* Add customizing cache store prefixes

* Test cache prefixing customization

* Fix code style (php-cs-fixer)

* Update ci.yml

* Delete tmpfs from docker-compose.yml (there were no benefits)

* Use default prefix generator inline, delete the 'default' key logic

* Fix original prefix logic

* Update tests

* Delete CacheTenancyBootstrapper

* Reset static properties in afterEach

* Use `$this->config` instead of `config()`

* Disable cache tagging by default, add CacheTagBootstrapper

* Fix code style (php-cs-fixer)

* Rename bootstrapper

* Improve CacheManager

* Move logic from separate method to __call

* Make original prefixes customizable

* Add info in comment

* Add defaultPrefix property

* Use `$this->app` instead of `app()`

* Rename bootstrapper

* Fix code style (php-cs-fixer)

* Use a single original prefix

* Update prefix generator logic + tests

* Correct `$addTags` reset in a test

* Update cache tests so that both prefixing and tagging is covered

* Simplify cache tests

* Delete afterEach

* Small testing improvements

* Set `cache.default` in beforeEach

* Update cache prefixing and tests

* Add assertion

* Refactor assertion

* Refactor assertions

* Delete TTL from cache put calls

* Add re-initialization cache assertion

* Assert that cache is null from the beginning

* Merge the tenantCacheStores tests

* Fix formatting

* Improve test name

* Improve tests

* Add cache manager config key

* Fix code style (php-cs-fixer)

* Update defaulting test

* Add todo

* Update comments

* Extract duplicate assertions into a closure

* Update comment

* Add assertions + comment

* Delete redundant config put calls

* Use `tenancy.cache.manager` config instead of `Stancl\Tenancy\CacheManager`

* Change setting to assertion, add comment

* Inline variable & config key assignment

* Delete `cache.default` assertion

* Override cache manager only in CacheTagsBootstrapper

* Fix code style (php-cs-fixer)

* Prefix both drivers by default, add assertions for the second driver where missing

* Clean up global state (static properties) in before/afterEach

* Add docblock to tags bootstrapper

* Delete extra dependency

* Add `illuminate/support` dependency back

* Use `$addTags` approach again

* Fix code style (php-cs-fixer)

* Revert "Fix code style (php-cs-fixer)"

This reverts commit ea805fa231.

* Revert "Use `$addTags` approach again"

This reverts commit 8f5a4e4eb6.

* Add commented CacheTagsBootstrapper with info to the bootstrappers config

* Delete legacy bootstrapper from the bootstrappers config, add info to the bootstrapper's docblock

* Delete "?" from `tenant()?->getTenantKey()

* call generatePrefix() on $bootstrapper

* misc improvements

---------

Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-04-24 16:25:51 +02:00
Samuel Štancl
6a26f712e7 Merge branch 'master' of github.com:archtechx/tenancy 2023-04-14 17:28:32 +02:00
Samuel Štancl
0832ab805b wip 2023-04-14 17:23:19 +02:00
Samuel Štancl
1f4dae7012
exception message 2023-04-14 17:06:15 +02:00
lukinovec
228c2676f3
Add remember column to to the impersonation token (#1101) 2023-04-13 02:05:26 +02:00
Samuel Štancl
dfd39722a7
bump stancl/jobpipeline to v2.0.0-rc1 2023-03-16 22:20:47 +01:00
lukinovec
719b1be245
Fix URL root override example (#1079) 2023-03-01 10:40:56 +01:00
Samuel Štancl
8b7862d8ad
add --xdebug option to phpstan 2023-02-21 18:28:57 +01:00
Samuel Štancl
e531f96c4b
specify full laravel versions to support using dev-master in PRs 2023-02-21 17:47:25 +01:00
Samuel Štancl
858249759f Merge branch 'master' of github.com:archtechx/tenancy 2023-02-21 00:40:40 +01:00
lukinovec
e61a26d604
Add L10 support to 4.x (merge 3.x to master) (#1071)
* exclude master from CI

* Add space after 'up' in 'docker-compose up-d' (#900)

* Fix ArgumentCountError on the TenantAssetsController (#894)

* Fix ArgumentCount exception on the TenantAssetsController when no `$path` is provided

* CS

* CS

* Handle null case explicitly

* code style

Co-authored-by: Bram Wubs <bram@sibi.nl>
Co-authored-by: Samuel Štancl <samuel@archte.ch>

* Add support for nested tenant config override (#920)

* feat: add support for nested tenant config override

* test: ensure nested tenant values are mapped

* fix: typo mistake (#954)

* [3.x] Add Vite helper for tenancy (#956)

* Add Vite helper for tenancy

* Move Vite bundler to an Optional Feature

* Rename to foundation vite

* Add ViteBundlerTest

* Add missing end of file

* Update tests

* remove unnecessary end() call

Co-authored-by: Samuel Štancl <samuel@archte.ch>

* rewrite ViteBundlerTest to phpunit syntax

* skip vite test in Laravel < 9

* convert ViteBundler to PHP 7 syntax

* remove import of nonexistent class in older Laravel versions

* remove import of Foundation\Vite in tests

* try to exclude Vite.php from coverage report

* remove typehint

* update channel name

* Cache crash fix (#1048)

* Don't prevent accessing missing Tenant attributes. (#1045)

* [3.x] L10 compatibility (#1065)

* Bump dependencies for Laravel 10

* Update GitHub Actions for Laravel 10

* ci: do not test L10 using PHP 7.3

* drop < L9 support

* use `dispatch_sync` instead of `dispatch_now`

* migrate phpunit configuration

* Update ci.yml

* drop laravel < 9 support

* misc L10 fixes, new docker image

* specify odbc version

* wip

* properly list php versions as strings

* minor changes

* Add `getValue($queryGrammar)` to raw query

* Clean up `isVersion8` code

* rewrite hasFailed assertion

* phpunit schema update

* Upgrade `doctrine/dbal`

---------

Co-authored-by: Samuel Štancl <samuel@archte.ch>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
Co-authored-by: lukinovec <lukinovec@gmail.com>

* Update ci.yml

* Fix code style (php-cs-fixer)

* Update dependencies

* Change invade version

* Delete ViteBundlerTest

* Fix PHPStan error

* Delete PHPStan error ignore

* Fix CONTRIBUTING.md

* Delete ViteBundler remains

* Bring back ViteBundler

* Convert ViteBundlerTest to Pest

* Update ci.yml

---------

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
Co-authored-by: Bram Wubs <megawubs@users.noreply.github.com>
Co-authored-by: Bram Wubs <bram@sibi.nl>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
Co-authored-by: George Bishop <email.georgebishop@gmail.com>
Co-authored-by: Anbuselvan Rocky <15264938+anburocky3@users.noreply.github.com>
Co-authored-by: Wilsen Hernández <13445515+wilsenhc@users.noreply.github.com>
Co-authored-by: Joel Stein <joel@mediatrix.digital>
Co-authored-by: Guilherme Saade <saade@outlook.com.br>
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
2023-02-20 23:47:10 +01:00
lukinovec
d7a4982cd3
[4.x] Make broadcasting work with Tenancy (#1027)
* Add BroadcastTenancyBootstrapper and TenancyBroadcastManager

* Fix code style (php-cs-fixer)

* Bind original BroadcastManager again on `revert()`

* Fix code style (php-cs-fixer)

* Move manager to correct directory

* Fix property type

* Make BroadcastTenancyBootstrapper a singleton in tests

* Fix code style (php-cs-fixer)

* Bind the original broadcaster instance on `revert()`

* Instead of just forgetting the old broadcaster instance, bind the new one

* Add BroadcastTenancyBootstrapper tests

* Separate the test

* Fix code style (php-cs-fixer)

* Add bootstrapper test

* Add broadcaster channels test

* Clean up BootstrapperTest

* Fix BroadcastingTest

* Add comments to TenancyBroadcastManager

* Add BroadcastTenancyBootstrapper comments

* Simplify BroadcastManager extension, remove setDriver method

* Add comment

* Fix PHPStan errors

* Fix PHPStan errors

* Remove duplicate import

* Fix test

* Delete `::class` from test name

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>

* Create databases for newly created tenants in BroadcastingTest

* move spatie/invade to require

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-02-18 15:52:55 +01:00
lukinovec
fbdb13f392
[4.x] Set app.url config in UrlTenancyBootstrapper (#1068)
* Set `app.url` config in UrlTenancyBootstrapper

* Add assertions

* Set base app URL in config

* Make UrlTenancyBootstrapper a singleton
2023-02-18 13:01:17 +01:00
lukinovec
617e9a7a73
[4.x] Allow user to customize tenant's URL root in CLI (#1044)
* Add UrlTenancyBootstrapper

* Fix code style (php-cs-fixer)

* Move URL overriding to a separate method, call it in `boot()`

* Test URL root overriding

* Change parameter formatting

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>

* Fix code style (php-cs-fixer)

* Improve URL bootstrapper test

* Move `$scheme` and `$hostname` to the closure

* Update code example comment

* Hardcode values instead of referencing variables

* Delete extra line

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-02-17 10:56:43 +01:00
Samuel Štancl
a006e49881
specify version of odbc libraries 2023-02-16 17:20:55 +01:00
Abrar Ahmad
758fbc8a75
Use polymorphic table for mapping resources to tenants (#997)
* wip

* Fix code style (php-cs-fixer)

* adjust tests

* Update ResourceSyncingPolymorphicTest.php

* Update SyncMaster.php

* correct method name

* Update ResourceSyncingPolymorphicTest.php

* use BelongsToMany return type

* separate pivot model for each approach

* ability to publish migrations

* remove unsed import

* use resource migrations from asset

* anonymous migration for `tenant_resources` table

* rename file

* rename classes

* trait

* add back using statement

* revert to unset change

* use unset approach

* use unset approach

* Assert `tenants` are accessible

* Update ResourceSyncingUsingPolymorphicTest.php

* improve `tenants` assertions

* improve assertions

* remove `getResourceTenantModelName` method and use config

* use `BelongsToMany` for `tenants` method return type

* Fix code style (php-cs-fixer)

* revert type

* use correct key

* test right resources are accessible from the tenant

* Update tests/ResourceSyncingUsingPolymorphicTest.php

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
2023-02-02 06:39:35 +01:00
Abrar Ahmad
087733d5db
Allow defining the tenant connection template using array syntax in config (#1040)
* `template_tenant_connection` can be array or string

* Update TenantDatabaseManagerTest.php

* Update TenantDatabaseManagerTest.php

* Update TenantDatabaseManagerTest.php

* Update DatabaseConfig.php

* partial database config for template

* Update tests/TenantDatabaseManagerTest.php

Co-authored-by: lukinovec <lukinovec@gmail.com>

* update test name

* improve test names

* add comments

---------

Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
2023-02-01 07:02:03 +01:00
lukinovec
342c67fe02
Add skip-failing option to the Migrate command (#945)
* Add and test Migrate command's skip-failing option

* Improve naming

* Move migration event dispatching inside try block

* Change test name

* Fix skip-failing test

* Use QueryException instead of Exception

* Correct TenantDatabaseDoesNotExistException import

* Correct test

* Check for the the testing env in DB bootstrapper

* Correct the Migrate command

* Fix code style (php-cs-fixer)

* add docs todo

* Add QueryException to the Migrat command try/catch

* Return status codes in Migrate

* Fix code style (php-cs-fixer)

* Add test for not stopping tenants:migrate after the first failure

* Update Migrate command

* Fix code style (php-cs-fixer)

* Fix code style (php-cs-fixer)

* Use `getTenants()`

* Use withtenantDatabases where needed

* Add withTenantDatabases to test

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-02-01 06:55:26 +01:00
Samuel Štancl
d7437c42d2 Merge branch 'master' of github.com:tenancy-for-laravel/v4 2023-02-01 06:20:27 +01:00
Samuel Štancl
f741f44527 Merge branch 'master' of github.com:archtechx/tenancy 2023-02-01 06:17:27 +01:00
Samuel Štancl
0a205dd817 resolve phpstan issues 2023-02-01 06:17:19 +01:00
PHP CS Fixer
7767fea5ba Fix code style (php-cs-fixer) 2023-02-01 05:05:50 +00:00
Samuel Štancl
66c7d6a066 fix PhpParser exception 2023-02-01 06:05:26 +01:00