Jump to content

Modifying the code for users filter - Advise


Mariano

Recommended Posts

Hello, I wanted to share what i did to the souce code of the core to get some advice if there something can go wrong (the logic works, but in case I am missing something) and if there could be a better way to implement it or some idea so I don't need to change/check so much files after updates. It is for multi-company.

The goal of the changes is that: a staff member, a client of company A and a client of a company B can use (or not) the same username (is not the same account, just the same username, these are independent users). What i did:

Step 1: split the Users model functions in two, same logic, only changes the filter:

getByUsername -> getByUsernameOnlyClient / getByUsernameOnlyStaff -> It filters only users in one company (current) that are client / filters only users that are staff

validateUniqueUser -> validateUniqueUserOnlyClient and validateUniqueUserOnlyStaff -> Same as before

Step 2: split the rest of the Users model functions in two as before (validateUser, add, getRules, ...), to use the new previous functions (same logic, only changed wich function is called).

Step 3: updated all the controllers to use the "OnlyClient" functions when is a client action (login, register, recovery, create, update, ...) and "OnlyStaff" functions when is a staff action.

Step 4: removed the username unique key in the database. 

I tried to keep the old functions and not just edit these ones to keep better track of changes.

Any idea or recommendation is welcome.

Thank you in advance,

regards.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...