mardi 27 février 2018

How to implement a Switch Account feature in web architecture [Rails]?

I don't quite know where this question belongs or how to ask it, but I will try my best to try and explain.

Basically, a User can have multiple Unit's that they can use.

We are running into problems with the context of our application, where the Unit you are making requests to... is NOT the one that user thinks it is.

To exemplify, suppose the current_user has 2 Units.

#< Unit id: 1, name: "Happy Unit One", created: "2018-02-26 05:00:00 UTC">,

#< Unit id: 2, name: "Sad Unit Two", created: "2018-02-27 05:00:00 UTC">

When the user logs in, they will be directed to their home page /home/:unit_id for their last unit. So, for this case they will be redirected to /home/2. I decided that it will be useful to store this value in a current_unit_id variable, where we can access and reference it.

Take a look below:

Contextualising the navigation menu

current_unit_id is the foundation of our side nav. Meaning, if our curent_unit_id changes to 1... then, it Happy Unit One will be at the top. Makes sense right?

This is where things get funky

If a user clicks on a different unit through the navigation, it will update the current_unit_id and redirect them to THAT home page. BUT, imagine if their current_unit_id = 2 and they are on it's home page (/home/2) but they hardcode the URL: /home/1...

Now, they will be LOOKING at the Home Page of #< Unit id: 1, name: "Happy Unit One"> but their navigation will still have #< Unit id: 2, name: "Sad Unit Two"> because the current_unit_id did not update.

If you are suggesting, why don't we just update in on the /home/:unit_id GET request... (believe me, we tried this) the problem is that we have so many routes that are making use of /something/:unit_id and it doesn't make sense to to update current_unit_id on each of these requests.

Other examples I looked at.

I tried to look at the way Bitbucket contextualises their repo and branches.Bitbucket example

Over here, anywhere you go in the application, it will always be in the context of the random-repo repository. HOWEVER, if you change the highlight part of the URL to something like management it will understand and it will look like this after: enter image description here




Aucun commentaire:

Enregistrer un commentaire