Answer the question
In order to leave comments, you need to log in
JavaScript framework + user rights + interface
There is backbone.js or angular.js or some similar unknown crap. There is express.js on the backend. As a result, we get a single-page application that works without reloading.
The user logs in and receives a role, let's say "ordinary user". He has certain rights on the site, on which the interface depends: additional buttons, functions, etc.
At some point, while the user is on the site, the admin gives him a different role, let's say "privileged user". At this point, the user should have new features, buttons, and other interface elements.
Apparently, we need to notify the user, we can use socket.io, and make an event handler on the client, which in turn will add the necessary interface elements.
So, am I thinking right?
And the second question: keep all these interface elements permanently on the page and show / hide when changing user roles, or change the dom every time?
Answer the question
In order to leave comments, you need to log in
Listen to the change event on the model. The admin gives new rights (read - sets new data to the model), the change trigger fires and your view renders a new template, where all these buttons of a privileged user already exist. (this is on the backbone, I think it’s somehow similar in angular)
Well, yes, that's how it's done. If they are completely different - into different templates, if not very much - hide the control with ng-show or ng-if.
There are still cases when the administrator's interface weighs 10 times more and takes longer to load. Or you don't want a regular user to be able to access them. Then you can also give templates and scripts of the admin interface separately when the user has such a role.
If you think about it, it's not enough to hide-show elements - for this you can use, as you rightly said, rootScope + directives (ng-if, ng-hide).
After all, it is also necessary to limit the return of data - an ordinary user should not receive data from the server that he cannot see.
Those. it is not enough, in my opinion, just to hide a column in the table, if the data for this column still arrives from the server.
To receive data asynchronously, you either need to use a socket or long poling (in short, this is a way of communicating with the server when the client gives a get-post request to the server, but the server does not respond immediately, but gives the data as soon as they appear). Some of this should help you.
And secondly, what's stopping you from changing the dom every time? If nothing, then change every time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question