grails / scaffolding

Scaffolding plugin for Grails® framework
Apache License 2.0
15 stars 23 forks source link

Make scaffolded actions tenant id aware #35

Open magnomp opened 7 years ago

magnomp commented 7 years ago

As GORM 6 has support for multi tenancy, scaffolded controllers for multi tenant domains should take into account the current tenant, which RestfulController (the super class for scaffolded controllers) don't.

ScaffoldingControllerInjector should detect that: 1) GORM 6 is being used 2) The scaffold property points to a domain class that implements MultiTenancy

If "1" and "2" are true, then the super class must be something that exposes the same actions as RestfulController but whose actions are tenant id aware, like: def delete() { Tenants.withCurrent { resource.withTransaction { transactionStatus -> ... } } }

If "1" or "2" are false then should behave as today

magnomp commented 7 years ago

Ideally the same super class should be used (so that we're not repeating code), but that's not possible because RestfulController uses @Transaction which don't handles multi tenancy. Instead it should be something like: class ScaffoldedController<T> { def delete() { resource.withTransaction { transactionStatus -> } } }

class TenantAwareScaffoldedController<T> extends ScaffoldedController<T> { @Override def delete() { Tenants.withCurrent { super.delete() } } }