mercredi 22 février 2017

Ember - advanced routing structure for user impersonation

In my app I have the following user hierarchy organisation (org) > reseller > customer. From a business perspective all three user types in the hierarchy are a customer with a :customer_id. From an app perspective they are seperate concerns, with the ability to impersonate users down the hierarchy.

So their base URL would all be the equivalent of:

localhost/org/:customer_id.

But An organisation could route into a reseller as:

localhost/org/:customer_id/reseller/:customer_id.

And both organisation and resellers could route into customers as:

localhost/org/:customer_id/reseller/:customer_id/customer/:customer_id or localhost/reseller/:customer_id/customer/:customer_id

Problems with this structure

The main issue is that every customer has it's own site and service route. And I want to avoid repeating routes under the top level :customer_id. Essentially ending up with the following.

Router.map(function() {
  this.route('org', { path: 'org/:customer_id' }, function() {
    this.route('site');
    this.route('service');
    this.route('reseller', { path: 'reseller/:customer_id' }, function() {
      this.route('site');
      this.route('service');
      this.route('customer', { path: 'customer/:customer_id' }, function() {
        this.route('site');
        this.route('service');
      });
    });
  });
});

But I'm unsure how to split the routes so that they inherit the correct URL structure but aren't nested. And in a way where each customer can access/impersonate at the correct level.

As an aside

If I can't figure out how to execute this I'm planning on using a user-service to set a currentUser variable for impersonation, and then stripping the URL to localhost/org/:org_id/ for every customer. But this won't reflect the level of impersonation in the URL.




Aucun commentaire:

Enregistrer un commentaire